Skip to content

Commit

Permalink
Merge branch 'develop' into 913-add-search-by-name-and-email
Browse files Browse the repository at this point in the history
  • Loading branch information
ellen-wright authored Oct 15, 2024
2 parents e8944bb + 86c1697 commit 7b1e284
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
DO
$$
BEGIN
IF register_patch('0163_ExcludeExpiredProposalsFromReviewProposalView.sql', 'Thomas Cottee Meldrum', 'Exclude expired proposals from view', '2024-09-05') THEN

CREATE OR REPLACE VIEW review_data AS
SELECT proposal.proposal_pk,
proposal.proposal_id,
proposal.title,
proposal.instrument_name,
proposal.availability_time,
proposal.time_allocation,
proposal.fap_id,
proposal.rank_order,
proposal.call_id,
proposal.proposer_id,
proposal.instrument_id,
proposal.fap_time_allocation,
proposal.questionary_id,
grade.avg AS average_grade,
proposal.comment
from (
Select
fp.proposal_pk,
p.proposal_id,
p.title,
i.name as instrument_name,
chi.availability_time,
tr.time_allocation,
f.fap_id,
fmd.rank_order,
c.call_id,
p.proposer_id,
i.instrument_id,
fp.fap_time_allocation,
p.questionary_id,
tr.comment
from fap_proposals as fp
join faps as f on f.fap_id = fp.fap_id
join call c on c.call_id = fp.call_id
join proposals p on p.proposal_pk = fp.proposal_pk
join technical_review tr on tr.proposal_pk = p.proposal_pk and tr.instrument_id = fp.instrument_id
left join fap_meeting_decisions as fmd on fmd.proposal_pk = p.proposal_pk
join call_has_instruments as chi on chi.instrument_id = fp.instrument_id and chi.call_id = c.call_id
join instruments as i on i.instrument_id = chi.instrument_id
where p.status_id <> 9 and p.status_id <> 1 /* EXPIRED OR DRAFT*/
) as proposal
left join (
Select fr.proposal_pk, AVG(fr.grade) from
fap_proposals as fp
join fap_reviews as fr on fr.proposal_pk = fp.proposal_pk
group by fr.proposal_pk
) as grade on grade.proposal_pk = proposal.proposal_pk;
END IF;
END;
$$
LANGUAGE plpgsql;
16 changes: 16 additions & 0 deletions apps/backend/db_patches/0164_AllowSecsEditTechReview.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DO
$$
BEGIN
IF register_patch('AllowSecsEditTechReview.sql', 'TCMeldrum', 'Allow Fap Secretaries to Edit Tech Reviews', '2024-10-07') THEN
BEGIN

INSERT INTO settings(settings_id, description)
VALUES ('FAP_SECS_EDIT_TECH_REVIEWS',
'Allows Fap secretaries to edit technical reviews'
);

END;
END IF;
END;
$$
LANGUAGE plpgsql;
5 changes: 4 additions & 1 deletion apps/backend/src/auth/TechnicalReviewAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ export class TechnicalReviewAuthorization {
: technicalReviewOrProposalPk.proposalPk;

const isUserOfficer = this.userAuth.isUserOfficer(agent);
if (isUserOfficer) {
const isFapChairOrSecOfFap =
await this.proposalAuth.isChairOrSecretaryOfProposal(agent, proposalPk);

if (isUserOfficer || isFapChairOrSecOfFap) {
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/config/stfc/configureSTFCEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ async function enableDefaultStfcFeatures() {
settingsId: SettingsId.TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS,
settingsValue: 'FEASIBILITY',
});
await db.updateSettings({
settingsId: SettingsId.FAP_SECS_EDIT_TECH_REVIEWS,
settingsValue: 'true',
});
}

async function setSTFCRoleNames() {
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/models/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export enum SettingsId {
USER_OFFICE_EMAIL = 'USER_OFFICE_EMAIL',
SMTP_BCC_EMAIL = 'SMTP_BCC_EMAIL',
TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS = 'TECH_REVIEW_OPTIONAL_WORKFLOW_STATUS',
FAP_SECS_EDIT_TECH_REVIEWS = 'FAP_SECS_EDIT_TECH_REVIEWS',
}
14 changes: 12 additions & 2 deletions apps/backend/src/mutations/ReviewMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ export default class ReviewMutations {
}

@EventBus(Event.PROPOSAL_FEASIBILITY_REVIEW_SUBMITTED)
@Authorized([Roles.USER_OFFICER, Roles.INSTRUMENT_SCIENTIST])
@Authorized([
Roles.USER_OFFICER,
Roles.INSTRUMENT_SCIENTIST,
Roles.FAP_CHAIR,
Roles.FAP_SECRETARY,
])
async submitTechnicalReview(
agent: UserWithRole | null,
args: SubmitTechnicalReviewInput
Expand Down Expand Up @@ -204,7 +209,12 @@ export default class ReviewMutations {
'comment',
'publicComment',
])
@Authorized([Roles.USER_OFFICER, Roles.INSTRUMENT_SCIENTIST])
@Authorized([
Roles.USER_OFFICER,
Roles.INSTRUMENT_SCIENTIST,
Roles.FAP_CHAIR,
Roles.FAP_SECRETARY,
])
async setTechnicalReview(
agent: UserWithRole | null,
args: AddTechnicalReviewInput | SubmitTechnicalReviewInput
Expand Down
94 changes: 94 additions & 0 deletions apps/e2e/cypress/e2e/FAPs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,63 @@ context('Fap reviews tests', () => {

cy.finishedLoading();
});

it('Fap Secretary should be able to edit only comments of technical reviews', function () {
if (
settings
.getEnabledSettings()
.get(SettingsId.FAP_SECS_EDIT_TECH_REVIEWS) !== 'true'
) {
this.skip();
}

const internalComment = faker.word.words(2);
const publicComment = faker.word.words(2);

cy.addProposalTechnicalReview({
proposalPk: firstCreatedProposalPk,
status: TechnicalReviewStatus.FEASIBLE,
timeAllocation: firstProposalTimeAllocation,
submitted: true,
reviewerId: 6,
instrumentId: newlyCreatedInstrumentId,
});

cy.assignFapReviewersToProposals({
assignments: {
memberId: fapMembers.reviewer.id,
proposalPk: firstCreatedProposalPk,
},
fapId: createdFapId,
});

cy.visit(`/FapPage/${createdFapId}?tab=3`);

cy.finishedLoading();

cy.get('[data-cy="view-proposal"]').click();

cy.contains('Technical reviews').click();

// The children are the components that are disabled
cy.get('[data-cy="technical-review-status"]')
.children()
.should('be.disabled');
cy.get('[data-cy="timeAllocation"]')
.children()
.children()
.should('be.disabled');

cy.setTinyMceContent('comment', internalComment);
cy.setTinyMceContent('publicComment', publicComment);

cy.get('[data-cy="save-technical-review"]').click();

cy.notification({
variant: 'success',
text: 'Technical review submitted successfully',
});
});
});

describe('Fap Reviewer role', () => {
Expand Down Expand Up @@ -3609,6 +3666,7 @@ context('Automatic Fap assignment to Proposal', () => {

context('Fap meeting exports test', () => {
let createdInstrumentId: number;
let proposalPK: number;

beforeEach(function () {
cy.resetDB();
Expand Down Expand Up @@ -3705,6 +3763,7 @@ context('Fap meeting exports test', () => {
const createdProposal = result.createProposal;

cy.wrap(createdProposal.proposalId).as('proposal2Id');
proposalPK = createdProposal.primaryKey;

if (createdProposal) {
cy.updateProposal({
Expand Down Expand Up @@ -3947,4 +4006,39 @@ context('Fap meeting exports test', () => {
);
});
});

it('Expired proposals should not appear in exports', function () {
cy.getAndStoreFeaturesEnabled().then(function () {
if (!featureFlags.getEnabledFeatures().get(FeatureId.USER_MANAGEMENT)) {
this.skip();
}
});

cy.changeProposalsStatus({
proposalPks: [proposalPK],
statusId: 9,
});

cy.login('officer');
cy.visit('/FapPage/2?tab=4&call=1');

cy.get('button[aria-label="Export in Excel"]').click();

const downloadsFolder = Cypress.config('downloadsFolder');
const fileName = `Fap-${fap1.code}-${updatedCall.shortCode}.xlsx`;

cy.readFile(`${downloadsFolder}/${fileName}`)
.should('exist')
.then(() => {
cy.task('convertXlsxToJson', `${downloadsFolder}/${fileName}`).then(
(actualExport) => {
cy.fixture('exampleFapExportExpired.json').then(
(expectedExport) => {
expect(expectedExport).to.deep.equal(actualExport);
}
);
}
);
});
});
});
2 changes: 1 addition & 1 deletion apps/e2e/cypress/e2e/generalFaps.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ context('General facility access panel tests', () => {
});
});

describe.only('Fap document store tests', () => {
describe('Fap document store tests', () => {
it('Officer should be able to upload documents to the document store', () => {
const fileName1 = 'pdf_5_pages.pdf';
const fileName2 = 'pdf_3_pages.pdf';
Expand Down
14 changes: 14 additions & 0 deletions apps/e2e/cypress/fixtures/exampleFapExportExpired.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"Proposal Reference Number": "567122",
"Proposal Title": "lumen proofread hertz",
"Principal Investigator": "Carl Carlsson",
"Instrument": "Central lavender",
"Instrument available time": 20,
"Technical review allocated time": 25,
"Fap allocated time": 25,
"Average Score": 3,
"Current rank": "<missing>",
"Is in availability zone": "no"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const memberRole = (member: FapAssignedMember) => `${member.role?.title}`;
const columns = [
{ title: 'Name', field: 'firstname' },
{ title: 'Surname', field: 'lastname' },
{ title: 'Proposal Count', field: 'proposalsCountByCall' },
{
title: 'Role',
render: (rowData: FapAssignedMember) => memberRole(rowData),
Expand Down Expand Up @@ -52,12 +53,13 @@ const AssignFapMemberToProposalModal = ({
? FapMembersData.map((fapMember) => ({
...fapMember.user,
role: fapMember.role ?? null,
proposalsCountByCall: fapMember.proposalsCountByCall,
}))
: [];

return (
<Dialog
maxWidth="sm"
maxWidth="md"
fullWidth
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import RankInputModal from './RankInputModal';

type FapAssignedReviewersTableProps = {
fapProposal: FapProposalType;
fapChairAndSecs: number[];
removeAssignedReviewer: (
assignedReviewer: FapProposalAssignmentType,
proposalPk: number
Expand Down Expand Up @@ -60,6 +61,7 @@ const assignmentColumns = [

const FapAssignedReviewersTable = ({
fapProposal,
fapChairAndSecs,
removeAssignedReviewer,
updateView,
}: FapAssignedReviewersTableProps) => {
Expand Down Expand Up @@ -171,6 +173,7 @@ const FapAssignedReviewersTable = ({
proposalPk={fapProposal.proposalPk}
reviewId={reviewerModal ? +reviewerModal : undefined}
fapId={fapProposal.fapId}
fapSecAndChair={fapChairAndSecs}
tabNames={reviewProposalTabNames}
/>
</ProposalReviewModal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@ const FapProposalsAndAssignmentsTable = ({
return (
<FapAssignedReviewersTable
fapProposal={rowData}
fapChairAndSecs={data.fapChairs
.map((user) => user.id)
.concat(data.fapSecretaries.map((user) => user.id))}
removeAssignedReviewer={removeAssignedReviewer}
updateView={updateFapProposalAssignmentsView}
/>
Expand Down Expand Up @@ -748,6 +751,9 @@ const FapProposalsAndAssignmentsTable = ({
PROPOSAL_MODAL_TAB_NAMES.PROPOSAL_INFORMATION,
PROPOSAL_MODAL_TAB_NAMES.TECHNICAL_REVIEW,
]}
fapSecAndChair={data.fapChairs
.map((user) => user.id)
.concat(data.fapSecretaries.map((user) => user.id))}
/>
</ProposalReviewModal>
<AssignFapMemberToProposalModal
Expand Down
Loading

0 comments on commit 7b1e284

Please sign in to comment.