-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dataset_security_feature' into SIMSBIOHUB-379
- Loading branch information
1 parent
85a2aa4
commit eb023bd
Showing
47 changed files
with
1,453 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
api/src/paths/administrative/submission/unreviewed/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { RequestHandler } from 'express'; | ||
import { Operation } from 'express-openapi'; | ||
import { SYSTEM_ROLE } from '../../../../constants/roles'; | ||
import { getDBConnection } from '../../../../database/db'; | ||
import { defaultErrorResponses } from '../../../../openapi/schemas/http-responses'; | ||
import { authorizeRequestHandler } from '../../../../request-handlers/security/authorization'; | ||
import { SubmissionService } from '../../../../services/submission-service'; | ||
import { getLogger } from '../../../../utils/logger'; | ||
|
||
const defaultLog = getLogger('paths/administrative/submission/unreviewed'); | ||
|
||
export const GET: Operation = [ | ||
authorizeRequestHandler(() => { | ||
return { | ||
and: [ | ||
{ | ||
validSystemRoles: [SYSTEM_ROLE.SYSTEM_ADMIN, SYSTEM_ROLE.DATA_ADMINISTRATOR], | ||
discriminator: 'SystemRole' | ||
} | ||
] | ||
}; | ||
}), | ||
getUnreviewedSubmissions() | ||
]; | ||
|
||
GET.apiDoc = { | ||
description: 'Get a list of submissions that need security review (are unreviewed).', | ||
tags: ['admin'], | ||
security: [ | ||
{ | ||
Bearer: [] | ||
} | ||
], | ||
responses: { | ||
200: { | ||
description: 'List of submissions that need security review.', | ||
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 unreviewed submissions. | ||
* | ||
* @returns {RequestHandler} | ||
*/ | ||
export function getUnreviewedSubmissions(): RequestHandler { | ||
return async (req, res) => { | ||
const connection = getDBConnection(req['keycloak_token']); | ||
|
||
try { | ||
await connection.open(); | ||
|
||
await connection.commit(); | ||
|
||
const service = new SubmissionService(connection); | ||
const response = await service.getUnreviewedSubmissions(); | ||
|
||
return res.status(200).json(response); | ||
} catch (error) { | ||
defaultLog.error({ label: 'getUnreviewedSubmissions', message: 'error', error }); | ||
throw error; | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { RequestHandler } from 'express'; | ||
import { Operation } from 'express-openapi'; | ||
import { getAPIUserDBConnection, getDBConnection } from '../../../database/db'; | ||
import { defaultErrorResponses } from '../../../openapi/schemas/http-responses'; | ||
import { DatasetService } from '../../../services/dataset-service'; | ||
import { getLogger } from '../../../utils/logger'; | ||
|
||
const defaultLog = getLogger('paths/dataset/{datasetId}'); | ||
|
||
export const GET: Operation = [getDatasetInformation()]; | ||
|
||
GET.apiDoc = { | ||
description: 'retrieves dataset data from the submission table', | ||
tags: ['eml'], | ||
security: [ | ||
{ | ||
OptionalBearer: [] | ||
} | ||
], | ||
parameters: [ | ||
{ | ||
description: 'dataset uuid', | ||
in: 'path', | ||
name: 'datasetId', | ||
schema: { | ||
type: 'string', | ||
format: 'uuid' | ||
}, | ||
required: true | ||
} | ||
], | ||
responses: { | ||
200: { | ||
description: 'Dataset metadata response object.', | ||
content: { | ||
'application/json': { | ||
schema: { | ||
type: 'object' | ||
//TODO: add schema | ||
} | ||
} | ||
} | ||
}, | ||
...defaultErrorResponses | ||
} | ||
}; | ||
|
||
/** | ||
* Retrieves dataset data from the submission table. | ||
* | ||
* @returns {RequestHandler} | ||
*/ | ||
export function getDatasetInformation(): RequestHandler { | ||
return async (req, res) => { | ||
const connection = req['keycloak_token'] ? getDBConnection(req['keycloak_token']) : getAPIUserDBConnection(); | ||
|
||
const datasetId = String(req.params.datasetId); | ||
|
||
try { | ||
await connection.open(); | ||
|
||
const datasetService = new DatasetService(connection); | ||
|
||
const result = await datasetService.getDatasetByDatasetUUID(datasetId); | ||
|
||
await connection.commit(); | ||
|
||
res.status(200).json(result); | ||
} catch (error) { | ||
defaultLog.error({ label: 'getMetadataByDatasetId', message: 'error', error }); | ||
await connection.rollback(); | ||
throw error; | ||
} finally { | ||
connection.release(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.