-
Notifications
You must be signed in to change notification settings - Fork 0
A big collection of fixes related to translations and TanStack Query, and packages update. #130
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
Changes from 1 commit
dce4d45
9c547c3
df18dab
b568425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,9 @@ export interface AccessBarrierProps extends Pick<QueryBarrierProps, "Error" | "P | |
| facilityUrl?: string; | ||
| } | ||
|
|
||
| /** The roles for which querying facility permissions is necessary. */ | ||
| const FACILITY_ROLES = new Set<PermissionKey>(["facilityMember", "facilityClient", "facilityStaff", "facilityAdmin"]); | ||
|
|
||
| /** | ||
| * Utility component that checks authentication | ||
| * state and user's permissions | ||
|
|
@@ -53,12 +56,25 @@ export const AccessBarrier: ParentComponent<AccessBarrierProps> = (props) => { | |
| ); | ||
| const [queryBarrierProps, localProps] = splitProps(merged, ["Error", "Pending"]); | ||
| const facilitiesQuery = createQuery(System.facilitiesQueryOptions); | ||
| const facilityId = () => facilitiesQuery.data?.find(({url}) => url === localProps.facilityUrl)?.id; | ||
|
|
||
| const statusQuery = createQuery(() => User.statusQueryOptions(facilityId())); | ||
| const accessGranted = () => | ||
| statusQuery.isSuccess && localProps.roles?.every((role) => statusQuery.data?.permissions[role]); | ||
|
|
||
| const statusQuery = createQuery(() => { | ||
| // Only load the facility permissions if they are actually checked. | ||
| if (localProps.roles.some((role) => FACILITY_ROLES.has(role))) { | ||
| const facilityId = facilitiesQuery.data?.find(({url}) => url === localProps.facilityUrl)?.id; | ||
| if (facilityId) { | ||
| return User.statusWithFacilityPermissionsQueryOptions(facilityId); | ||
| } | ||
| // If the facility is not available, return statusQueryOptions below, which will fail | ||
|
||
| // the permissions check anyway because the facility permissions fields are false in it. | ||
| } | ||
| return User.statusQueryOptions(); | ||
| }); | ||
| const accessGranted = () => { | ||
| if (!statusQuery.isSuccess) { | ||
| return false; | ||
| } | ||
| const permissions = statusQuery.data!.permissions as Partial<Record<PermissionKey, boolean>>; | ||
| return localProps.roles?.every((role) => permissions[role]); | ||
| }; | ||
| return ( | ||
| <QueryBarrier queries={[statusQuery]} {...queryBarrierProps}> | ||
| <Show when={accessGranted()} fallback={<localProps.Fallback />}> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.