Skip to content

Commit

Permalink
Publish security review update
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Dec 14, 2023
1 parent 0af3140 commit 18846ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 55 deletions.
10 changes: 10 additions & 0 deletions api/src/paths/submission/{submissionId}/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { getAPIUserDBConnection, getDBConnection } from '../../../database/db';
import { defaultErrorResponses } from '../../../openapi/schemas/http-responses';
import { SECURITY_APPLIED_STATUS } from '../../../repositories/security-repository';
import { SubmissionService } from '../../../services/submission-service';
import { getLogger } from '../../../utils/logger';

Expand Down Expand Up @@ -97,6 +98,15 @@ GET.apiDoc = {
revision_count: {
type: 'integer',
minimum: 0
},
security: {
type: 'string',
enum: [
SECURITY_APPLIED_STATUS.PENDING,
SECURITY_APPLIED_STATUS.UNSECURED,
SECURITY_APPLIED_STATUS.SECURED,
SECURITY_APPLIED_STATUS.PARTIALLY_SECURED
]
}
}
},
Expand Down
12 changes: 8 additions & 4 deletions api/src/services/submission-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,23 @@ export class SubmissionService extends DBService {
return this.submissionRepository.getReviewedSubmissionsWithSecurity();
}

/*
/**
* Retrieves submission data from the submission table.
*
* @param {number} submissionId
* @return {*} {(Promise<{
* submission: ISubmissionModel & { create_user: string };
* @return {*} {Promise<{
* submission: SubmissionWithSecurityRecord;
* features: {
* dataset: SubmissionRecordWithTypeAndSecurity[];
* sampleSites: SubmissionRecordWithTypeAndSecurity[];
* animals: SubmissionRecordWithTypeAndSecurity[];
* observations: SubmissionRecordWithTypeAndSecurity[];
* };
* }>}
* @memberof SubmissionService
*/
async getSubmissionAndFeaturesBySubmissionId(submissionId: number): Promise<{
submission: ISubmissionModel & { create_user: string };
submission: SubmissionWithSecurityRecord;
features: {
dataset: SubmissionRecordWithTypeAndSecurity[];
sampleSites: SubmissionRecordWithTypeAndSecurity[];
Expand Down
51 changes: 0 additions & 51 deletions app/src/features/submissions/components/SubmissionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,6 @@ export interface ISubmissionHeaderProps {
selectedFeatures: number[];
}

/**
* Checks if security has been applied to all features in a submission.
*
* @param {IGetSubmissionResponse} submission
* @return {*} {SECURITY_APPLIED_STATUS}
*/
export const checkSubmissionSecurity = (submission: IGetSubmissionResponse): SECURITY_APPLIED_STATUS => {
let securityCount = 0;
let featureCount = 0;

submission.features?.observations.forEach((observation: IFeature) => {
if (
observation.data?.submission_feature_security_ids &&
observation.data?.submission_feature_security_ids.length > 0
) {
securityCount += 1;
}
featureCount += 1;
});

submission.features?.animals.forEach((animal: IFeature) => {
if (animal.data?.submission_feature_security_ids && animal.data?.submission_feature_security_ids.length > 0) {
securityCount += 1;
}
featureCount += 1;
});

submission.features?.sampleSites.forEach((sampleSite: IFeature) => {
if (
sampleSite.data?.submission_feature_security_ids &&
sampleSite.data?.submission_feature_security_ids.length > 0
) {
securityCount += 1;
}
featureCount += 1;
});

if (securityCount === 0) {
return SECURITY_APPLIED_STATUS.UNSECURED;
}

if (securityCount === featureCount) {
return SECURITY_APPLIED_STATUS.SECURED;
}

return SECURITY_APPLIED_STATUS.PARTIALLY_SECURED;
};

/**
* Submission header for admin single-submission view.
*
Expand All @@ -72,15 +24,12 @@ const SubmissionHeader = (props: ISubmissionHeaderProps) => {

const api = useApi();

const submissionUUID = submissionContext.submissionDataLoader.data?.submission.uuid;
const submissionDataLoader = submissionContext.submissionDataLoader;

if (!submissionDataLoader.data) {
return <CircularProgress className="pageProgress" size={40} />;
}

const secure = checkSubmissionSecurity(submissionDataLoader.data);

const submission = submissionDataLoader.data?.submission;
const features = submissionDataLoader.data?.features;
const dataset = features.dataset[0];
Expand Down

0 comments on commit 18846ad

Please sign in to comment.