Skip to content

Commit

Permalink
Configured collections list and barchart (PP-1535, PP-1536 & PP-1537) (
Browse files Browse the repository at this point in the history
…#124)

* Restrict roles to allowed values.

* Add some business rule hooks.

* Configured collections refactor.

* Factor out a StatsGroup component.

* Update patron stats and factor out more components.
  • Loading branch information
tdilauro authored Aug 15, 2024
1 parent ffdd3f0 commit 668f286
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 409 deletions.
27 changes: 27 additions & 0 deletions src/businessRules/roleBasedAccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 `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();
};
Loading

0 comments on commit 668f286

Please sign in to comment.