diff --git a/.github/workflows/test.js.yml b/.github/workflows/test.js.yml index 47c8fbe..0792bbf 100644 --- a/.github/workflows/test.js.yml +++ b/.github/workflows/test.js.yml @@ -38,4 +38,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage/coverage-final.json - fail_ci_if_error: true + fail_ci_if_error: false diff --git a/server/BlaiseAPI/index.ts b/server/BlaiseAPI/index.ts index 563fa23..9ae46cd 100644 --- a/server/BlaiseAPI/index.ts +++ b/server/BlaiseAPI/index.ts @@ -47,9 +47,15 @@ export default function BlaiseAPIRouter(config: CustomConfig, auth: Auth, blaise router.post("/api/users", auth.Middleware, async function (req: Request, res: Response) { const data = req.body; - data.serverParks = [config.ServerPark]; - data.defaultServerPark = config.ServerPark; - + const roleServerParksOverride = config.RoleToServerParksMap[data.role]; + if (roleServerParksOverride != null) { + data.serverParks = roleServerParksOverride; + data.defaultServerPark = roleServerParksOverride[0]; + } else { + const defaultServerPark = config.RoleToServerParksMap["DEFAULT"]; + data.serverParks = defaultServerPark; + data.defaultServerPark = defaultServerPark[0]; + } return res.status(200).json(await blaiseApiClient.createUser(data)); }); diff --git a/server/Config.ts b/server/Config.ts index da0cc73..e7e3f57 100644 --- a/server/Config.ts +++ b/server/Config.ts @@ -1,6 +1,7 @@ import crypto from "crypto"; import pino from "pino"; import { CustomConfig } from "./interfaces/server"; +import role_to_serverparks_map_json from "./role-to-serverparks-map.json"; export function loadConfigFromEnv(): CustomConfig { let { PROJECT_ID, BLAISE_API_URL, SERVER_PARK, SESSION_TIMEOUT } = process.env; @@ -26,6 +27,7 @@ export function loadConfigFromEnv(): CustomConfig { logger.info("SESSION_TIMEOUT environment variable has not been set, using default of 12h"); SESSION_TIMEOUT = "12h"; } + const roleToServerParksMap: { [key: string]: string[] } = role_to_serverparks_map_json; return { BlaiseApiUrl: fixURL(BLAISE_API_URL), @@ -33,7 +35,8 @@ export function loadConfigFromEnv(): CustomConfig { ServerPark: SERVER_PARK, Roles: loadRoles(ROLES), SessionTimeout: SESSION_TIMEOUT, - SessionSecret: sessionSecret(SESSION_SECRET) + SessionSecret: sessionSecret(SESSION_SECRET), + RoleToServerParksMap: roleToServerParksMap }; } diff --git a/server/interfaces/server.ts b/server/interfaces/server.ts index 4a6a347..9a82c4e 100644 --- a/server/interfaces/server.ts +++ b/server/interfaces/server.ts @@ -1,7 +1,9 @@ import { AuthConfig } from "blaise-login-react/blaise-login-react-server"; +import { string } from "prop-types"; export interface CustomConfig extends AuthConfig { BlaiseApiUrl: string ProjectId: string - ServerPark: string + ServerPark: string, + RoleToServerParksMap: { [key: string]: string[] } } \ No newline at end of file diff --git a/server/role-to-serverparks-map.json b/server/role-to-serverparks-map.json new file mode 100644 index 0000000..8682348 --- /dev/null +++ b/server/role-to-serverparks-map.json @@ -0,0 +1,5 @@ +{ + "IPS Manager" : ["gusty", "cma"], + "IPS Field Interviewer" : ["gusty", "cma"], + "DEFAULT" : ["gusty"] +} \ No newline at end of file diff --git a/server/tests/config.test.ts b/server/tests/config.test.ts index 207f45d..587b851 100644 --- a/server/tests/config.test.ts +++ b/server/tests/config.test.ts @@ -16,6 +16,7 @@ describe("Config setup", () => { expect(config.ProjectId).toBe("mock-project"); expect(config.ServerPark).toBe("mock-server-park"); expect(config.BlaiseApiUrl).toBe("http://mock"); + expect(config.RoleToServerParksMap).not.toBeNull(); }); it("should return variables with default string if variables are not defined", () => { @@ -30,5 +31,6 @@ describe("Config setup", () => { expect(config.ProjectId).toBe("ENV_VAR_NOT_SET"); expect(config.ServerPark).toBe("ENV_VAR_NOT_SET"); expect(config.BlaiseApiUrl).toBe("http://ENV_VAR_NOT_SET"); + expect(config.RoleToServerParksMap).not.toBeNull(); }); }); diff --git a/src/ClientConfig.ts b/src/ClientConfig.ts new file mode 100644 index 0000000..9157e5f --- /dev/null +++ b/src/ClientConfig.ts @@ -0,0 +1,11 @@ +export interface ClientConfig { + RoleToServerParksMap: { [key: string]: string[] } ; +} +import role_to_serverparks_map_json from "./role-to-serverparks-map.json"; + +export function loadConfigFromEnv(): ClientConfig { + const roleToServerParksMap: { [key: string]: string[] } = role_to_serverparks_map_json; + return { + RoleToServerParksMap: roleToServerParksMap + }; +} \ No newline at end of file diff --git a/src/pages/users/NewUser.tsx b/src/pages/users/NewUser.tsx index 5b04b2f..6098b44 100644 --- a/src/pages/users/NewUser.tsx +++ b/src/pages/users/NewUser.tsx @@ -10,6 +10,7 @@ import { passwordMatchedValidator, requiredValidator } from "../../form/FormVali import { UserForm } from "../../Interfaces"; import { BreadcrumbItem } from "../../Interfaces"; import Breadcrumbs from "../../Components/Breadcrumbs"; +import { loadConfigFromEnv } from "../../ClientConfig"; function NewUserComponent(): ReactElement { const [buttonLoading, setButtonLoading] = useState(false); @@ -18,6 +19,7 @@ function NewUserComponent(): ReactElement { const [message, setMessage] = useState(""); const [redirect, setRedirect] = useState(false); const [roleList, setRoleList] = useState([]); + const cconfig = loadConfigFromEnv(); async function createNewUser(formData: UserForm) { setUsername(formData.username); @@ -29,6 +31,15 @@ function NewUserComponent(): ReactElement { defaultServerPark: "gusty", serverParks: ["gusty"] }; + const roleServerParksOverride = cconfig.RoleToServerParksMap[role]; + if (roleServerParksOverride != null) { + newUser.serverParks = roleServerParksOverride; + newUser.defaultServerPark = roleServerParksOverride[0]; + } else { + const defaultServerPark = cconfig.RoleToServerParksMap["DEFAULT"]; + newUser.serverParks = defaultServerPark; + newUser.defaultServerPark = defaultServerPark[0]; + } setButtonLoading(true); const created = await addNewUser(newUser); diff --git a/src/pages/users/UsersTable.tsx b/src/pages/users/UsersTable.tsx index 2bd88ac..acb4464 100644 --- a/src/pages/users/UsersTable.tsx +++ b/src/pages/users/UsersTable.tsx @@ -4,6 +4,7 @@ import React, { ReactElement } from "react"; import { UsersTableProps } from "../../Interfaces/usersPage"; function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactElement { + return <> { users && users.length > 0 @@ -18,7 +19,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl Role - Default server park + Server Parks {/**/} {/* Edit user*/} @@ -33,7 +34,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl { - users.map(({ role, defaultServerPark, name }: User) => { + users.map(({ role, name, serverParks }: User) => { return ( @@ -43,7 +44,7 @@ function UsersTable({ users, currentUser, listError }: UsersTableProps): ReactEl {role} - {defaultServerPark} + {serverParks.join(", ")} {/**/} {/* Edit*/} diff --git a/src/pages/users/__snapshots__/Users.test.tsx.snap b/src/pages/users/__snapshots__/Users.test.tsx.snap index c569f04..9502629 100644 --- a/src/pages/users/__snapshots__/Users.test.tsx.snap +++ b/src/pages/users/__snapshots__/Users.test.tsx.snap @@ -98,7 +98,7 @@ Object { scope="col" > - Default server park + Server Parks - Default server park + Server Parks