-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(role based view): implemented a role based view for user groups #175
Changes from 9 commits
68542bf
d661433
bd6cce9
a5da740
b71c930
f2c330c
4eb6b8f
987f041
ff38023
f191132
595f276
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ | |
] | ||
}, | ||
{ | ||
"username": "onemac-micro-[email protected]", | ||
"username": "[email protected]", | ||
"attributes": [ | ||
{ | ||
"Name": "email", | ||
|
@@ -172,5 +172,26 @@ | |
"Value": "onemac-micro-statesubmitter" | ||
} | ||
] | ||
}, | ||
{ | ||
"username": "[email protected]", | ||
"attributes": [ | ||
{ | ||
"Name": "email", | ||
"Value": "[email protected]" | ||
}, | ||
{ | ||
"Name": "given_name", | ||
"Value": "bad" | ||
}, | ||
{ | ||
"Name": "family_name", | ||
"Value": "football" | ||
}, | ||
{ | ||
"Name": "email_verified", | ||
"Value": "true" | ||
} | ||
] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ import { Auth } from "aws-amplify"; | |
import { CognitoUserAttributes } from "shared-types"; | ||
import { isCmsUser } from "shared-utils"; | ||
|
||
export const getUser = async () => { | ||
export type OneMacUser = { isCms?: boolean, user: CognitoUserAttributes | null } | ||
|
||
export const getUser = async (): Promise<OneMacUser> => { | ||
try { | ||
const authenticatedUser = await Auth.currentAuthenticatedUser(); | ||
const attributes = await Auth.userAttributes(authenticatedUser); | ||
|
@@ -14,14 +16,14 @@ export const getUser = async () => { | |
}, {}) as unknown as CognitoUserAttributes; | ||
if (user["custom:cms-roles"]) { | ||
const isCms = isCmsUser(user); | ||
return { user, isCms }; | ||
return { user, isCms } satisfies OneMacUser; | ||
} else { | ||
user["custom:cms-roles"] = ""; | ||
return { user, isCms: false }; | ||
return { user, isCms: false } satisfies OneMacUser; | ||
} | ||
} catch (e) { | ||
console.log({ e }); | ||
return { user: null }; | ||
return { user: null } satisfies OneMacUser; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { OneMacUser, useGetUser } from "@/api/useGetUser"; | ||
import { PropsWithChildren, createContext, useContext } from "react"; | ||
|
||
const initialState = { user: null }; | ||
|
||
export const UserContext = createContext<OneMacUser | undefined>(initialState); | ||
export const UserContextProvider = ({ children }: PropsWithChildren) => { | ||
const { data: userData } = useGetUser(); | ||
return ( | ||
<UserContext.Provider value={userData}>{children}</UserContext.Provider> | ||
); | ||
}; | ||
|
||
export const useUserContext = () => useContext(UserContext); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ export const TABLE_COLUMNS = (props?: { isCms?: boolean }): OsTableColumn[] => [ | |
{ | ||
field: "state.keyword", | ||
label: "State", | ||
visible: false, | ||
visible: true, | ||
cell: (data) => data.state, | ||
}, | ||
{ | ||
|
@@ -43,9 +43,9 @@ export const TABLE_COLUMNS = (props?: { isCms?: boolean }): OsTableColumn[] => [ | |
: BLANK_VALUE, | ||
}, | ||
{ | ||
field: props?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword", | ||
field: props?.isCms ? "stateStatus.keyword" : "stateStatus.keyword", | ||
label: "Status", | ||
cell: (data) => (props?.isCms ? data.cmsStatus : data.stateStatus), | ||
cell: (data) => (props?.isCms ? data.stateStatus : data.stateStatus), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines 46 and 48 here are both saying "If the user is CMS, show them the stateStatus, else, show them the stateStatus". Why wouldn't we want to show them the CMS value if they're CMS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on what we talked about, I think the check should be more like
That way we still show CMS statuses to everyone at CMS except the helpdesk as the AC says |
||
}, | ||
{ | ||
field: "submissionDate", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ export const TABLE_COLUMNS = (props?: { isCms?: boolean }): OsTableColumn[] => [ | |
{ | ||
field: "state.keyword", | ||
label: "State", | ||
visible: false, | ||
visible: true, | ||
cell: (data) => data.state, | ||
}, | ||
{ | ||
|
@@ -44,9 +44,9 @@ export const TABLE_COLUMNS = (props?: { isCms?: boolean }): OsTableColumn[] => [ | |
: BLANK_VALUE, | ||
}, | ||
{ | ||
field: props?.isCms ? "cmsStatus.keyword" : "stateStatus.keyword", | ||
field: props?.isCms ? "stateStatus.keyword" : "stateStatus.keyword", | ||
label: "Status", | ||
cell: (data) => (props?.isCms ? data.cmsStatus : data.stateStatus), | ||
cell: (data) => (props?.isCms ? data.stateStatus : data.stateStatus), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
}, | ||
{ | ||
field: "submissionDate", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad football? This must be Sheffield United's email address 😂