Skip to content

Commit

Permalink
Merge pull request #146 from neulab/feat/public-leaderboard
Browse files Browse the repository at this point in the history
feat: allow public systems to be viewed without auth
  • Loading branch information
lyuyangh authored Apr 28, 2022
2 parents d7f75c0 + 4baf1ef commit 46973b6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
4 changes: 3 additions & 1 deletion backend/src/impl/db_models/system_metadata_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ def find(
filter["system_info.dataset_split"] = split
if creator:
filter["creator"] = creator
filter["$or"] = [{"is_private": False}, {"creator": get_user().email}]
filter["$or"] = [{"is_private": False}]
if get_user().is_authenticated:
filter["$or"].append({"creator": get_user().email})

cursor, total = super().find(filter, sort, page * page_size, page_size)
documents = list(cursor)
Expand Down
22 changes: 18 additions & 4 deletions frontend/src/components/SystemsTable/SystemTableTools.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Button, Input, Select, Space, Tooltip } from "antd";
import { Button, ButtonProps, Input, Select, Space, Tooltip } from "antd";
import { TaskSelect } from "..";
import { TaskCategory } from "../../clients/openapi";
import {
Expand All @@ -8,6 +8,7 @@ import {
WarningOutlined,
} from "@ant-design/icons";
import { SystemModel } from "../../models";
import { LoginState, useUser } from "../useUser";

export interface Filter {
name?: string;
Expand Down Expand Up @@ -162,10 +163,23 @@ export function SystemTableTools({
onChange={(e) => onChange({ name: e.target.value })}
/>

<Button type="primary" onClick={() => toggleSubmitDrawer()}>
New
</Button>
<NewSystemButton onClick={toggleSubmitDrawer} />
</Space>
</div>
);
}

function NewSystemButton(props: ButtonProps) {
const { state } = useUser();
if (state === LoginState.yes)
return (
<Button type="primary" {...props}>
New
</Button>
);
return (
<Tooltip title="Please log in to submit new systems" placement="topLeft">
<Button disabled>New</Button>
</Tooltip>
);
}
6 changes: 3 additions & 3 deletions frontend/src/components/UserPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export function UserPanel() {
);
const userMenu = (
<Menu className="menu" style={{ float: "right" }}>
<Menu.Item className="menu-item">
<Menu.Item className="menu-item" key="email">
Email:{" "}
<Typography.Paragraph copyable className="menu-item-text">
{userInfo?.email}
</Typography.Paragraph>
</Menu.Item>
<Menu.Item>
<Menu.Item className="menu-item" key="api_key">
API Key:{" "}
<Typography.Paragraph copyable className="menu-item-text">
{userInfo?.api_key}
</Typography.Paragraph>
</Menu.Item>
<Menu.Item danger className="menu-item" onClick={logout}>
<Menu.Item danger className="menu-item" onClick={logout} key="logout">
<Tooltip
placement="left"
title="Currently, logging out from the web interface doesn't immediately invoke your access from our platform. Instead, your access will expire in a day (at which point, you have logged out completely). The support for a true logout will be added in the future."
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/useUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function UserProvider({ children }: { children: React.ReactNode }) {
setState(LoginState.yes);
} catch (e) {
setState(LoginState.expired);
refreshBackendClient(null);
}
}
if (jwt) fetchUserInfo();
Expand Down Expand Up @@ -81,7 +82,10 @@ export function UserProvider({ children }: { children: React.ReactNode }) {

/** redirect to login page */
const login = useCallback(() => {
localStorage.setItem(redirectPageKey, window.location.pathname);
localStorage.setItem(
redirectPageKey,
window.location.pathname + window.location.search
);
const { protocol, host } = window.location;
window.location.href = encodeURI(
`${authURL}${protocol}//${host}/login-callback`
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ const routes: Route[] = [
title: "Systems",
icon: <CodeOutlined />,
children: <SystemsPage />,
requireLogin: true,
requireLogin: false,
},
{
path: "/leaderboards",
title: "Leaderboards",
icon: <TableOutlined />,
children: <LeaderboardPage />,
requireLogin: true,
requireLogin: false,
},
{
path: "/terms",
Expand Down
6 changes: 6 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ paths:
/systems:
get:
summary: Returns a list of systems
description: only public systems are returned for unauthenticated requests
security:
- ApiKeyAuth: []
- BearerAuth: []
- {}

parameters:
- in: query
name: system_name
Expand Down

0 comments on commit 46973b6

Please sign in to comment.