-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: use auth with project update/delete * feat: support project delete * fix: wrong auth key * feat: #1171 component with privilege * refactor: simplified auth code
- Loading branch information
Showing
18 changed files
with
263 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const Privileges = { | ||
'member.delete': true, | ||
'member.update': true, | ||
'member.create': true, | ||
'member.read': true, | ||
'project.update': true, | ||
'project.delete': true, | ||
'evaluation.action': true, | ||
'evaluation.create': true, | ||
'runtime.version.revert': true, | ||
'model.version.revert': true, | ||
'dataset.version.revert': true, | ||
} | ||
export type IPrivileges = typeof Privileges | ||
|
||
export enum Role { | ||
OWNER = 'OWNER', | ||
GUEST = 'GUEST', | ||
MAINTAINER = 'MAINTAINER', | ||
NONE = 'NONE', | ||
} | ||
|
||
export const RolePrivilege: Record<Role, any> = { | ||
OWNER: { | ||
...Privileges, | ||
}, | ||
MAINTAINER: { | ||
...Privileges, | ||
'member.update': false, | ||
}, | ||
GUEST: { | ||
'member.read': true, | ||
}, | ||
NONE: {}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react' | ||
import { Role } from '@/api/const' | ||
import { useQuery } from 'react-query' | ||
import { useCurrentUser } from '../../../hooks/useCurrentUser' | ||
import { listProjectRole } from '../services/project' | ||
|
||
export function useFetchProjectRole(projectId: string) { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const { currentUser } = useCurrentUser() | ||
const members = useQuery( | ||
['fetchProjectMembers', projectId], | ||
() => { | ||
return listProjectRole(projectId) | ||
}, | ||
{ refetchOnWindowFocus: false, enabled: false } | ||
) | ||
|
||
React.useEffect(() => { | ||
if (projectId) { | ||
members.refetch() | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [projectId]) | ||
|
||
const role = React.useMemo(() => { | ||
if (!members.data) return Role.NONE | ||
const member = members?.data?.find((m) => { | ||
return m?.user?.id === currentUser?.id | ||
}) | ||
if (!member) return Role.NONE | ||
return (member?.role?.code as Role) ?? Role.NONE | ||
}, [currentUser, members]) | ||
|
||
return { | ||
role, | ||
} | ||
} |
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,10 @@ | ||
import useGlobalState from '@/hooks/global' | ||
|
||
export const useProjectRole = () => { | ||
const [role, setRole] = useGlobalState('role') | ||
|
||
return { | ||
role, | ||
setRole, | ||
} | ||
} |
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
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
Oops, something went wrong.