-
Notifications
You must be signed in to change notification settings - Fork 4
/
roleBasedAccess.ts
35 lines (31 loc) · 1.28 KB
/
roleBasedAccess.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useAppAdmin, useAppFeatureFlags } from "../context/appContext";
// Not all methods taking this type will use the specified properties.
// The type is here to ensure that the call site provides the right
// properties, in case the rules change in the future.
type HasLibraryKeyProps = {
library: string; // library "key" or "short name"
[key: string]: unknown;
};
// If the `quicksightOnlyForSysadmins` feature flag is set, only system
// admins should see the QuickSight link.
export const useMaySeeQuickSightLink = (_: HasLibraryKeyProps): boolean => {
const admin = useAppAdmin();
const onlyForSysAdmins = useAppFeatureFlags().quicksightOnlyForSysadmins;
return !onlyForSysAdmins || admin.isSystemAdmin();
};
// If the `reportsOnlyForSysadmins` feature flag is set, only system admins
// may request inventory reports.
export const useMayRequestInventoryReports = (
_: HasLibraryKeyProps
): boolean => {
const admin = useAppAdmin();
const onlyForSysAdmins = useAppFeatureFlags().reportsOnlyForSysadmins;
return !onlyForSysAdmins || admin.isSystemAdmin();
};
// Only system admins may view the collection statistics barchart.
export const useMayViewCollectionBarChart = (
_: HasLibraryKeyProps
): boolean => {
const admin = useAppAdmin();
return admin.isSystemAdmin();
};