-
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 (#2940)
- 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. - move `useStores` to the hooks directory.
- Loading branch information
1 parent
2994b07
commit daa07b7
Showing
22 changed files
with
155 additions
and
56 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
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 useStores } from './useStores' | ||
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,19 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
import { useStores } from '@hooks' | ||
import { getBearerToken } from '@store/utils' | ||
|
||
export default function usePanoptesAuth(userID) { | ||
const { authClient } = useStores() | ||
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,17 @@ | ||
import useSWR from 'swr' | ||
|
||
import { useStores } from '@hooks' | ||
|
||
const SWRoptions = { | ||
revalidateIfStale: true, | ||
revalidateOnMount: true, | ||
revalidateOnFocus: true, | ||
revalidateOnReconnect: true, | ||
refreshInterval: 0 | ||
} | ||
|
||
export default function usePanoptesUser() { | ||
const { authClient } = useStores() | ||
const { data } = useSWR('/me', authClient.checkCurrent, 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) { | ||
const authorization = usePanoptesAuth(user_id) | ||
const { data } = useSWR({ project_id, user_id, authorization }, fetchProjectRoles, SWRoptions) | ||
return data ?? [] | ||
} |
File renamed without changes.
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,5 +1,4 @@ | ||
import useSWR from 'swr' | ||
|
||
import { panoptes } from '@zooniverse/panoptes-js' | ||
|
||
const SWRoptions = { | ||
|
Oops, something went wrong.