Skip to content

Commit

Permalink
Merge branch 'SIMSBIOHUB-239' of github.com:bcgov/biohubbc into SIMSB…
Browse files Browse the repository at this point in the history
…IOHUB-239
  • Loading branch information
GrahamS-Quartech committed Aug 29, 2023
2 parents 4a7fd49 + ea815d1 commit b444fab
Show file tree
Hide file tree
Showing 118 changed files with 4,927 additions and 3,474 deletions.
30 changes: 30 additions & 0 deletions api/src/models/project-create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Feature } from 'geojson';
import { SYSTEM_IDENTITY_SOURCE } from '../constants/database';
import { PROJECT_ROLE } from '../constants/roles';
import { getLogger } from '../utils/logger';

const defaultLog = getLogger('models/project-create');
Expand All @@ -16,6 +18,7 @@ export class PostProjectObject {
location: PostLocationData;
iucn: PostIUCNData;
partnerships: PostPartnershipsData;
participants: PostParticipantData[];

constructor(obj?: any) {
defaultLog.debug({ label: 'PostProjectObject', message: 'params', obj });
Expand All @@ -26,6 +29,7 @@ export class PostProjectObject {
this.location = (obj?.location && new PostLocationData(obj.location)) || null;
this.iucn = (obj?.iucn && new PostIUCNData(obj.iucn)) || null;
this.partnerships = (obj?.partnerships && new PostPartnershipsData(obj.partnerships)) || null;
this.participants = obj?.participants || [];
}
}

Expand Down Expand Up @@ -169,6 +173,32 @@ export class PostPartnershipsData {
}
}

export class PostParticipantsData {
systemUserId: number;
userIdentifier: string;
identitySource: SYSTEM_IDENTITY_SOURCE;
displayName: string;
email: string;
roleId: number;

constructor(obj?: any) {
defaultLog.debug({ label: 'PostParticipantsData', message: 'params', obj });

this.systemUserId = obj?.systemUserId || null;
this.userIdentifier = obj?.userIdentifier || null;
this.identitySource = obj?.identitySource || null;
this.displayName = obj?.displayName || null;
this.email = obj?.email || null;
this.roleId = obj?.roleId || null;
}
}

export interface PostParticipantData {
project_participation_id?: number;
system_user_id: number;
project_role_names: PROJECT_ROLE[];
}

export class PostDraftData {
name: string;
data: object;
Expand Down
2 changes: 2 additions & 0 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Feature } from 'geojson';
import { z } from 'zod';
import { ProjectMetadataPublish } from '../repositories/history-publish-repository';
import { ProjectUser } from '../repositories/project-participation-repository';

export interface IProjectAdvancedFilters {
coordinator_agency?: string;
Expand All @@ -18,6 +19,7 @@ export interface IGetProject {
coordinator: GetCoordinatorData;
project: ProjectData;
objectives: GetObjectivesData;
participants: ProjectUser[];
location: GetLocationData;
iucn: GetIUCNClassificationData;
partnerships: GetPartnershipsData;
Expand Down
23 changes: 0 additions & 23 deletions api/src/models/user.ts

This file was deleted.

27 changes: 25 additions & 2 deletions api/src/openapi/schemas/project.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { PROJECT_ROLE } from '../../constants/roles';

/**
* Request Object for project create POST request
*/
export const projectCreatePostRequestObject = {
title: 'Project post request object',
type: 'object',
required: ['coordinator', 'project', 'location', 'iucn'],
required: ['coordinator', 'project', 'location', 'iucn', 'participants'],
properties: {
coordinator: {
title: 'Project coordinator',
Expand Down Expand Up @@ -104,6 +106,26 @@ export const projectCreatePostRequestObject = {
}
}
}
},
participants: {
title: 'Project participants',
type: 'array',
items: {
type: 'object',
required: ['system_user_id', 'project_role_names'],
properties: {
system_user_id: {
type: 'number'
},
project_role_names: {
type: 'array',
items: {
type: 'string',
enum: [PROJECT_ROLE.COORDINATOR, PROJECT_ROLE.COLLABORATOR, PROJECT_ROLE.OBSERVER]
}
}
}
}
}
}
};
Expand Down Expand Up @@ -146,7 +168,8 @@ const projectUpdateProperties = {
}
}
},
partnerships: { type: 'object', properties: {} }
partnerships: { type: 'object', properties: {} },
participants: { type: 'array', items: { type: 'object', properties: {} } }
};

/**
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 { User } from '../../../../models/user';
import { SystemUser } from '../../../../repositories/user-repository';
import { AdministrativeActivityService } from '../../../../services/administrative-activity-service';
import { UserService } from '../../../../services/user-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../__mocks__/db';
Expand Down Expand Up @@ -65,14 +65,17 @@ describe('approveAccessRequest', () => {

const systemUserId = 4;
const existingRoleIds = [1, 2];
const mockSystemUser: User = {
const mockSystemUser: SystemUser = {
system_user_id: systemUserId,
user_identifier: '',
user_guid: '',
identity_source: 'idir',
record_end_date: '',
role_ids: existingRoleIds,
role_names: []
role_names: [],
email: '',
display_name: '',
agency: null
};
const ensureSystemUserStub = sinon.stub(UserService.prototype, 'ensureSystemUser').resolves(mockSystemUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from '../../../../../constants/roles';
import { getDBConnection } from '../../../../../database/db';
import { User } from '../../../../../models/user';
import { SystemUser } from '../../../../../repositories/user-repository';
import { authorizeRequestHandler, getSystemUserObject } from '../../../../../request-handlers/security/authorization';
import { AttachmentService } from '../../../../../services/attachment-service';
import { getLogger } from '../../../../../utils/logger';
Expand Down Expand Up @@ -103,7 +103,7 @@ export function deleteAttachment(): RequestHandler {

const attachmentService = new AttachmentService(connection);

const systemUserObject: User = req['system_user'] || (await getSystemUserObject(connection));
const systemUserObject: SystemUser = req['system_user'] || (await getSystemUserObject(connection));
const isAdmin =
systemUserObject.role_names.includes(SYSTEM_ROLE.SYSTEM_ADMIN) ||
systemUserObject.role_names.includes(SYSTEM_ROLE.DATA_ADMINISTRATOR);
Expand Down
83 changes: 0 additions & 83 deletions api/src/paths/project/{projectId}/participants/create.test.ts

This file was deleted.

Loading

0 comments on commit b444fab

Please sign in to comment.