Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,13 @@ export const SnapshotContainer: React.FC<SnapshotContainerProps> = ({
heading="Authors"
item={
<>
{profile && (
<RequestContributorButton
dataset={dataset}
currentUserId={currentUserId}
/>
)}
{profile && !profile.scopes.includes("dataset:reviewer") &&
(
<RequestContributorButton
dataset={dataset}
currentUserId={currentUserId}
/>
)}
<ContributorsListDisplay
datasetId={dataset.id}
contributors={snapshot.contributors}
Expand Down
72 changes: 43 additions & 29 deletions packages/openneuro-app/src/scripts/users/user-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,46 @@ import { useUser } from "../queries/user"
import { useNotifications } from "./notifications/user-notifications-context"
import "./scss/user-menu.scss"

interface UserMenuListProps {
user: NonNullable<ReturnType<typeof useUser>["user"]>
}

function UserMenuList({ user }: UserMenuListProps) {
return (
<>
<li>
<Link
to={user.orcid ? `/user/${user.orcid}` : "/search?mydatasets"}
>
My Datasets
</Link>
</li>

{user.orcid && (
<li>
<Link to={`/user/${user.orcid}/account`}>Account Info</Link>
</li>
)}

<li className="user-menu-link">
<Link to="/keygen">Obtain an API Key</Link>
</li>

{user.provider !== "orcid" && (
<li className="user-menu-link">
<a href="/crn/auth/orcid?link=true">Link ORCID to my account</a>
</li>
)}

{user.admin && (
<li className="user-menu-link">
<Link to="/admin">Admin</Link>
</li>
)}
</>
)
}

export interface UserMenuProps {
signOutAndRedirect: () => void
}
Expand All @@ -15,6 +55,8 @@ export const UserMenu: React.FC<UserMenuProps> = ({ signOutAndRedirect }) => {

if (loading || !user) return null

const reviewer = user.id === "reviewer"

const inboxCount =
notifications?.filter((n) => n.status === "unread").length || 0

Expand Down Expand Up @@ -66,35 +108,7 @@ export const UserMenu: React.FC<UserMenuProps> = ({ signOutAndRedirect }) => {
</p>
</li>

<li>
<Link
to={user.orcid ? `/user/${user.orcid}` : "/search?mydatasets"}
>
My Datasets
</Link>
</li>

{user.orcid && (
<li>
<Link to={`/user/${user.orcid}/account`}>Account Info</Link>
</li>
)}

<li className="user-menu-link">
<Link to="/keygen">Obtain an API Key</Link>
</li>

{user.provider !== "orcid" && (
<li className="user-menu-link">
<a href="/crn/auth/orcid?link=true">Link ORCID to my account</a>
</li>
)}

{user.admin && (
<li className="user-menu-link">
<Link to="/admin">Admin</Link>
</li>
)}
{!reviewer && <UserMenuList user={user} />}

<li className="user-menu-link">
<a onClick={signOutAndRedirect} className="btn-submit-other">
Expand Down
49 changes: 48 additions & 1 deletion packages/openneuro-server/src/graphql/resolvers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,53 @@ function isValidOrcid(orcid: string): boolean {
return /^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$/.test(orcid || "")
}

// TODO - Use GraphQL codegen
type GraphQLUserType = {
id: string
provider: "orcid" | "google"
avatar: string
orcid: string
created: Date
modified: Date
lastSeen: Date
email: string
name: string
admin: boolean
blocked: boolean
location: string
institution: string
github: string
githubSynced: Date
links: [string]
notifications: [Record<string, unknown>]
orcidConsent: boolean
}

export async function user(
obj,
{ id },
{ userInfo }: { userInfo?: Record<string, unknown> } = {},
) {
): Promise<Partial<GraphQLUserType> | null> {
if (userInfo.reviewer) {
const oneWeekAgo = new Date()
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7)
return {
id: "reviewer",
name: "Anonymous Reviewer",
email: "reviewer@openneuro.org",
provider: "orcid",
orcid: "0000-0000-0000-0000",
admin: false,
blocked: false,
location: "",
institution: "",
orcidConsent: true,
created: oneWeekAgo,
lastSeen: new Date(),
modified: oneWeekAgo,
}
}

let user
if (isValidOrcid(id)) {
user = await User.findOne({
Expand Down Expand Up @@ -226,6 +268,11 @@ export const updateUser = async (
export async function notifications(obj, _, { userInfo }) {
const userId = obj.id

// Reviewers never have notifications
if (userInfo.reviewer) {
return []
}

// --- authorization ---
if (!userInfo || (userInfo.id !== userId && !userInfo.admin)) {
throw new Error("Not authorized to view these notifications.")
Expand Down
Loading