Skip to content

Commit

Permalink
Merge branch 'dev-staging' into SIMSBIOHUB-343
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisupshall committed Oct 26, 2023
2 parents acc28b4 + 3b1400a commit 07504d5
Show file tree
Hide file tree
Showing 142 changed files with 7,569 additions and 2,441 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ db-container: ## Executes into database container.
@echo "Make: Shelling into database container"
@echo "==============================================="
@export PGPASSWORD=$(DB_ADMIN_PASS)
@

app-container: ## Executes into the app container.
@echo "==============================================="
Expand Down
12 changes: 6 additions & 6 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions api/src/models/survey-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from 'chai';
import { describe } from 'mocha';
import {
PostAgreementsData,
PostLocationData,
PostPartnershipsData,
PostPermitData,
PostProprietorData,
Expand Down Expand Up @@ -362,54 +361,6 @@ describe('PostProprietorData', () => {
});
});

describe('PostLocationData', () => {
describe('No values provided', () => {
let data: PostLocationData;

before(() => {
data = new PostLocationData(null);
});

it('sets name', () => {
expect(data.name).to.equal(null);
});

it('sets description', () => {
expect(data.description).to.equal(null);
});

it('sets geojson', () => {
expect(data.geojson).to.eql([]);
});
});

describe('All values provided with first nations id', () => {
let data: PostLocationData;

const obj = {
name: 'area name',
description: 'area description',
geojson: [{}]
};

before(() => {
data = new PostLocationData(obj);
});

it('sets name', () => {
expect(data.name).to.equal(obj.name);
});

it('sets description', () => {
expect(data.description).to.equal(obj.description);
});

it('sets geojson', () => {
expect(data.geojson).to.eql(obj.geojson);
});
});
});

describe('PostPurposeAndMethodologyData', () => {
describe('No values provided', () => {
let data: PostPurposeAndMethodologyData;
Expand Down
18 changes: 3 additions & 15 deletions api/src/models/survey-create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Feature } from 'geojson';
import { SurveyStratum } from '../repositories/site-selection-strategy-repository';
import { PostSurveyBlock } from '../repositories/survey-block-repository';
import { PostSurveyLocationData } from './survey-update';

export class PostSurveyObject {
survey_details: PostSurveyDetailsData;
Expand All @@ -9,7 +9,7 @@ export class PostSurveyObject {
funding_sources: PostFundingSourceData[];
proprietor: PostProprietorData;
purpose_and_methodology: PostPurposeAndMethodologyData;
locations: PostLocationData[];
locations: PostSurveyLocationData[];
agreements: PostAgreementsData;
participants: PostParticipationData[];
partnerships: PostPartnershipsData;
Expand All @@ -29,7 +29,7 @@ export class PostSurveyObject {
this.participants =
(obj?.participants?.length && obj.participants.map((p: any) => new PostParticipationData(p))) || [];
this.partnerships = (obj?.partnerships && new PostPartnershipsData(obj.partnerships)) || null;
this.locations = (obj?.locations && obj.locations.map((p: any) => new PostLocationData(p))) || [];
this.locations = (obj?.locations && obj.locations.map((p: any) => new PostSurveyLocationData(p))) || [];
this.site_selection = (obj?.site_selection && new PostSiteSelectionData(obj)) || null;
this.blocks = (obj?.blocks && obj.blocks.map((p: any) => p as PostSurveyBlock)) || [];
}
Expand Down Expand Up @@ -120,18 +120,6 @@ export class PostProprietorData {
}
}

export class PostLocationData {
name: string;
description: string;
geojson: Feature[];

constructor(obj?: any) {
this.name = obj?.name || null;
this.description = obj?.description || null;
this.geojson = (obj?.geojson?.length && obj.geojson) || [];
}
}

export class PostPurposeAndMethodologyData {
intended_outcome_id: number;
additional_details: string;
Expand Down
12 changes: 6 additions & 6 deletions api/src/models/survey-update.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import {
PostSurveyLocationData,
PutPartnershipsData,
PutSurveyDetailsData,
PutSurveyLocationData,
PutSurveyObject,
PutSurveyPermitData,
PutSurveyProprietorData,
Expand Down Expand Up @@ -410,18 +410,18 @@ describe('PutPurposeAndMethodologyData', () => {

describe('PutLocationData', () => {
describe('No values provided', () => {
let data: PutSurveyLocationData;
let data: PostSurveyLocationData;

before(() => {
data = new PutSurveyLocationData(null);
data = new PostSurveyLocationData(null);
});

it('sets name', () => {
expect(data.name).to.equal(null);
});

it('sets description', () => {
expect(data.description).to.equal(null);
expect(data.description).to.equal('');
});

it('sets geojson', () => {
Expand All @@ -434,7 +434,7 @@ describe('PutLocationData', () => {
});

describe('All values provided with first nations id', () => {
let data: PutSurveyLocationData;
let data: PostSurveyLocationData;

const obj = {
name: 'area name',
Expand All @@ -444,7 +444,7 @@ describe('PutLocationData', () => {
};

before(() => {
data = new PutSurveyLocationData(obj);
data = new PostSurveyLocationData(obj);
});

it('sets name', () => {
Expand Down
13 changes: 7 additions & 6 deletions api/src/models/survey-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PutSurveyObject {
funding_sources: PutFundingSourceData[];
proprietor: PutSurveyProprietorData;
purpose_and_methodology: PutSurveyPurposeAndMethodologyData;
locations: PutSurveyLocationData[];
locations: PostSurveyLocationData[];
participants: PutSurveyParticipantsData[];
partnerships: PutPartnershipsData;
site_selection: PutSiteSelectionData;
Expand All @@ -26,7 +26,7 @@ export class PutSurveyObject {
(obj?.purpose_and_methodology && new PutSurveyPurposeAndMethodologyData(obj.purpose_and_methodology)) || null;
this.participants =
(obj?.participants?.length && obj.participants.map((p: any) => new PutSurveyParticipantsData(p))) || [];
this.locations = (obj?.locations && obj.locations.map((p: any) => new PutSurveyLocationData(p))) || [];
this.locations = (obj?.locations && obj.locations.map((p: any) => new PostSurveyLocationData(p))) || [];
this.partnerships = (obj?.partnerships && new PutPartnershipsData(obj.partnerships)) || null;
this.site_selection = (obj?.site_selection && new PutSiteSelectionData(obj)) || null;
this.blocks = (obj?.blocks && obj.blocks.map((p: any) => p as PostSurveyBlock)) || [];
Expand Down Expand Up @@ -150,17 +150,18 @@ export class PutSurveyPurposeAndMethodologyData {
}
}

export class PutSurveyLocationData {
survey_location_id: number;
// This class is used for both insert and updating a survey location
export class PostSurveyLocationData {
survey_location_id: number | undefined;
name: string;
description: string;
geojson: Feature[];
revision_count: number;
revision_count: number | undefined;

constructor(obj?: any) {
this.survey_location_id = obj?.survey_location_id || null;
this.name = obj?.name || null;
this.description = obj?.description || null;
this.description = obj?.description || '';
this.geojson = (obj?.geojson?.length && obj.geojson) || [];
this.revision_count = obj?.revision_count ?? null;
}
Expand Down
16 changes: 2 additions & 14 deletions api/src/paths/funding-sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FundingSource, FundingSourceSupplementaryData } from '../../repositorie
import { SystemUser } from '../../repositories/user-repository';
import { authorizeRequestHandler } from '../../request-handlers/security/authorization';
import { FundingSourceService, IFundingSourceSearchParams } from '../../services/funding-source-service';
import { UserService } from '../../services/user-service';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/funding-sources/index');
Expand Down Expand Up @@ -121,7 +122,7 @@ export function getFundingSources(): RequestHandler {
await connection.commit();

const systemUserObject: SystemUser = req['system_user'];
if (!isAdmin(systemUserObject)) {
if (!UserService.isAdmin(systemUserObject)) {
// User is not an admin, strip sensitive fields from response
response = removeNonAdminFieldsFromFundingSourcesResponse(response);
}
Expand All @@ -137,19 +138,6 @@ export function getFundingSources(): RequestHandler {
};
}

/**
* Checks if the system user is an admin (has an admin level system role).
*
* @param {SystemUser} systemUserObject
* @return {*} {boolean} `true` if the user is an admin, `false` otherwise.
*/
function isAdmin(systemUserObject: SystemUser): boolean {
return (
systemUserObject.role_names.includes(SYSTEM_ROLE.SYSTEM_ADMIN) ||
systemUserObject.role_names.includes(SYSTEM_ROLE.DATA_ADMINISTRATOR)
);
}

/**
* Removes sensitive (admin-only) fields from the funding sources response, returning a new sanitized array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDBConnection } from '../../../../../database/db';
import { SystemUser } from '../../../../../repositories/user-repository';
import { authorizeRequestHandler } from '../../../../../request-handlers/security/authorization';
import { AttachmentService } from '../../../../../services/attachment-service';
import { UserService } from '../../../../../services/user-service';
import { getLogger } from '../../../../../utils/logger';
import { attachmentApiDocObject } from '../../../../../utils/shared-api-docs';

Expand Down Expand Up @@ -104,15 +105,12 @@ export function deleteAttachment(): RequestHandler {
const attachmentService = new AttachmentService(connection);

const systemUserObject: SystemUser = req['system_user'];
const isAdmin =
systemUserObject.role_names.includes(SYSTEM_ROLE.SYSTEM_ADMIN) ||
systemUserObject.role_names.includes(SYSTEM_ROLE.DATA_ADMINISTRATOR);

await attachmentService.handleDeleteProjectAttachment(
Number(req.params.projectId),
Number(req.params.attachmentId),
req.body.attachmentType,
isAdmin
UserService.isAdmin(systemUserObject)
);

await connection.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDBConnection } from '../../../../../../../database/db';
import { SystemUser } from '../../../../../../../repositories/user-repository';
import { authorizeRequestHandler } from '../../../../../../../request-handlers/security/authorization';
import { AttachmentService } from '../../../../../../../services/attachment-service';
import { UserService } from '../../../../../../../services/user-service';
import { getLogger } from '../../../../../../../utils/logger';
import { attachmentApiDocObject } from '../../../../../../../utils/shared-api-docs';

Expand Down Expand Up @@ -110,15 +111,12 @@ export function deleteAttachment(): RequestHandler {
const attachmentService = new AttachmentService(connection);

const systemUserObject: SystemUser = req['system_user'];
const isAdmin =
systemUserObject.role_names.includes(SYSTEM_ROLE.SYSTEM_ADMIN) ||
systemUserObject.role_names.includes(SYSTEM_ROLE.DATA_ADMINISTRATOR);

await attachmentService.handleDeleteSurveyAttachment(
Number(req.params.surveyId),
Number(req.params.attachmentId),
req.body.attachmentType,
isAdmin
UserService.isAdmin(systemUserObject)
);

await connection.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {
MESSAGE_CLASS_NAME,
SUBMISSION_MESSAGE_TYPE,
SUBMISSION_STATUS_TYPE
} from '../../../../../../../constants/status';
import * as db from '../../../../../../../database/db';
import { OccurrenceSubmissionPublish } from '../../../../../../../repositories/history-publish-repository';
} from '../../../../../../../../constants/status';
import * as db from '../../../../../../../../database/db';
import { OccurrenceSubmissionPublish } from '../../../../../../../../repositories/history-publish-repository';
import {
IGetLatestSurveyOccurrenceSubmission,
SurveyRepository
} from '../../../../../../../repositories/survey-repository';
import { HistoryPublishService } from '../../../../../../../services/history-publish-service';
import { SurveyService } from '../../../../../../../services/survey-service';
import { getMockDBConnection } from '../../../../../../../__mocks__/db';
} from '../../../../../../../../repositories/survey-repository';
import { HistoryPublishService } from '../../../../../../../../services/history-publish-service';
import { SurveyService } from '../../../../../../../../services/survey-service';
import { getMockDBConnection } from '../../../../../../../../__mocks__/db';
import * as observationSubmission from './get';

chai.use(sinonChai);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from '../../../../../../../constants/roles';
import { SUBMISSION_STATUS_TYPE } from '../../../../../../../constants/status';
import { getDBConnection } from '../../../../../../../database/db';
import { authorizeRequestHandler } from '../../../../../../../request-handlers/security/authorization';
import { HistoryPublishService } from '../../../../../../../services/history-publish-service';
import { IMessageTypeGroup, SurveyService } from '../../../../../../../services/survey-service';
import { getLogger } from '../../../../../../../utils/logger';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from '../../../../../../../../constants/roles';
import { SUBMISSION_STATUS_TYPE } from '../../../../../../../../constants/status';
import { getDBConnection } from '../../../../../../../../database/db';
import { authorizeRequestHandler } from '../../../../../../../../request-handlers/security/authorization';
import { HistoryPublishService } from '../../../../../../../../services/history-publish-service';
import { IMessageTypeGroup, SurveyService } from '../../../../../../../../services/survey-service';
import { getLogger } from '../../../../../../../../utils/logger';

const defaultLog = getLogger('/api/project/{projectId}/survey/{surveyId}/observation/submission/get');
const defaultLog = getLogger('/api/project/{projectId}/survey/{surveyId}/dwca/observations/submission/get');

export const GET: Operation = [
authorizeRequestHandler((req) => {
Expand Down
Loading

0 comments on commit 07504d5

Please sign in to comment.