Skip to content
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

custom-scopes: misc bugs #8281

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/client/src/components/interface/Navigation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ describe('Given a user with scopes views Navigation', () => {
describe('Sent for approval', async () => {
const id = `#navigation_${WORKQUEUE_TABS.sentForApproval}`

const requiredScopes = [SCOPES.RECORD_SUBMIT_FOR_APPROVAL] as Scope[]
const requiredScopes = [
SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
] as Scope[]

const allOtherScopes = allScopes.filter(
(scope) => !requiredScopes.includes(scope)
Expand Down Expand Up @@ -447,12 +450,8 @@ describe('Given a user with scopes views Navigation', () => {
const id = `#navigation_${WORKQUEUE_TABS.outbox}`

const requiredScopes = [
SCOPES.RECORD_DECLARE_BIRTH,
SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION,
SCOPES.RECORD_DECLARE_DEATH,
SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION,
SCOPES.RECORD_DECLARE_MARRIAGE,
SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION,
SCOPES.RECORD_SUBMIT_INCOMPLETE,
SCOPES.RECORD_SUBMIT_FOR_REVIEW,
SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
SCOPES.RECORD_SUBMIT_FOR_UPDATES,
SCOPES.RECORD_REVIEW_DUPLICATES,
Expand Down
5 changes: 1 addition & 4 deletions packages/client/src/hooks/useAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export const RECORD_ALLOWED_SCOPES = {
UPDATE: [
SCOPES.RECORD_REGISTER,
SCOPES.RECORD_SUBMIT_FOR_UPDATES,
SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
SCOPES.RECORD_DECLARE_BIRTH,
SCOPES.RECORD_DECLARE_DEATH,
SCOPES.RECORD_DECLARE_MARRIAGE
SCOPES.RECORD_SUBMIT_FOR_APPROVAL
],
REVIEW: [
SCOPES.RECORD_REGISTER,
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/hooks/useNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const routeAccess: NavigationConfig[] = [
{
name: WORKQUEUE_TABS.outbox,
scopes: [
SCOPES.RECORD_SUBMIT_INCOMPLETE,
SCOPES.RECORD_SUBMIT_FOR_REVIEW,
SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
SCOPES.RECORD_SUBMIT_FOR_UPDATES,
SCOPES.RECORD_REVIEW_DUPLICATES,
Expand Down
22 changes: 17 additions & 5 deletions packages/client/src/user/userReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ export const userFormReducer: LoopReducer<IUserFormState, UserFormAction> = (
const roleScopes = (role: string) =>
userRoles.find(({ id }) => id === role)?.scopes ?? []

const canCreateOrUpdateAll = [
SCOPES.USER_CREATE,
SCOPES.USER_UPDATE
].some((scope) => loggedInUserScopes.includes(scope))

const canCreateOrUpdateJurisdiction = [
SCOPES.USER_CREATE_MY_JURISDICTION,
SCOPES.USER_UPDATE_MY_JURISDICTION
].some((scope) => loggedInUserScopes.includes(scope))

const form = deserializeForm(getCreateUserForm(), validators)

const modifiedForm = modifyFormField(
Expand All @@ -406,11 +416,13 @@ export const userFormReducer: LoopReducer<IUserFormState, UserFormAction> = (
options: userRoles
.filter(
({ id }) =>
loggedInUserScopes.includes(SCOPES.USER_CREATE) ||
(loggedInUserScopes.includes(
SCOPES.USER_CREATE_MY_JURISDICTION
) &&
!roleScopes(id).includes(SCOPES.USER_CREATE))
canCreateOrUpdateAll ||
(canCreateOrUpdateJurisdiction &&
!roleScopes(id).some((scope) =>
(
[SCOPES.USER_CREATE, SCOPES.USER_UPDATE] as string[]
).includes(scope)
))
)
.map((role) => ({
value: role.id,
Expand Down
Loading