Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMSBIOHUB-144-2: Project Role updates #1065

Merged
merged 44 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0f453db
wip
al-rosenthal Jul 28, 2023
6fdb9a2
Merge branch 'dev' into SIMSBIOHUB-144
al-rosenthal Jul 28, 2023
2915397
adding new tables
al-rosenthal Jul 28, 2023
d15c39c
updated comments
al-rosenthal Jul 31, 2023
4b39135
clean
al-rosenthal Jul 31, 2023
c68f922
fixed migration
al-rosenthal Jul 31, 2023
7abba68
basic migration completed
al-rosenthal Jul 31, 2023
42c1d94
turned back time
al-rosenthal Jul 31, 2023
6fd28d2
Merge branch 'dev' into SIMSBIOHUB-144
al-rosenthal Jul 31, 2023
52b739c
clean up
al-rosenthal Jul 31, 2023
6192711
renamed project role permission table
al-rosenthal Jul 31, 2023
f1c835d
trying new things
al-rosenthal Jul 31, 2023
60e96c7
added updates back
al-rosenthal Jul 31, 2023
311777b
added linking
al-rosenthal Jul 31, 2023
5263d7a
added comments
al-rosenthal Jul 31, 2023
0d062c0
clean up
al-rosenthal Aug 1, 2023
8cdeb49
updated comments
al-rosenthal Aug 1, 2023
31b4477
ignore-skip
al-rosenthal Aug 1, 2023
40fc1a9
wip
al-rosenthal Aug 1, 2023
ba74568
wip
al-rosenthal Aug 1, 2023
f1a683d
updated get user sql and authorization code
al-rosenthal Aug 1, 2023
ef19d52
updating endpoints with new project permissions
al-rosenthal Aug 1, 2023
e3f9133
updated role guard in app
al-rosenthal Aug 1, 2023
c080210
updated role guards to use permissions instead of roles
al-rosenthal Aug 1, 2023
20c3cea
fixed compile errors
al-rosenthal Aug 1, 2023
f5cca14
more clean up
al-rosenthal Aug 1, 2023
a7fac12
got basics working
al-rosenthal Aug 1, 2023
918f0ee
updated user objects and api paths
al-rosenthal Aug 1, 2023
480f445
fixing tests
al-rosenthal Aug 2, 2023
0f35cc0
fixing more compile errors
al-rosenthal Aug 2, 2023
087541a
fixed more tests
al-rosenthal Aug 2, 2023
5f70a4b
Merge branch 'dev' into SIMSBIOHUB-144-2
al-rosenthal Aug 2, 2023
761336c
squashed smell and fixed user list
al-rosenthal Aug 2, 2023
b38cc13
ignore-skip
al-rosenthal Aug 2, 2023
a9b1a58
text changes removing/ replacing project lead
al-rosenthal Aug 3, 2023
cf60f1d
fixed comment spacing
al-rosenthal Aug 3, 2023
b701432
code smell fix
al-rosenthal Aug 3, 2023
cd1fdc1
setup zod schemas properly
al-rosenthal Aug 3, 2023
85b90d6
added new zod schema
al-rosenthal Aug 3, 2023
29fb3f6
fixed a bunch of tests
al-rosenthal Aug 3, 2023
fbd709c
fixed small bugs
al-rosenthal Aug 3, 2023
d8b566c
clean
al-rosenthal Aug 3, 2023
ca7f689
fixed user guid issue
al-rosenthal Aug 4, 2023
68aadfb
Fix project permission field name.
NickPhura Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions api/src/constants/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* System level roles.
*
* @export
* @enum {number}
* @enum {string}
*/
export enum SYSTEM_ROLE {
SYSTEM_ADMIN = 'System Administrator',
Expand All @@ -14,10 +14,22 @@ export enum SYSTEM_ROLE {
* Project level roles.
*
* @export
* @enum {number}
* @enum {string}
*/
export enum PROJECT_ROLE {
PROJECT_LEAD = 'Project Lead',
PROJECT_EDITOR = 'Editor',
PROJECT_VIEWER = 'Viewer'
COORDINATOR = 'Coordinator',
COLLABORATOR = 'Collaborator',
OBSERVER = 'Observer'
}

/**
* Role permissions.
*
* @export
* @enum {string}
*/
export enum PROJECT_PERMISSION {
COORDINATOR = 'Coordinator',
COLLABORATOR = 'Collaborator',
OBSERVER = 'Observer'
}
9 changes: 9 additions & 0 deletions api/src/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ pg.types.setTypeParser(pg.types.builtins.DATE, (stringValue: string) => {
return stringValue; // 1082 for `DATE` type
});

// Adding a TIMESTAMP type parser to keep all dates used in the system consistent
pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (stringValue: string) => {
return stringValue; // 1082 for `TIMESTAMP` type
});
// Adding a TIMESTAMPTZ type parser to keep all dates used in the system consistent
pg.types.setTypeParser(pg.types.builtins.TIMESTAMPTZ, (stringValue: string) => {
return stringValue; // 1082 for `DATE` type
});

// singleton pg pool instance used by the api
let DBPool: pg.Pool | undefined;

Expand Down
20 changes: 8 additions & 12 deletions api/src/models/project-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('ProjectData', () => {
project_name: '',
project_programs: [],
project_types: [],
start_date: new Date('2005-01-01'),
end_date: new Date('2006-01-01'),
start_date: '2005-01-01',
end_date: '2006-01-01',
comments: '',
revision_count: 1
};
Expand All @@ -47,11 +47,11 @@ describe('ProjectData', () => {
});

it('sets start_date', () => {
expect(data.start_date).to.eql(new Date('2005-01-01'));
expect(data.start_date).to.eql('2005-01-01');
});

it('sets end_date', () => {
expect(data.end_date).to.eql(new Date('2006-01-01'));
expect(data.end_date).to.eql('2006-01-01');
});
});

Expand All @@ -74,8 +74,8 @@ describe('ProjectData', () => {
project_name: 'project name',
project_programs: [1],
project_types: [1, 2],
start_date: new Date('2020-04-20T07:00:00.000Z'),
end_date: new Date('2020-05-20T07:00:00.000Z'),
start_date: '2020-04-20T07:00:00.000Z',
end_date: '2020-05-20T07:00:00.000Z',
comments: '',
revision_count: 1
};
Expand All @@ -98,16 +98,12 @@ describe('ProjectData', () => {
});

it('sets start_date', () => {
expect(data.start_date).to.eql(new Date('2020-04-20T07:00:00.000Z'));
expect(data.start_date).to.eql('2020-04-20T07:00:00.000Z');
});

it('sets end_date', () => {
expect(data.end_date).to.eql(new Date('2020-05-20T07:00:00.000Z'));
expect(data.end_date).to.eql('2020-05-20T07:00:00.000Z');
});

// it('sets completion_status', () => {
// expect(data.completion_status).to.equal(COMPLETION_STATUS.COMPLETED);
// });
});
});

Expand Down
18 changes: 16 additions & 2 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,28 @@ export const ProjectData = z.object({
project_name: z.string(),
project_programs: z.array(z.number()),
project_types: z.array(z.number()),
start_date: z.date(),
end_date: z.date().nullable(),
start_date: z.string(),
end_date: z.string().nullable(),
comments: z.string().nullable(),
revision_count: z.number()
});

export type ProjectData = z.infer<typeof ProjectData>;

export const ProjectListData = z.object({
project_id: z.number(),
uuid: z.string(),
project_name: z.string(),
coordinator_agency: z.string(),
project_programs: z.array(z.number()).default([]),
project_types: z.array(z.number()).default([]),
regions: z.array(z.string()).default([]),
start_date: z.string(),
end_date: z.string().nullable().optional()
});

export type ProjectListData = z.infer<typeof ProjectListData>;

/**
* Pre-processes GET /projects/{id} objectives data
*
Expand Down
82 changes: 0 additions & 82 deletions api/src/models/user.test.ts

This file was deleted.

50 changes: 20 additions & 30 deletions api/src/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
export class UserObject {
id: number;
user_identifier: string;
user_guid: string | null;
identity_source: string;
record_end_date: string;
role_ids: number[];
role_names: string[];
import { z } from 'zod';

constructor(obj?: any) {
this.id = obj?.system_user_id || null;
this.user_identifier = obj?.user_identifier || null;
this.user_guid = obj?.user_guid || null;
this.identity_source = obj?.identity_source || null;
this.record_end_date = obj?.record_end_date || null;
this.role_ids = (obj?.role_ids?.length && obj.role_ids) || [];
this.role_names = (obj?.role_names?.length && obj.role_names) || [];
}
}
export const User = z.object({
system_user_id: z.number(),
user_identifier: z.string(),
user_guid: z.string().nullable(),
identity_source: z.string(),
record_end_date: z.string().nullable(),
role_ids: z.array(z.number()).default([]),
role_names: z.array(z.string()).default([])
});

export class ProjectUserObject {
project_id: number;
system_user_id: number;
project_role_ids: number[];
project_role_names: string[];
export type User = z.infer<typeof User>;

constructor(obj?: any) {
this.project_id = obj?.project_id || null;
this.system_user_id = obj?.system_user_id || null;
this.project_role_ids = (obj?.project_role_ids?.length && obj.project_role_ids) || [];
this.project_role_names = (obj?.project_role_names?.length && obj.project_role_names) || [];
}
}
export const ProjectUser = z.object({
project_id: z.number(),
system_user_id: z.number(),
project_role_ids: z.array(z.number()),
project_role_names: z.array(z.string()),
project_role_permissions: z.array(z.string())
});

export type ProjectUser = z.infer<typeof ProjectUser>;
2 changes: 1 addition & 1 deletion api/src/paths/administrative-activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('createAdministrativeActivity', () => {
const dbConnectionObj = getMockDBConnection({ systemUserId: () => systemUserId, commit: sinon.stub() });
sinon.stub(db, 'getAPIUserDBConnection').returns(dbConnectionObj);

const mockResponse: ICreateAdministrativeActivity = { id: 2, date: new Date() };
const mockResponse: ICreateAdministrativeActivity = { id: 2, date: '2023-01-01' };

sinon.stub(AdministrativeActivityService.prototype, 'createPendingAccessRequest').resolves(mockResponse);
sinon.stub(AdministrativeActivityService.prototype, 'sendAccessRequestNotificationEmailToAdmin').resolves();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { ADMINISTRATIVE_ACTIVITY_STATUS_TYPE } from '../../../../constants/administrative-activity';
import * as db from '../../../../database/db';
import { UserObject } from '../../../../models/user';
import { User } from '../../../../models/user';
import { AdministrativeActivityService } from '../../../../services/administrative-activity-service';
import { UserService } from '../../../../services/user-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../__mocks__/db';
Expand Down Expand Up @@ -65,10 +65,10 @@ describe('approveAccessRequest', () => {

const systemUserId = 4;
const existingRoleIds = [1, 2];
const mockSystemUser: UserObject = {
id: systemUserId,
const mockSystemUser: User = {
system_user_id: systemUserId,
user_identifier: '',
user_guid: 'aaaa',
user_guid: '',
identity_source: 'idir',
record_end_date: '',
role_ids: existingRoleIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function approveAccessRequest(): RequestHandler {

if (rolesIdsToAdd?.length) {
// Add any missing roles (if any)
await userService.addUserSystemRoles(systemUserObject.id, rolesIdsToAdd);
await userService.addUserSystemRoles(systemUserObject.system_user_id, rolesIdsToAdd);
}

// Update the access request record status
Expand Down
4 changes: 2 additions & 2 deletions api/src/paths/draft/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('paths/draft/create', () => {
webform_draft_id: 1,
name: 'draft object',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
});
const requestHandler = create.createDraft();
Expand All @@ -71,7 +71,7 @@ describe('paths/draft/create', () => {
webform_draft_id: 1,
name: 'draft object',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
});
});
Expand Down
12 changes: 6 additions & 6 deletions api/src/paths/draft/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ describe('paths/draft/list', () => {
webform_draft_id: 1,
name: 'draft object 1',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
},
{
webform_draft_id: 2,
name: 'draft object 2',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
update_date: ('2022-10-11' as unknown) as Date
create_date: '2022-10-10',
update_date: '2022-10-11'
}
]);

Expand All @@ -85,15 +85,15 @@ describe('paths/draft/list', () => {
webform_draft_id: 1,
name: 'draft object 1',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
},
{
webform_draft_id: 2,
name: 'draft object 2',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
update_date: ('2022-10-11' as unknown) as Date
create_date: '2022-10-10',
update_date: '2022-10-11'
}
]);
});
Expand Down
4 changes: 2 additions & 2 deletions api/src/paths/draft/{draftId}/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('paths/draft/{draftId}/get', () => {
webform_draft_id: 1,
name: 'draft object',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
});

Expand All @@ -75,7 +75,7 @@ describe('paths/draft/{draftId}/get', () => {
webform_draft_id: 1,
name: 'draft object',
data: {},
create_date: ('2022-10-10' as unknown) as Date,
create_date: '2022-10-10',
update_date: null
});
});
Expand Down
Loading