Repository navigation
[Feature/#232] 워크스페이스 역할 기반 접근 제어(RBAC) 도입 #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9ce3812
feat: myRole 필드 추가. mainLayout 초기 로드시 role 세팅, workspaceSwitcher 전환시 …
jjjsun 6a56978
feat: RoleGuard 컴포넌트 구현
jjjsun 7e2116b
feat: ADMIN 전용 라우트에 RoleGuard 적용, RoleGuard함수 반환타입 명시 추가
jjjsun d761481
feat: INavItem에 requiredRole 추가 + 사이드바 필터링 구현
jjjsun 2b87133
feat: useIsAdmin훅 생성
jjjsun b1ef77d
feat: useIsAdmin훅 버튼 처리
jjjsun b227a8d
fix: 워크스페이스별 role로 인가되도록 설정
jjjsun 0beda2f
fix: 쿼리 실패시 null 고정되어서 화면 비는 문제 해결
jjjsun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| import useWorkspaceStore from "@/store/useWorkspaceStore"; | ||
|
|
||
| /*useWorkspaceStore에서 myRole을 읽어서 booelan으로 반환하는 훅*/ | ||
| function useIsAdmin(): boolean { | ||
| const myRole = useWorkspaceStore((s) => s.myRole); | ||
| return myRole === "ADMIN"; | ||
| } | ||
|
|
||
| export default useIsAdmin; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
| import type { ReactElement, ReactNode } from "react"; | ||
| import { Navigate, useParams } from "react-router-dom"; | ||
|
|
||
| import type { TMemberRole } from "@/types/workspace/workspace"; | ||
|
|
||
| import { useCoreQuery } from "@/hooks/customQuery"; | ||
|
|
||
| import { getMyWorkspaces } from "@/api/workspace/org"; | ||
| import useWorkspaceStore from "@/store/useWorkspaceStore"; | ||
|
|
||
| interface IRoleGuardProps { | ||
| children: ReactNode; | ||
| allowedRoles: TMemberRole[]; | ||
| } | ||
|
|
||
| function RoleGuard({ | ||
| children, | ||
| allowedRoles, | ||
| }: IRoleGuardProps): ReactElement | null { | ||
| const { workspaceId } = useParams<{ workspaceId?: string }>(); | ||
| const myRole = useWorkspaceStore((s) => s.myRole); | ||
| const { | ||
| data: workspaces, | ||
| isPending, | ||
| isError, | ||
| } = useCoreQuery(["my-workspaces"], getMyWorkspaces); | ||
|
|
||
| //URL에 workspaceId가 있는 경우 -> URL 기준 워크스페이스의 role로 판정 | ||
| if (workspaceId) { | ||
| //워크스페이스 목록 로드 전 -> 랜더 보류 | ||
| if (isPending) { | ||
| return null; | ||
| } | ||
| if (isError || !workspaces) { | ||
| return <Navigate to="/dashboard" replace />; | ||
| } | ||
| const targetWorkspace = workspaces.find( | ||
| (w) => w.orgId === Number(workspaceId), | ||
| ); | ||
|
|
||
| //URL의 workspaceId가 내 워크스페이스 목록에 없는 경우 -> 대시보드로 | ||
| if (!targetWorkspace) { | ||
| return <Navigate to="/dashboard" replace />; | ||
| } | ||
|
|
||
| if (!allowedRoles.includes(targetWorkspace.myRole)) { | ||
| return <Navigate to="/dashboard" replace />; | ||
| } | ||
| return <>{children}</>; | ||
| } | ||
|
|
||
| //워크스페이스 초기화 전(null)에 랜더 보류 | ||
| if (myRole === null) { | ||
| return null; | ||
| } | ||
| if (!allowedRoles.includes(myRole)) { | ||
| return <Navigate to="/dashboard" replace />; | ||
| } | ||
| return <>{children}</>; | ||
| } | ||
|
|
||
| export default RoleGuard; | ||
This file contains hidden or 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,13 +1,19 @@ | ||
| import { create } from "zustand"; | ||
|
|
||
| import type { TMemberRole } from "@/types/workspace/workspace"; | ||
|
|
||
| interface IWorkspaceState { | ||
| selectedOrgId: number | null; | ||
| myRole: TMemberRole | null; | ||
| setSelectedOrgId: (orgId: number) => void; | ||
| setMyRole: (role: TMemberRole | null) => void; | ||
| } | ||
|
|
||
| const useWorkspaceStore = create<IWorkspaceState>((set) => ({ | ||
| selectedOrgId: null, | ||
| myRole: null, | ||
| setSelectedOrgId: (orgId) => set({ selectedOrgId: orgId }), | ||
| setMyRole: (role) => set({ myRole: role }), | ||
| })); | ||
|
|
||
| export default useWorkspaceStore; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.