Skip to content

Commit

Permalink
Merge branch 'dataset_security_feature' into SIMSBIOHUB-397
Browse files Browse the repository at this point in the history
  • Loading branch information
al-rosenthal committed Dec 11, 2023
2 parents f08a81b + 6186468 commit 9961059
Show file tree
Hide file tree
Showing 25 changed files with 959 additions and 290 deletions.
22 changes: 22 additions & 0 deletions api/src/openapi/root-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ export const rootAPIDoc = {
}
},
additionalProperties: false
},
feature: {
type: 'object',
required: ['submission_feature_id', 'submission_id', 'feature_type', 'data', 'parent_submission_feature_id'],
properties: {
submission_feature_id: {
type: 'number'
},
submission_id: {
type: 'number'
},
feature_type: {
type: 'string'
},
data: {
type: 'object'
},
parent_submission_feature_id: {
type: 'number',
nullable: true
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { getUnreviewedSubmissions } from '.';
import { getUnreviewedSubmissionsForAdmins } from '.';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import { SubmissionService } from '../../../../services/submission-service';
Expand All @@ -26,7 +26,7 @@ describe('list', () => {

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

const requestHandler = getUnreviewedSubmissions();
const requestHandler = getUnreviewedSubmissionsForAdmins();

try {
await requestHandler(mockReq, mockRes, mockNext);
Expand All @@ -48,10 +48,10 @@ describe('list', () => {
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

const getUnreviewedSubmissionsStub = sinon
.stub(SubmissionService.prototype, 'getUnreviewedSubmissions')
.stub(SubmissionService.prototype, 'getUnreviewedSubmissionsForAdmins')
.resolves([]);

const requestHandler = getUnreviewedSubmissions();
const requestHandler = getUnreviewedSubmissionsForAdmins();

await requestHandler(mockReq, mockRes, mockNext);

Expand Down
77 changes: 0 additions & 77 deletions api/src/paths/dataset/{datasetId}/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions api/src/paths/dwc/submission/{datasetId}/artifacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/http-error';
import { Artifact } from '../../../../repositories/artifact-repository';
import { SECURITY_APPLIED_STATUS } from '../../../../repositories/security-repository';
import { ArtifactService } from '../../../../services/artifact-service';
import { SecurityService } from '../../../../services/security-service';
Expand Down Expand Up @@ -219,7 +218,7 @@ describe('getArtifactsByDatasetId', () => {
const artifactServiceStub = sinon.stub(ArtifactService.prototype, 'getArtifactsByDatasetId').resolves([
{ artifact_id: 1, security_review_timestamp: new Date('1970-01-01T00:00:00.000Z') },
{ artifact_id: 2, security_review_timestamp: new Date('1970-01-01T00:00:00.000Z') }
] as Artifact[]);
] as any[]);

const isSystemUserAdminStub = sinon.stub(UserService.prototype, 'isSystemUserAdmin').resolves(true);

Expand Down
105 changes: 105 additions & 0 deletions api/src/paths/submission/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { getAPIUserDBConnection } from '../../database/db';
import { defaultErrorResponses } from '../../openapi/schemas/http-responses';
import { SubmissionService } from '../../services/submission-service';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/submission');

export const GET: Operation = [getReviewedSubmissionsWithSecurity()];

GET.apiDoc = {
description: 'Get a list of reviewed submissions',
tags: ['submisssion', 'reviewed'],
security: [],
responses: {
200: {
description: 'List of reviewed submissions',
content: {
'application/json': {
schema: {
type: 'array',
items: {
type: 'object',
properties: {
submission_id: {
type: 'integer',
minimum: 1
},
uuid: {
type: 'string',
format: 'uuid'
},
security_review_timestamp: {
type: 'string',
nullable: true
},
source_system: {
type: 'string'
},
name: {
type: 'string',
maxLength: 200
},
description: {
type: 'string',
maxLength: 3000
},
create_date: {
type: 'string'
},
create_user: {
type: 'integer',
minimum: 1
},
update_date: {
type: 'string',
nullable: true
},
update_user: {
type: 'integer',
minimum: 1,
nullable: true
},
revision_count: {
type: 'integer',
minimum: 0
}
}
}
}
}
}
},
...defaultErrorResponses
}
};

/**
* Get all reviewed submissions (with security status).
*
* @returns {RequestHandler}
*/
export function getReviewedSubmissionsWithSecurity(): RequestHandler {
return async (_req, res) => {
const connection = getAPIUserDBConnection();

try {
await connection.open();

const service = new SubmissionService(connection);
const response = await service.getReviewedSubmissionsWithSecurity();

await connection.commit();

return res.status(200).json(response);
} catch (error) {
await connection.rollback();
defaultLog.error({ label: 'getReviewedSubmissionsWithSecurity', message: 'error', error });
throw error;
} finally {
connection.release();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { ValidationService } from '../../services/validation-service';
import { getKeycloakSource } from '../../utils/keycloak-utils';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/dataset/intake');
const defaultLog = getLogger('paths/submission/intake');

/*
TODO: UPDATED PATH TO SUBMISSION/INTAKE NEED TO UPDATE SIMS TO USE THIS PATH
*/

export const POST: Operation = [
authorizeRequestHandler(() => {
Expand All @@ -23,12 +27,12 @@ export const POST: Operation = [
]
};
}),
datasetIntake()
submissionIntake()
];

POST.apiDoc = {
description: 'Submit dataset to BioHub',
tags: ['dataset'],
description: 'Submit submission to BioHub',
tags: ['submission'],
security: [
{
Bearer: []
Expand All @@ -48,7 +52,7 @@ POST.apiDoc = {
},
type: {
type: 'string',
enum: ['dataset']
enum: ['submission']
},
properties: {
title: 'Dataset properties',
Expand Down Expand Up @@ -89,7 +93,7 @@ POST.apiDoc = {
}
};

export function datasetIntake(): RequestHandler {
export function submissionIntake(): RequestHandler {
return async (req, res) => {
const sourceSystem = getKeycloakSource(req['keycloak_token']);

Expand All @@ -99,7 +103,7 @@ export function datasetIntake(): RequestHandler {
]);
}

const dataset = {
const submission = {
...req.body,
properties: { ...req.body.properties, additionalInformation: req.body.properties.additionalInformation }
};
Expand All @@ -113,21 +117,21 @@ export function datasetIntake(): RequestHandler {
const submissionService = new SubmissionService(connection);
const validationService = new ValidationService(connection);

// validate the dataset submission
if (!(await validationService.validateDatasetSubmission(dataset))) {
throw new HTTP400('Invalid dataset submission');
// validate the submission submission
if (!(await validationService.validateDatasetSubmission(submission))) {
throw new HTTP400('Invalid submission submission');
}

// insert the submission record
const response = await submissionService.insertSubmissionRecordWithPotentialConflict(id);

// insert each submission feature record
await submissionService.insertSubmissionFeatureRecords(response.submission_id, dataset.features);
await submissionService.insertSubmissionFeatureRecords(response.submission_id, submission.features);

await connection.commit();
res.status(200).json(response);
} catch (error) {
defaultLog.error({ label: 'datasetIntake', message: 'error', error });
defaultLog.error({ label: 'submissionIntake', message: 'error', error });
await connection.rollback();
throw error;
} finally {
Expand Down
Loading

0 comments on commit 9961059

Please sign in to comment.