-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for inactive (private) workflows
- swap `project.links.workflows` for `project.links.active_workflows` when validating workflow IDs in `app-project`. - add a `useProjectRoles` hook to the classifier, which gets roles for a project, user and token. - check project roles during workflow selection. Allow owners, testers and collaborators to select any project workflow. - add a usePanoptesUser hook. - add a usePanoptesAuth hook.
- Loading branch information
1 parent
5fbdb31
commit bb9fbd8
Showing
16 changed files
with
136 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export { default as useHydratedStore } from './useHydratedStore' | ||
export { default as usePanoptesAuth } from './usePanoptesAuth' | ||
export { default as usePanoptesUser } from './usePanoptesUser' | ||
export { default as useProjectRoles } from './useProjectRoles' | ||
export { default as useWorkflowSnapshot } from './useWorkflowSnapshot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useEffect, useState } from 'react' | ||
import { getBearerToken } from '@store/utils' | ||
|
||
export default function usePanoptesAuth(userID, authClient) { | ||
const [authorization, setAuthorization] = useState() | ||
async function checkAuth() { | ||
const token = await getBearerToken(authClient) | ||
setAuthorization(token) | ||
} | ||
|
||
useEffect(function onUserChange() { | ||
checkAuth() | ||
}, [userID]) | ||
|
||
return authorization | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import useSWR from 'swr' | ||
|
||
const SWRoptions = { | ||
revalidateIfStale: true, | ||
revalidateOnMount: true, | ||
revalidateOnFocus: true, | ||
revalidateOnReconnect: true, | ||
refreshInterval: 0 | ||
} | ||
|
||
async function fetchUser(authClient) { | ||
const user = await authClient.checkCurrent() | ||
return user | ||
} | ||
|
||
export default function usePanoptesUser(authClient) { | ||
const { data } = useSWR(authClient, fetchUser, SWRoptions) | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import useSWR from 'swr' | ||
import { panoptes } from '@zooniverse/panoptes-js' | ||
|
||
import { usePanoptesAuth } from './' | ||
|
||
const SWRoptions = { | ||
revalidateIfStale: true, | ||
revalidateOnMount: true, | ||
revalidateOnFocus: true, | ||
revalidateOnReconnect: true, | ||
refreshInterval: 0 | ||
} | ||
|
||
async function fetchProjectRoles({ project_id, user_id, authorization }) { | ||
if (authorization) { | ||
const { body } = await panoptes.get(`/project_roles`, { project_id, user_id }, { authorization }) | ||
const [projectRoles] = body.project_roles | ||
return projectRoles.roles | ||
} | ||
return [] | ||
} | ||
|
||
export default function useProjectRoles(project_id, user_id, authClient) { | ||
const authorization = usePanoptesAuth(user_id, authClient) | ||
const { data } = useSWR({ project_id, user_id, authorization }, fetchProjectRoles, SWRoptions) | ||
return data ?? [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import useSWR from 'swr' | ||
|
||
import { panoptes } from '@zooniverse/panoptes-js' | ||
|
||
const SWRoptions = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.