@thepalaceproject/circulation-admin 1.22.0-post.8 → 1.23.0-post.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -150,5 +150,5 @@
150
150
  "*.{js,jsx,ts,tsx,css,md}": "prettier --write",
151
151
  "*.{js,css,md}": "prettier --write"
152
152
  },
153
- "version": "1.22.0-post.8"
153
+ "version": "1.23.0-post.1"
154
154
  }
@@ -4,6 +4,7 @@ import { ContextProviderProps } from "../../../src/components/ContextProvider";
4
4
  import { ConfigurationSettings, FeatureFlags } from "../../../src/interfaces";
5
5
  import {
6
6
  useMayRequestInventoryReports,
7
+ useMaySeeQuickSightLink,
7
8
  useMayViewCollectionBarChart,
8
9
  } from "../../../src/businessRules/roleBasedAccess";
9
10
 
@@ -116,6 +117,98 @@ describe("Business rules for role-based access", () => {
116
117
  });
117
118
  });
118
119
 
120
+ describe("controls access to the quicksight link", () => {
121
+ const testAccess = (
122
+ expectedResult: boolean,
123
+ config: Partial<ConfigurationSettings>
124
+ ) => {
125
+ const wrapper = setupWrapper(config);
126
+ const { result } = renderHook(
127
+ () => useMaySeeQuickSightLink({ library: libraryMatch }),
128
+ { wrapper }
129
+ );
130
+ expect(result.current).toBe(expectedResult);
131
+ };
132
+
133
+ it("restricts access to only sysadmins, if the restriction feature flag is true", () => {
134
+ const featureFlags: FeatureFlags = { quicksightOnlyForSysadmins: true };
135
+
136
+ testAccess(true, { roles: [{ role: "system" }], featureFlags });
137
+
138
+ testAccess(false, { roles: [{ role: "manager-all" }], featureFlags });
139
+ testAccess(false, { roles: [{ role: "librarian-all" }], featureFlags });
140
+
141
+ testAccess(false, {
142
+ roles: [{ role: "manager", library: libraryMatch }],
143
+ featureFlags,
144
+ });
145
+ testAccess(false, {
146
+ roles: [{ role: "manager", library: libraryMismatch }],
147
+ featureFlags,
148
+ });
149
+ testAccess(false, {
150
+ roles: [{ role: "librarian", library: libraryMatch }],
151
+ featureFlags,
152
+ });
153
+ testAccess(false, {
154
+ roles: [{ role: "librarian", library: libraryMismatch }],
155
+ featureFlags,
156
+ });
157
+ });
158
+
159
+ it("allows all users, if the restriction feature flag is is false", () => {
160
+ const featureFlags: FeatureFlags = { quicksightOnlyForSysadmins: false };
161
+
162
+ testAccess(true, { roles: [{ role: "system" }], featureFlags });
163
+
164
+ testAccess(true, { roles: [{ role: "manager-all" }], featureFlags });
165
+ testAccess(true, { roles: [{ role: "librarian-all" }], featureFlags });
166
+
167
+ testAccess(true, {
168
+ roles: [{ role: "manager", library: libraryMatch }],
169
+ featureFlags,
170
+ });
171
+ testAccess(true, {
172
+ roles: [{ role: "manager", library: libraryMismatch }],
173
+ featureFlags,
174
+ });
175
+ testAccess(true, {
176
+ roles: [{ role: "librarian", library: libraryMatch }],
177
+ featureFlags,
178
+ });
179
+ testAccess(true, {
180
+ roles: [{ role: "librarian", library: libraryMismatch }],
181
+ featureFlags,
182
+ });
183
+ });
184
+
185
+ it("allows all users, if the restriction feature flag is not set", () => {
186
+ const featureFlags: FeatureFlags = {};
187
+
188
+ testAccess(true, { roles: [{ role: "system" }], featureFlags });
189
+
190
+ testAccess(true, { roles: [{ role: "manager-all" }], featureFlags });
191
+ testAccess(true, { roles: [{ role: "librarian-all" }], featureFlags });
192
+
193
+ testAccess(true, {
194
+ roles: [{ role: "manager", library: libraryMatch }],
195
+ featureFlags,
196
+ });
197
+ testAccess(true, {
198
+ roles: [{ role: "manager", library: libraryMismatch }],
199
+ featureFlags,
200
+ });
201
+ testAccess(true, {
202
+ roles: [{ role: "librarian", library: libraryMatch }],
203
+ featureFlags,
204
+ });
205
+ testAccess(true, {
206
+ roles: [{ role: "librarian", library: libraryMismatch }],
207
+ featureFlags,
208
+ });
209
+ });
210
+ });
211
+
119
212
  describe("controls access to the collection statistics barchart", () => {
120
213
  const testAccess = (
121
214
  expectedResult: boolean,
@@ -434,6 +434,53 @@ describe("Dashboard Statistics", () => {
434
434
  expect(renderFor(false, managerAll)).not.toBeNull();
435
435
  expect(renderFor(false, librarianAll)).not.toBeNull();
436
436
  });
437
+
438
+ it("shows quicksight link only for sysadmins, if sysadmin-only flag set", () => {
439
+ const fakeQuickSightHref = "https://example.com/fakeQS";
440
+
441
+ // We'll use this function to test multiple scenarios.
442
+ const renderFor = (
443
+ onlySysadmins: boolean,
444
+ roles: { role: string; library?: string }[]
445
+ ) => {
446
+ const contextProviderProps: Partial<ContextProviderProps> = {
447
+ featureFlags: { quicksightOnlyForSysadmins: onlySysadmins },
448
+ roles,
449
+ quicksightPagePath: fakeQuickSightHref,
450
+ };
451
+ const {
452
+ container,
453
+ getByRole,
454
+ queryByRole,
455
+ queryByText,
456
+ } = renderWithProviders(<Stats library={sampleLibraryKey} />, {
457
+ contextProviderProps,
458
+ });
459
+
460
+ // We should always render a Usage reports group when a library is specified.
461
+ getByRole("heading", {
462
+ level: 3,
463
+ name: statGroupToHeading.usageReports,
464
+ });
465
+ const usageReportLink = queryByRole("link", { name: /View Usage/i });
466
+ if (usageReportLink) {
467
+ expect(usageReportLink).toHaveAttribute("href", fakeQuickSightHref);
468
+ }
469
+
470
+ // Clean up the container after each render.
471
+ document.body.removeChild(container);
472
+ return usageReportLink;
473
+ };
474
+
475
+ // If the feature flag is set, the link should be visible only to sysadmins.
476
+ expect(renderFor(true, systemAdmin)).not.toBeNull();
477
+ expect(renderFor(true, managerAll)).toBeNull();
478
+ expect(renderFor(true, librarianAll)).toBeNull();
479
+ // If the feature flag is false, the button should be visible to all users.
480
+ expect(renderFor(false, systemAdmin)).not.toBeNull();
481
+ expect(renderFor(false, managerAll)).not.toBeNull();
482
+ expect(renderFor(false, librarianAll)).not.toBeNull();
483
+ });
437
484
  });
438
485
 
439
486
  describe("charting - custom tooltip", () => {