diff --git a/api/src/constants/database.ts b/api/src/constants/database.ts index 2c7d1d11eb..e3e2a98fa7 100644 --- a/api/src/constants/database.ts +++ b/api/src/constants/database.ts @@ -1,5 +1,5 @@ export enum SYSTEM_IDENTITY_SOURCE { DATABASE = 'DATABASE', IDIR = 'IDIR', - BCEID = 'BCEID' + BCEID = 'BCEID-BASIC-AND-BUSINESS' } diff --git a/api/src/paths/access-request.test.ts b/api/src/paths/access-request.test.ts index 36136cb097..9309dfc513 100644 --- a/api/src/paths/access-request.test.ts +++ b/api/src/paths/access-request.test.ts @@ -1,20 +1,21 @@ import chai, { expect } from 'chai'; import { describe } from 'mocha'; +import { QueryResult } from 'pg'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import SQL from 'sql-template-strings'; +import { SYSTEM_IDENTITY_SOURCE } from '../constants/database'; import * as db from '../database/db'; import { HTTPError } from '../errors/custom-error'; +import { IgcNotifyPostReturn } from '../models/gcnotify'; import { UserObject } from '../models/user'; import * as administrative_activity from '../paths/administrative-activity'; +import { queries } from '../queries/queries'; +import { GCNotifyService } from '../services/gcnotify-service'; +import { KeycloakService, KeycloakUser } from '../services/keycloak-service'; import { UserService } from '../services/user-service'; import { getMockDBConnection, getRequestHandlerMocks } from '../__mocks__/db'; import * as access_request from './access-request'; -import { queries } from '../queries/queries'; -import SQL from 'sql-template-strings'; -import { QueryResult } from 'pg'; -import { KeycloakService, KeycloakUser } from '../services/keycloak-service'; -import { IgcNotifyPostReturn } from '../models/gcnotify'; -import { GCNotifyService } from '../services/gcnotify-service'; chai.use(sinonChai); @@ -245,7 +246,7 @@ describe('updateAccessRequest', () => { .stub(GCNotifyService.prototype, 'sendEmailGCNotification') .resolves(GCNotifyPostReturnObject); - await access_request.sendApprovalEmail(2, mockDBConnection, 'name', 'idir'); + await access_request.sendApprovalEmail(2, mockDBConnection, 'name', SYSTEM_IDENTITY_SOURCE.IDIR); expect(queriesStub).to.be.calledOnce; expect(getUserByUsernameStub).to.be.calledOnce; diff --git a/api/src/paths/project/{projectId}/participants/create.test.ts b/api/src/paths/project/{projectId}/participants/create.test.ts index 1971b6d530..350d864821 100644 --- a/api/src/paths/project/{projectId}/participants/create.test.ts +++ b/api/src/paths/project/{projectId}/participants/create.test.ts @@ -2,6 +2,7 @@ import chai, { expect } from 'chai'; import { describe } from 'mocha'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import { SYSTEM_IDENTITY_SOURCE } from '../../../../constants/database'; import * as db from '../../../../database/db'; import { HTTPError } from '../../../../errors/custom-error'; import { UserService } from '../../../../services/user-service'; @@ -16,7 +17,7 @@ describe('createProjectParticipants', () => { const sampleReq = { keycloak_token: {}, body: { - participants: [['jsmith', 'IDIR', 1]] + participants: [['jsmith', SYSTEM_IDENTITY_SOURCE.IDIR, 1]] }, params: { projectId: 1 diff --git a/api/src/paths/project/{projectId}/participants/create.ts b/api/src/paths/project/{projectId}/participants/create.ts index 11f5344ce8..b06dd1d135 100644 --- a/api/src/paths/project/{projectId}/participants/create.ts +++ b/api/src/paths/project/{projectId}/participants/create.ts @@ -1,5 +1,6 @@ import { RequestHandler } from 'express'; import { Operation } from 'express-openapi'; +import { SYSTEM_IDENTITY_SOURCE } from '../../../../constants/database'; import { PROJECT_ROLE } from '../../../../constants/roles'; import { getDBConnection, IDBConnection } from '../../../../database/db'; import { HTTP400 } from '../../../../errors/custom-error'; @@ -62,7 +63,7 @@ POST.apiDoc = { }, identitySource: { type: 'string', - enum: ['IDIR', 'BCEID'] + enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID] }, roleId: { description: 'The id of the project role to assign to the participant.', diff --git a/api/src/paths/user.ts b/api/src/paths/user.ts index 5ca22b9a7e..6b39b67c8e 100644 --- a/api/src/paths/user.ts +++ b/api/src/paths/user.ts @@ -1,5 +1,6 @@ import { RequestHandler } from 'express'; import { Operation } from 'express-openapi'; +import { SYSTEM_IDENTITY_SOURCE } from '../constants/database'; import { SYSTEM_ROLE } from '../constants/roles'; import { getDBConnection } from '../database/db'; import { HTTP400 } from '../errors/custom-error'; @@ -45,7 +46,7 @@ DELETE.apiDoc = { }, identitySource: { type: 'string', - enum: ['idir', 'bceid'] + enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID] } } } diff --git a/api/src/paths/user/add.test.ts b/api/src/paths/user/add.test.ts index d32a4ff94b..594633bb58 100644 --- a/api/src/paths/user/add.test.ts +++ b/api/src/paths/user/add.test.ts @@ -2,6 +2,7 @@ import chai, { expect } from 'chai'; import { describe } from 'mocha'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; +import { SYSTEM_IDENTITY_SOURCE } from '../../constants/database'; import * as db from '../../database/db'; import { HTTPError } from '../../errors/custom-error'; import { UserObject } from '../../models/user'; @@ -45,7 +46,7 @@ describe('user', () => { const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); mockReq.body = { - identitySource: 'IDIR', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }; @@ -92,7 +93,7 @@ describe('user', () => { mockReq.body = { userIdentifier: 'username', - identitySource: 'IDIR' + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR }; try { @@ -115,7 +116,7 @@ describe('user', () => { mockReq.body = { userIdentifier: 'username', - identitySource: 'IDIR', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }; diff --git a/api/src/paths/user/add.ts b/api/src/paths/user/add.ts index 5dbae93f4c..8d761453dd 100644 --- a/api/src/paths/user/add.ts +++ b/api/src/paths/user/add.ts @@ -6,6 +6,7 @@ import { HTTP400 } from '../../errors/custom-error'; import { authorizeRequestHandler } from '../../request-handlers/security/authorization'; import { UserService } from '../../services/user-service'; import { getLogger } from '../../utils/logger'; +import { SYSTEM_IDENTITY_SOURCE } from '../../constants/database'; const defaultLog = getLogger('paths/user/add'); @@ -45,7 +46,7 @@ POST.apiDoc = { }, identitySource: { type: 'string', - enum: ['idir', 'bceid'] + enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID] }, roleId: { type: 'number', diff --git a/api/src/services/user-service.test.ts b/api/src/services/user-service.test.ts index 356df28a77..39fd18d5bc 100644 --- a/api/src/services/user-service.test.ts +++ b/api/src/services/user-service.test.ts @@ -4,6 +4,7 @@ import { QueryResult } from 'pg'; import sinon from 'sinon'; import sinonChai from 'sinon-chai'; import SQL from 'sql-template-strings'; +import { SYSTEM_IDENTITY_SOURCE } from '../constants/database'; import { ApiError } from '../errors/custom-error'; import { UserObject } from '../models/user'; import { queries } from '../queries/queries'; @@ -128,7 +129,7 @@ describe('UserService', () => { sinon.stub(queries.users, 'addSystemUserSQL').returns(null); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; try { await userService.addSystemUser(userIdentifier, identitySource); @@ -147,7 +148,7 @@ describe('UserService', () => { sinon.stub(queries.users, 'addSystemUserSQL').returns(SQL`valid sql`); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; try { await userService.addSystemUser(userIdentifier, identitySource); @@ -168,7 +169,7 @@ describe('UserService', () => { const addSystemUserSQLStub = sinon.stub(queries.users, 'addSystemUserSQL').returns(SQL`valid sql`); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const result = await userService.addSystemUser(userIdentifier, identitySource); @@ -255,7 +256,7 @@ describe('UserService', () => { const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser'); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const userService = new UserService(mockDBConnection); @@ -285,7 +286,7 @@ describe('UserService', () => { const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser'); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const userService = new UserService(mockDBConnection); @@ -304,7 +305,7 @@ describe('UserService', () => { const existingInactiveSystemUser = new UserObject({ system_user_id: 2, - user_identifier: 'idir', + user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR, record_end_date: null, role_ids: [1], role_names: ['Editor'] @@ -318,7 +319,7 @@ describe('UserService', () => { const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser'); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const userService = new UserService(mockDBConnection); @@ -337,7 +338,7 @@ describe('UserService', () => { const existingSystemUser = new UserObject({ system_user_id: 2, - user_identifier: 'idir', + user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR, record_end_date: '2021-11-22', role_ids: [1], role_names: ['Editor'] @@ -354,7 +355,7 @@ describe('UserService', () => { const getUserByIdStub = sinon.stub(UserService.prototype, 'getUserById').resolves(activatedSystemUser); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const userService = new UserService(mockDBConnection); @@ -376,7 +377,7 @@ describe('UserService', () => { const existingSystemUser = new UserObject({ system_user_id: 2, - user_identifier: 'idir', + user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR, record_end_date: '2021-11-22', role_ids: [1], role_names: ['Editor'] @@ -391,7 +392,7 @@ describe('UserService', () => { const activatedSystemUser = new UserObject({ system_user_id: 2, - user_identifier: 'idir', + user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR, record_end_date: null, role_ids: [1], role_names: ['Editor'] @@ -399,7 +400,7 @@ describe('UserService', () => { const getUserByIdStub = sinon.stub(UserService.prototype, 'getUserById').resolves(activatedSystemUser); const userIdentifier = 'username'; - const identitySource = 'idir'; + const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR; const userService = new UserService(mockDBConnection); diff --git a/api/src/utils/keycloak-utils.test.ts b/api/src/utils/keycloak-utils.test.ts index e2f5b2b40f..452ae9c5d6 100644 --- a/api/src/utils/keycloak-utils.test.ts +++ b/api/src/utils/keycloak-utils.test.ts @@ -67,7 +67,7 @@ describe('getUserIdentitySource', () => { }); it('returns non null response when valid keycloakToken provided with bceid source', () => { - const response = getUserIdentitySource({ preferred_username: 'username@bceid' }); + const response = getUserIdentitySource({ preferred_username: 'username@bceid-basic-and-business' }); expect(response).to.equal(SYSTEM_IDENTITY_SOURCE.BCEID); }); diff --git a/app/package-lock.json b/app/package-lock.json index 3f743cadda..c410ce0a34 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -7189,9 +7189,9 @@ } }, "follow-redirects": { - "version": "1.14.7", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", - "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==" + "version": "1.14.8", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz", + "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==" }, "for-each": { "version": "0.3.3", @@ -16882,9 +16882,9 @@ } }, "url-parse": { - "version": "1.4.7", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.7.tgz", - "integrity": "sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.7.tgz", + "integrity": "sha512-HxWkieX+STA38EDk7CE9MEryFeHCKzgagxlGvsdS7WBImq9Mk+PGwiT56w82WI3aicwJA8REp42Cxo98c8FZMA==", "dev": true, "requires": { "querystringify": "^2.1.1", diff --git a/app/src/components/layout/Header.test.tsx b/app/src/components/layout/Header.test.tsx index 0f7bc9d2bb..b79ba5edab 100644 --- a/app/src/components/layout/Header.test.tsx +++ b/app/src/components/layout/Header.test.tsx @@ -4,7 +4,7 @@ import { AuthStateContext } from 'contexts/authStateContext'; import { createMemoryHistory } from 'history'; import React from 'react'; import { Router } from 'react-router-dom'; -import Header from './Header'; +import Header, { SYSTEM_IDENTITY_SOURCE } from './Header'; const history = createMemoryHistory(); @@ -73,7 +73,7 @@ describe('Header', () => { getUserIdentifier: () => 'testuser', hasAccessRequest: false, hasSystemRole: mockHasSystemRole, - getIdentitySource: () => 'bceid', + getIdentitySource: () => SYSTEM_IDENTITY_SOURCE.BCEID, username: 'testusername', displayName: 'testdisplayname', email: 'test@email.com', @@ -109,7 +109,7 @@ describe('Header', () => { getUserIdentifier: () => 'testuser', hasAccessRequest: false, hasSystemRole: jest.fn(), - getIdentitySource: () => 'bceid', + getIdentitySource: () => SYSTEM_IDENTITY_SOURCE.BCEID, username: 'testusername', displayName: 'testdisplayname', email: 'test@email.com', diff --git a/app/src/components/layout/Header.tsx b/app/src/components/layout/Header.tsx index 3a49bc54b9..8d76363a38 100644 --- a/app/src/components/layout/Header.tsx +++ b/app/src/components/layout/Header.tsx @@ -113,6 +113,12 @@ const useStyles = makeStyles((theme: Theme) => ({ } })); +export enum SYSTEM_IDENTITY_SOURCE { + DATABASE = 'DATABASE', + IDIR = 'IDIR', + BCEID = 'BCEID-BASIC-AND-BUSINESS' +} + const Header: React.FC = () => { const classes = useStyles(); const config = useContext(ConfigContext); @@ -121,7 +127,12 @@ const Header: React.FC = () => { // Authenticated view const LoggedInUser = () => { - const loggedInUserDisplayName = `${keycloakWrapper?.getIdentitySource()} / ${keycloakWrapper?.getUserIdentifier()}`.toUpperCase(); + const identitySource = keycloakWrapper?.getIdentitySource()?.toUpperCase(); + + const userIdentifier = keycloakWrapper?.getUserIdentifier()?.toUpperCase(); + + const loggedInUserDisplayName = + identitySource === SYSTEM_IDENTITY_SOURCE.BCEID ? `BCEID / ${userIdentifier}` : `IDIR / ${userIdentifier}`; return ( diff --git a/app/src/features/admin/users/AccessRequestList.test.tsx b/app/src/features/admin/users/AccessRequestList.test.tsx index 4415072548..7362213faf 100644 --- a/app/src/features/admin/users/AccessRequestList.test.tsx +++ b/app/src/features/admin/users/AccessRequestList.test.tsx @@ -1,10 +1,11 @@ -import { codes } from 'test-helpers/code-helpers'; import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import AccessRequestList from 'features/admin/users/AccessRequestList'; +import { useBiohubApi } from 'hooks/useBioHubApi'; import { IAccessRequestDataObject, IGetAccessRequestsListResponse } from 'interfaces/useAdminApi.interface'; import { IGetAllCodeSetsResponse } from 'interfaces/useCodesApi.interface'; import React from 'react'; -import { useBiohubApi } from 'hooks/useBioHubApi'; +import { codes } from 'test-helpers/code-helpers'; jest.mock('../../../hooks/useBioHubApi'); const mockUseBiohubApi = { @@ -59,10 +60,11 @@ describe('AccessRequestList', () => { username: 'testusername', email: 'email@email.com', role: 2, - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, company: 'test company', regional_offices: [1, 2], - comments: 'test comment' + comments: 'test comment', + request_reason: 'my reason' }, create_date: '2020-04-20' } @@ -95,10 +97,11 @@ describe('AccessRequestList', () => { username: 'testusername', email: 'email@email.com', role: 2, - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, company: 'test company', regional_offices: [1, 2], - comments: 'test comment' + comments: 'test comment', + request_reason: 'my reason' }, create_date: '2020-04-20' } @@ -131,10 +134,11 @@ describe('AccessRequestList', () => { username: 'testusername', email: 'email@email.com', role: 2, - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, company: 'test company', regional_offices: [1, 2], - comments: 'test comment' + comments: 'test comment', + request_reason: 'my reason' }, create_date: '2020-04-20' } @@ -194,10 +198,11 @@ describe('AccessRequestList', () => { username: 'testusername', email: 'email@email.com', role: 2, - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, company: 'test company', regional_offices: [1, 2], - comments: 'test comment' + comments: 'test comment', + request_reason: 'my reason' }, create_date: '2020-04-20' } @@ -219,7 +224,13 @@ describe('AccessRequestList', () => { await waitFor(() => { expect(refresh).toHaveBeenCalledTimes(1); expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledTimes(1); - expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledWith('testusername', 'idir', 1, 2, [2]); + expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledWith( + 'testusername', + SYSTEM_IDENTITY_SOURCE.IDIR, + 1, + 2, + [2] + ); }); }); @@ -241,10 +252,11 @@ describe('AccessRequestList', () => { username: 'testusername', email: 'email@email.com', role: 1, - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, company: 'test company', regional_offices: [1, 2], - comments: 'test comment' + comments: 'test comment', + request_reason: 'my reason' }, create_date: '2020-04-20' } @@ -266,7 +278,12 @@ describe('AccessRequestList', () => { await waitFor(() => { expect(refresh).toHaveBeenCalledTimes(1); expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledTimes(1); - expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledWith('testusername', 'idir', 1, 3); + expect(mockBiohubApi().admin.updateAccessRequest).toHaveBeenCalledWith( + 'testusername', + SYSTEM_IDENTITY_SOURCE.IDIR, + 1, + 3 + ); }); }); }); diff --git a/app/src/features/admin/users/AddSystemUsersForm.tsx b/app/src/features/admin/users/AddSystemUsersForm.tsx index d0e4eb7cf3..d1b0cacb38 100644 --- a/app/src/features/admin/users/AddSystemUsersForm.tsx +++ b/app/src/features/admin/users/AddSystemUsersForm.tsx @@ -10,6 +10,7 @@ import Select from '@material-ui/core/Select'; import { mdiPlus, mdiTrashCanOutline } from '@mdi/js'; import Icon from '@mdi/react'; import CustomTextField from 'components/fields/CustomTextField'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import { FieldArray, useFormikContext } from 'formik'; import React from 'react'; import yup from 'utils/YupSchema'; @@ -94,10 +95,10 @@ const AddSystemUsersForm: React.FC = (props) => { error={identitySourceMeta.touched && Boolean(identitySourceMeta.error)} displayEmpty inputProps={{ 'aria-label': 'Login Method' }}> - + IDIR - + BCEID diff --git a/app/src/features/admin/users/ReviewAccessRequestForm.test.tsx b/app/src/features/admin/users/ReviewAccessRequestForm.test.tsx index 4b7cd0d1be..7a88714acb 100644 --- a/app/src/features/admin/users/ReviewAccessRequestForm.test.tsx +++ b/app/src/features/admin/users/ReviewAccessRequestForm.test.tsx @@ -1,4 +1,5 @@ import { render, waitFor } from '@testing-library/react'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import ReviewAccessRequestForm, { ReviewAccessRequestFormYupSchema } from 'features/admin/users/ReviewAccessRequestForm'; @@ -44,7 +45,7 @@ describe('ReviewAccessRequestForm', () => { name: 'test data name', username: 'test data username', email: 'test data email', - identitySource: 'idir', + identitySource: SYSTEM_IDENTITY_SOURCE.IDIR, role: 2, company: 'test data company', regional_offices: [1], diff --git a/app/src/features/projects/participants/AddProjectParticipantsForm.tsx b/app/src/features/projects/participants/AddProjectParticipantsForm.tsx index da7465dd0f..f8bc7e4e2e 100644 --- a/app/src/features/projects/participants/AddProjectParticipantsForm.tsx +++ b/app/src/features/projects/participants/AddProjectParticipantsForm.tsx @@ -9,6 +9,7 @@ import Select from '@material-ui/core/Select'; import { mdiPlus, mdiTrashCanOutline } from '@mdi/js'; import Icon from '@mdi/react'; import CustomTextField from 'components/fields/CustomTextField'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import { FieldArray, useFormikContext } from 'formik'; import React from 'react'; import yup from 'utils/YupSchema'; @@ -97,10 +98,10 @@ const AddProjectParticipantsForm: React.FC = (p onChange={handleChange} displayEmpty inputProps={{ 'aria-label': 'Login Method' }}> - + IDIR - + BCEID diff --git a/app/src/features/surveys/view/SurveyPage.test.tsx b/app/src/features/surveys/view/SurveyPage.test.tsx index 4cb81a508f..cace737b80 100644 --- a/app/src/features/surveys/view/SurveyPage.test.tsx +++ b/app/src/features/surveys/view/SurveyPage.test.tsx @@ -1,4 +1,5 @@ import { cleanup, render, waitFor } from '@testing-library/react'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import { SYSTEM_ROLE } from 'constants/roles'; import { AuthStateContext, IAuthState } from 'contexts/authStateContext'; import { DialogContextProvider } from 'contexts/dialogContext'; @@ -43,7 +44,7 @@ const defaultAuthState = { getUserIdentifier: () => 'testuser', hasAccessRequest: false, hasSystemRole: () => true, - getIdentitySource: () => 'idir', + getIdentitySource: () => SYSTEM_IDENTITY_SOURCE.IDIR, username: 'testusername', displayName: 'testdisplayname', email: 'test@email.com', diff --git a/app/src/interfaces/useAdminApi.interface.ts b/app/src/interfaces/useAdminApi.interface.ts index 9abce116f3..85ffa479bb 100644 --- a/app/src/interfaces/useAdminApi.interface.ts +++ b/app/src/interfaces/useAdminApi.interface.ts @@ -19,7 +19,6 @@ export interface IGetAccessRequestsListResponse { description: string; notes: string; create_date: string; - data: IAccessRequestDataObject; } diff --git a/app/src/pages/access/AccessRequestPage.tsx b/app/src/pages/access/AccessRequestPage.tsx index 3ee1b15c80..9097268d69 100644 --- a/app/src/pages/access/AccessRequestPage.tsx +++ b/app/src/pages/access/AccessRequestPage.tsx @@ -7,6 +7,7 @@ import { Theme } from '@material-ui/core/styles/createMuiTheme'; import makeStyles from '@material-ui/core/styles/makeStyles'; import Typography from '@material-ui/core/Typography'; import { IErrorDialogProps } from 'components/dialog/ErrorDialog'; +import { SYSTEM_IDENTITY_SOURCE } from 'components/layout/Header'; import { AccessRequestI18N } from 'constants/i18n'; import { AuthStateContext } from 'contexts/authStateContext'; import { DialogContext } from 'contexts/dialogContext'; @@ -145,7 +146,7 @@ export const AccessRequestPage: React.FC = () => { let validationSchema: any; let requestForm: any; - if (keycloakWrapper?.getIdentitySource()?.toLowerCase() === 'bceid') { + if (keycloakWrapper?.getIdentitySource()?.toUpperCase() === SYSTEM_IDENTITY_SOURCE.BCEID) { initialValues = BCeIDRequestFormInitialValues; validationSchema = BCeIDRequestFormYupSchema; requestForm = ; diff --git a/database/src/migrations/20220217010922_update_user_identity_source.ts b/database/src/migrations/20220217010922_update_user_identity_source.ts new file mode 100644 index 0000000000..7848c869c5 --- /dev/null +++ b/database/src/migrations/20220217010922_update_user_identity_source.ts @@ -0,0 +1,25 @@ +import * as Knex from 'knex'; +import { SYSTEM_IDENTITY_SOURCE } from 'seeds/01_db_system_users'; + +const DB_SCHEMA = process.env.DB_SCHEMA; + +export async function up(knex: Knex): Promise { + await knex.raw(` + SET SCHEMA '${DB_SCHEMA}'; + SET SEARCH_PATH = ${DB_SCHEMA},public; + + UPDATE user_identity_source SET name = ${SYSTEM_IDENTITY_SOURCE.BCEID} WHERE name = 'BCEID'; + + SET SEARCH_PATH = biohub_dapi_v1,public; + SET ROLE biohub_api; + + CREATE OR REPLACE VIEW user_identity_source AS SELECT * FROM ${DB_SCHEMA}.user_identity_source; + + SET ROLE postgres; + SET SEARCH_PATH = ${DB_SCHEMA},public; + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(''); +} diff --git a/database/src/seeds/01_db_system_users.ts b/database/src/seeds/01_db_system_users.ts index d293076236..ac6efdc2aa 100644 --- a/database/src/seeds/01_db_system_users.ts +++ b/database/src/seeds/01_db_system_users.ts @@ -3,27 +3,33 @@ import Knex from 'knex'; const DB_SCHEMA = process.env.DB_SCHEMA; const DB_ADMIN = process.env.DB_ADMIN; +export enum SYSTEM_IDENTITY_SOURCE { + DATABASE = 'DATABASE', + IDIR = 'IDIR', + BCEID = 'BCEID-BASIC-AND-BUSINESS' +} + const systemUsers = [ - { identifier: 'aagahche', type: 'IDIR', roleId: 1 }, - { identifier: 'cgarrett', type: 'IDIR', roleId: 1 }, - { identifier: 'istest1', type: 'IDIR', roleId: 1 }, - { identifier: 'jrpopkin', type: 'IDIR', roleId: 1 }, - { identifier: 'jxdunsdo', type: 'IDIR', roleId: 1 }, - { identifier: 'mbaerg', type: 'IDIR', roleId: 1 }, - { identifier: 'nphura', type: 'IDIR', roleId: 1 }, - { identifier: 'postman', type: 'IDIR', roleId: 2 }, - { identifier: 'robmunro', type: 'IDIR', roleId: 1 }, - { identifier: 'rstens', type: 'IDIR', roleId: 1 }, - { identifier: 'tadekens', type: 'IDIR', roleId: 1 }, - { identifier: 'test1', type: 'BCEID', roleId: 1 }, - { identifier: 'test2', type: 'BCEID', roleId: 1 }, - { identifier: 'test3', type: 'IDIR', roleId: 1 }, - { identifier: 'test4', type: 'IDIR', roleId: 2 }, - { identifier: 'test5', type: 'IDIR', roleId: 2 }, - { identifier: 'test6', type: 'IDIR', roleId: 6 }, - { identifier: 'test7', type: 'IDIR', roleId: 6 }, - { identifier: 'cypress', type: 'IDIR', roleId: 1 }, - { identifier: 'keinarss', type: 'IDIR', roleId: 1 } + { identifier: 'aagahche', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'cgarrett', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'istest1', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'jrpopkin', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'jxdunsdo', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'mbaerg', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'nphura', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'postman', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 2 }, + { identifier: 'robmunro', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'rstens', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'tadekens', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'test1', type: SYSTEM_IDENTITY_SOURCE.BCEID, roleId: 1 }, + { identifier: 'test2', type: SYSTEM_IDENTITY_SOURCE.BCEID, roleId: 1 }, + { identifier: 'test3', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'test4', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 2 }, + { identifier: 'test5', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 2 }, + { identifier: 'test6', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 6 }, + { identifier: 'test7', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 6 }, + { identifier: 'cypress', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 }, + { identifier: 'keinarss', type: SYSTEM_IDENTITY_SOURCE.IDIR, roleId: 1 } ]; /** diff --git a/n8n/package-lock.json b/n8n/package-lock.json index ec7810e47c..bd85576ef0 100644 --- a/n8n/package-lock.json +++ b/n8n/package-lock.json @@ -8086,9 +8086,9 @@ } }, "url-parse": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.3.tgz", - "integrity": "sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.7.tgz", + "integrity": "sha512-HxWkieX+STA38EDk7CE9MEryFeHCKzgagxlGvsdS7WBImq9Mk+PGwiT56w82WI3aicwJA8REp42Cxo98c8FZMA==", "dev": true, "requires": { "querystringify": "^2.1.1",