Skip to content

Commit

Permalink
feat: role change from sample reviewer to experiment safety reviewer (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yoganandaness authored Feb 24, 2025
2 parents 2eb1367 + a356591 commit a489606
Show file tree
Hide file tree
Showing 30 changed files with 275 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DO
$$
BEGIN
IF register_patch('0169_RenameSampleReviewerToExperimentReviewer.sql', 'Yoganandan Pandiyan', 'Rename the Roles Sample Safety Reviewer to Experiment Safety Reviewer', '2024-01-31') THEN
BEGIN
UPDATE roles SET title = 'Experiment safety reviewer', short_code = 'experiment_safety_reviewer' WHERE short_code = 'sample_safety_reviewer';

UPDATE settings SET settings_id = 'EXPERIMENT_SAFETY_REVIEW_EMAIL', description = 'Email address for the experiment safety review team.' WHERE settings_id = 'SAMPLE_SAFETY_EMAIL';

UPDATE features SET feature_id = 'EXPERIMENT_SAFETY_REVIEW', description = 'Experiment safety review functionality' WHERE feature_id = 'SAMPLE_SAFETY';
END;
END IF;
END;
$$
LANGUAGE plpgsql;
2 changes: 1 addition & 1 deletion apps/backend/src/auth/ProposalAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class ProposalAuthorization {
case Roles.USER_OFFICER:
hasAccess = true;
break;
case Roles.SAMPLE_SAFETY_REVIEWER:
case Roles.EXPERIMENT_SAFETY_REVIEWER:
hasAccess = true;
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/auth/SampleAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class SampleAuthorization {
return (
canEditProposal ||
(isMemberOfProposal && isPostProposalSubmission) ||
this.userAuth.isSampleSafetyReviewer(agent)
this.userAuth.isExperimentSafetyReviewer(agent)
);
}
}
4 changes: 2 additions & 2 deletions apps/backend/src/auth/UserAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export abstract class UserAuthorization {
return agent?.currentRole?.shortCode === Roles.USER_OFFICER;
}

isSampleSafetyReviewer(agent: UserWithRole | null) {
return agent?.currentRole?.shortCode === Roles.SAMPLE_SAFETY_REVIEWER;
isExperimentSafetyReviewer(agent: UserWithRole | null) {
return agent?.currentRole?.shortCode === Roles.EXPERIMENT_SAFETY_REVIEWER;
}

async isInternalUser(
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/config/eli/configureELIEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function enableDefaultELIFeatures() {
FeatureId.FAP_REVIEW,
FeatureId.USER_MANAGEMENT,
FeatureId.VISIT_MANAGEMENT,
FeatureId.SAMPLE_SAFETY,
FeatureId.EXPERIMENT_SAFETY_REVIEW,
FeatureId.OAUTH,
],
true
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/config/ess/configureESSEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function enableDefaultEssFeatures() {
FeatureId.FAP_REVIEW,
FeatureId.USER_MANAGEMENT,
FeatureId.VISIT_MANAGEMENT,
FeatureId.SAMPLE_SAFETY,
FeatureId.EXPERIMENT_SAFETY_REVIEW,
FeatureId.OAUTH,
FeatureId.CONFLICT_OF_INTEREST_WARNING,
],
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/datasources/mockups/UserDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export const dummySampleReviewer: UserWithRole = {
...dummyUser,
currentRole: {
id: 9,
title: 'Sample Reviewer',
shortCode: 'sample_safety_reviewer',
title: 'Experiment Safety Reviewer',
shortCode: 'experiment_safety_reviewer',
},
};

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/models/Feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export enum FeatureId {
FAP_REVIEW = 'FAP_REVIEW',
USER_MANAGEMENT = 'USER_MANAGEMENT',
VISIT_MANAGEMENT = 'VISIT_MANAGEMENT',
SAMPLE_SAFETY = 'SAMPLE_SAFETY',
EXPERIMENT_SAFETY_REVIEW = 'EXPERIMENT_SAFETY_REVIEW',
OAUTH = 'OAUTH',
STFC_IDLE_TIMER = 'STFC_IDLE_TIMER',
USER_SEARCH_FILTER = 'USER_SEARCH_FILTER',
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/models/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export enum Roles {
FAP_SECRETARY = 'fap_secretary',
FAP_REVIEWER = 'fap_reviewer',
INSTRUMENT_SCIENTIST = 'instrument_scientist',
SAMPLE_SAFETY_REVIEWER = 'sample_safety_reviewer',
EXPERIMENT_SAFETY_REVIEWER = 'experiment_safety_reviewer',
INTERNAL_REVIEWER = 'internal_reviewer',
}
2 changes: 1 addition & 1 deletion apps/backend/src/models/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ export enum SettingsId {
FAP_SECS_EDIT_TECH_REVIEWS = 'FAP_SECS_EDIT_TECH_REVIEWS',
DISPLAY_FAQ_LINK = 'DISPLAY_FAQ_LINK',
DISPLAY_PRIVACY_STATEMENT_LINK = 'DISPLAY_PRIVACY_STATEMENT_LINK',
SAMPLE_SAFETY_EMAIL = 'SAMPLE_SAFETY_EMAIL',
EXPERIMENT_SAFETY_REVIEW_EMAIL = 'EXPERIMENT_SAFETY_REVIEW_EMAIL',
}
4 changes: 2 additions & 2 deletions apps/backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export enum UserRole {
FAP_SECRETARY,
FAP_REVIEWER,
INSTRUMENT_SCIENTIST,
SAMPLE_SAFETY_REVIEWER,
EXPERIMENT_SAFETY_REVIEWER,
INTERNAL_REVIEWER,
}

Expand All @@ -77,7 +77,7 @@ export const UserRoleShortCodeMap = {
[UserRole.FAP_SECRETARY]: Roles.FAP_SECRETARY,
[UserRole.FAP_REVIEWER]: Roles.FAP_REVIEWER,
[UserRole.INSTRUMENT_SCIENTIST]: Roles.INSTRUMENT_SCIENTIST,
[UserRole.SAMPLE_SAFETY_REVIEWER]: Roles.SAMPLE_SAFETY_REVIEWER,
[UserRole.EXPERIMENT_SAFETY_REVIEWER]: Roles.EXPERIMENT_SAFETY_REVIEWER,
[UserRole.INTERNAL_REVIEWER]: Roles.INTERNAL_REVIEWER,
} as const;

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/mutations/ReviewMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default class ReviewMutations {
}

@EventBus(Event.PROPOSAL_SAMPLE_REVIEW_SUBMITTED)
@Authorized([Roles.USER_OFFICER, Roles.SAMPLE_SAFETY_REVIEWER])
@Authorized([Roles.USER_OFFICER, Roles.EXPERIMENT_SAFETY_REVIEWER])
async submitSampleReview(
agent: UserWithRole | null,
args: SubmitSampleReviewArg
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/mutations/SampleMutations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('User should be able to update title of the sample', () => {
).resolves.toHaveProperty('title', newTitle);
});

test('User should not be able to update the sample safety status and comment', async () => {
test('User should not be able to update the experiment safety status and comment', async () => {
const newComment = 'Updated comment';

return expect(
Expand All @@ -62,7 +62,7 @@ test('User should not be able to update the sample safety status and comment', a
).resolves.not.toHaveProperty('safetyStatus', SampleStatus.HIGH_RISK);
});

test('Sample safety reviewer should be able to update the sample safety status and comment', async () => {
test('Experiment safety reviewer should be able to update the experiment safety status and comment', async () => {
const newComment = 'Updated comment';

return expect(
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/queries/SampleQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class SampleQueries {
return samples;
}

@Authorized([Roles.USER_OFFICER, Roles.SAMPLE_SAFETY_REVIEWER])
@Authorized([Roles.USER_OFFICER, Roles.EXPERIMENT_SAFETY_REVIEWER])
async getSamplesByCallId(user: UserWithRole | null, callId: number) {
return await this.dataSource.getSamplesByCallId(callId);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/queries/ShipmentQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ShipmentQueries {
return shipments;
}

@Authorized([Roles.USER_OFFICER, Roles.SAMPLE_SAFETY_REVIEWER])
@Authorized([Roles.USER_OFFICER, Roles.EXPERIMENT_SAFETY_REVIEWER])
async getShipmentsByCallId(user: UserWithRole | null, callId: number) {
return await this.dataSource.getShipmentsByCallId(callId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export enum EmailStatusActionRecipients {
FAP_CHAIR_AND_SECRETARY = 'FAP_CHAIR_AND_SECRETARY',
USER_OFFICE = 'USER_OFFICE',
TECHNIQUE_SCIENTISTS = 'TECHNIQUE_SCIENTISTS',
SAMPLE_SAFETY = 'SAMPLE_SAFETY',
EXPERIMENT_SAFETY_REVIEWERS = 'EXPERIMENT_SAFETY_REVIEWERS',
OTHER = 'OTHER',
}

Expand Down Expand Up @@ -36,8 +36,8 @@ export const EmailStatusActionRecipientsWithDescription = new Map<
'The Technique Scentists email address',
],
[
EmailStatusActionRecipients.SAMPLE_SAFETY,
'The Sample Safety email address',
EmailStatusActionRecipients.EXPERIMENT_SAFETY_REVIEWERS,
'The Experiment Safety email address',
],
[
EmailStatusActionRecipients.OTHER,
Expand Down
34 changes: 19 additions & 15 deletions apps/backend/src/statusActionEngine/emailActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,50 +309,54 @@ export const emailStatusActionRecipient = async (
break;
}

case EmailStatusActionRecipients.SAMPLE_SAFETY: {
case EmailStatusActionRecipients.EXPERIMENT_SAFETY_REVIEWERS: {
const adminDataSource = container.resolve<AdminDataSource>(
Tokens.AdminDataSource
);

const sampleSafetyEmail = (
await adminDataSource.getSetting(SettingsId.SAMPLE_SAFETY_EMAIL)
const experimentSafetyEmail = (
await adminDataSource.getSetting(
SettingsId.EXPERIMENT_SAFETY_REVIEW_EMAIL
)
)?.settingsValue;

if (!sampleSafetyEmail) {
if (!experimentSafetyEmail) {
logger.logError(
'Could not send email(s) to the Sample Safety team as the setting (SAMPLE_SAFETY_EMAIL) is not set.',
'Could not send email(s) to the Experiment Safety team as the setting (EXPERIMENT_SAFETY_REVIEW_EMAIL) is not set.',
{ proposalEmailsSkipped: proposals }
);

break;
}

let sampleSafetyRecipients: EmailReadyType[];
let experimentSafetyRecipients: EmailReadyType[];

if (recipientWithTemplate.combineEmails) {
sampleSafetyRecipients = [
experimentSafetyRecipients = [
{
id: recipientWithTemplate.recipient.name,
email: sampleSafetyEmail,
email: experimentSafetyEmail,
proposals: proposals,
template: recipientWithTemplate.emailTemplate.id,
},
];
} else {
sampleSafetyRecipients = await getOtherAndFormatOutputForEmailSending(
proposals,
recipientWithTemplate,
sampleSafetyEmail
);
experimentSafetyRecipients =
await getOtherAndFormatOutputForEmailSending(
proposals,
recipientWithTemplate,
experimentSafetyEmail
);
}

await sendMail(
sampleSafetyRecipients,
experimentSafetyRecipients,
statusActionLogger({
connectionId: proposalStatusAction.connectionId,
actionId: proposalStatusAction.actionId,
statusActionsLogId,
emailStatusActionRecipient: EmailStatusActionRecipients.SAMPLE_SAFETY,
emailStatusActionRecipient:
EmailStatusActionRecipients.EXPERIMENT_SAFETY_REVIEWERS,
proposalPks,
}),
successfulMessage,
Expand Down
Loading

0 comments on commit a489606

Please sign in to comment.