Skip to content

Commit

Permalink
Restrict roles to allowed values.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Aug 9, 2024
1 parent ffdd3f0 commit 3e0a053
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 45 deletions.
23 changes: 13 additions & 10 deletions src/components/__tests__/IndividualAdminEditForm-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import IndividualAdminEditForm from "../IndividualAdminEditForm";
import EditableInput from "../EditableInput";
import Admin from "../../models/Admin";
import { Button, Form, Panel } from "library-simplified-reusable-components";
import { AdminRoleData, AdminRole } from "../../interfaces";

describe("IndividualAdminEditForm", () => {
let wrapper;
Expand All @@ -18,22 +19,24 @@ describe("IndividualAdminEditForm", () => {
};
const allLibraries = [{ short_name: "nypl" }, { short_name: "bpl" }];

const systemAdmin = [{ role: "system" }];
const managerAll = [{ role: "manager-all" }];
const librarianAll = [{ role: "librarian-all" }];
const nyplManager = [{ role: "manager", library: "nypl" }];
const bplManager = [{ role: "manager", library: "bpl" }];
const bothManager = [
const systemAdmin: AdminRoleData[] = [{ role: "system" }];
const managerAll: AdminRoleData[] = [{ role: "manager-all" }];
const librarianAll: AdminRoleData[] = [{ role: "librarian-all" }];
const nyplManager: AdminRoleData[] = [{ role: "manager", library: "nypl" }];
const bplManager: AdminRoleData[] = [{ role: "manager", library: "bpl" }];
const bothManager: AdminRoleData[] = [
{ role: "manager", library: "nypl" },
{ role: "manager", library: "bpl" },
];
const nyplLibrarian = [{ role: "librarian", library: "nypl" }];
const bplLibrarian = [{ role: "librarian", library: "bpl" }];
const bothLibrarian = [
const nyplLibrarian: AdminRoleData[] = [
{ role: "librarian", library: "nypl" },
];
const bplLibrarian: AdminRoleData[] = [{ role: "librarian", library: "bpl" }];
const bothLibrarian: AdminRoleData[] = [
{ role: "librarian", library: "nypl" },
{ role: "librarian", library: "bpl" },
];
const nyplManagerLibrarianAll = [
const nyplManagerLibrarianAll: AdminRoleData[] = [
{ role: "manager", library: "nypl" },
{ role: "librarian-all" },
];
Expand Down
35 changes: 1 addition & 34 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,9 @@ import AccountPage from "./components/AccountPage";
import SetupPage from "./components/SetupPage";
import ManagePatrons from "./components/ManagePatrons";
import TroubleshootingPage from "./components/TroubleshootingPage";
import { FeatureFlags } from "./interfaces";
import { ConfigurationSettings } from "./interfaces";
import { defaultFeatureFlags } from "./utils/featureFlags";

interface ConfigurationSettings {
/** A token generated by the server to prevent Cross-Site Request Forgery.
The token should be included in an 'X-CSRF-Token' header in any non-GET
requests. */
csrfToken: string;

/** `showCircEventsDownload` controls whether the dashboard will have an
option to download a CSV of circulation events. This should be false if
circulation events are not available for download. */
showCircEventsDownload: boolean;

/** `settingUp` will be true if this is a new circulation manager and the
admin interface has never been used before. The interface will show a page
for configuring admin authentication. The admin will need to set that up
and log in before accessing the rest of the interface. */
settingUp: boolean;

/** `email` will be the email address of the currently logged in admin. */
email?: string;

/** `roles` contains the logged in admin's roles: system administrator,
or library manager or librarian for one or more libraries. */
roles?: {
role: string;
library?: string;
}[];

tos_link_text?: string;
tos_link_href?: string;

featureFlags: FeatureFlags;
}

/** The main admin interface application. Create an instance of this class
to render the app and set up routing. */
class CirculationAdmin {
Expand Down
39 changes: 38 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
/* eslint-disable */

export interface ConfigurationSettings {
/** A token generated by the server to prevent Cross-Site Request Forgery.
The token should be included in an 'X-CSRF-Token' header in any non-GET
requests. */
csrfToken: string;

/** `showCircEventsDownload` controls whether the dashboard will have an
option to download a CSV of circulation events. This should be false if
circulation events are not available for download. */
showCircEventsDownload: boolean;

/** `settingUp` will be true if this is a new circulation manager and the
admin interface has never been used before. The interface will show a page
for configuring admin authentication. The admin will need to set that up
and log in before accessing the rest of the interface. */
settingUp: boolean;

/** `email` will be the email address of the currently logged in admin. */
email?: string;

/** `roles` contains the logged in admin's roles and their associated
libraries, where appropriate. */
roles?: AdminRoleData[];

tos_link_text?: string;
tos_link_href?: string;

featureFlags: FeatureFlags;
}

export interface FeatureFlags {
enableAutoList?: boolean;
reportsOnlyForSysadmins?: boolean;
Expand Down Expand Up @@ -329,9 +359,16 @@ export interface PathFor {
(collectionUrl: string, bookUrl: string, tab?: string): string;
}

export type AdminRole =
| "system"
| "manager-all"
| "manager"
| "librarian-all"
| "librarian";

export interface AdminRoleData {
library?: string;
role: string;
role: AdminRole;
}

export interface IndividualAdminData {
Expand Down

0 comments on commit 3e0a053

Please sign in to comment.