Skip to content

Commit

Permalink
[MDS-6263] Adjustments around Assigned status not behaving as aspected (
Browse files Browse the repository at this point in the history
#3334)

* adjustments around Assigned status

* update tests

* attempting to fix test error

* addressing pr comments

* removing text

* fix for cypress error
  • Loading branch information
asinn134 authored Dec 12, 2024
1 parent 0be6a12 commit 9c52a18
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ const ProjectDescriptionTab = () => {
<Typography.Title level={2}>Project Description Overview</Typography.Title>
</Col>
<Col>
<Button onClick={handleViewProjectDescriptionClicked} type="primary">
<Button onClick={handleViewProjectDescriptionClicked} type="primary" data-cy="view-project-description-details-button">
View Project Description Details
</Button>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports[`ProjectDescriptionTab renders properly 1`] = `
>
<button
class="ant-btn ant-btn-primary"
data-cy="view-project-description-details-button"
type="button"
>
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export const AuthorizationsInvolved: FC<ProjectSummaryFormComponentProps> = ({ f

const systemFlag = useSelector(getSystemFlag);
const isCore = systemFlag === SystemFlagEnum.core;
const envFieldsDisabled = areAuthEnvFieldsDisabled(systemFlag, formValues?.status_code);
const envFieldsDisabled = areAuthEnvFieldsDisabled(systemFlag, formValues?.status_code, formValues?.confirmation_of_submission);

const handleChange = (e, code) => {
if (e.target.checked) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,18 @@ export const ProjectManagement: FC = () => {
component={RenderSelect}
data={projectLeadData}
/>
{isProjectLeadAssigned && (
<Paragraph>
<b>Warning:</b> Unassigning the project lead will set the Project Description status to
'Submitted' in MineSpace. Ensure the status is correct before proceeding.
</Paragraph>
)}
{!isNewProject && !isProjectLeadAssigned && (
<Alert
message="This project does not have a Project Lead"
description={<p>Please assign a Project Lead to this project.</p>}
message="Assign a Project Lead"
description={<p>Assigning a Project Lead will set the Project Description status
to 'Assigned' in Core and 'Submitted' in MineSpace. Please ensure the project
is set at the correct status before continuing.</p>}
type="warning"
showIcon
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export const ProjectSummaryForm: FC<ProjectSummaryFormProps> = ({
getProjectSummaryAuthorizationTypesArray
);
const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm;
const { status_code } = formValues ?? {};
const { status_code, confirmation_of_submission } = formValues ?? {};

const fieldsDisabled = areFieldsDisabled(systemFlag, status_code);
const fieldsDisabled = areFieldsDisabled(systemFlag, status_code, confirmation_of_submission);
const docFieldsDisabled = areDocumentFieldsDisabled(systemFlag, status_code);
const authFieldsDisabled = areAuthFieldsDisabled(systemFlag, status_code);
const authFieldsDisabled = areAuthFieldsDisabled(systemFlag, status_code, confirmation_of_submission);

const handleTransformPayload = (valuesFromForm: any) => {
return formatProjectPayload(valuesFromForm, { projectSummaryAuthorizationTypesArray });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ exports[`Project Management renders properly 1`] = `
<div
class="ant-alert-message"
>
This project does not have a Project Lead
Assign a Project Lead
</div>
<div
class="ant-alert-description"
>
<p>
Please assign a Project Lead to this project.
Assigning a Project Lead will set the Project Description status to 'Assigned' in Core and 'Submitted' in MineSpace. Please ensure the project is set at the correct status before continuing.
</p>
</div>
</div>
Expand Down
16 changes: 14 additions & 2 deletions services/common/src/components/projects/projectUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,20 @@ TEST_PARAMETERS.forEach(
expect(result).toBe(true);
});
});

if (label !== "areDocumentFieldsDisabled") {
const noSubmissionMinespaceDisabledStatuses = [...msDisabledStatuses].filter((status) => status !== "ASG");
noSubmissionMinespaceDisabledStatuses.forEach((status) => {
it(`MS status: ${status} Should return true (disabled) when submission has not occured`, () => {
const result = testFunction(SystemFlagEnum.ms, status);
expect(result).toBe(true);
});
})
}

msDisabledStatuses.forEach((status) => {
it(`MS status: ${status} Should return true (disabled)`, () => {
const result = testFunction(SystemFlagEnum.ms, status);
it(`MS status: ${status} Should return true (disabled) when submission has occured`, () => {
const result = testFunction(SystemFlagEnum.ms, status, true);
expect(result).toBe(true);
});
});
Expand All @@ -72,6 +83,7 @@ TEST_PARAMETERS.forEach(
expect(result).toBe(false);
});
});

msEnabledStatuses.forEach((status) => {
it(`MS status: ${status} Should return false (enabled)`, () => {
const result = testFunction(SystemFlagEnum.ms, status);
Expand Down
17 changes: 6 additions & 11 deletions services/common/src/components/projects/projectUtils.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import { PROJECT_STATUS_CODES, SystemFlagEnum } from "@mds/common/constants/enums";
import { memoize } from "lodash";

export const areFieldsDisabled = memoize((systemFlag: SystemFlagEnum, projectSummaryStatusCode: string) => {
export const areFieldsDisabled = memoize((systemFlag: SystemFlagEnum, projectSummaryStatusCode: string, confirmationOfSubmission?: boolean) => {
// Return false (enabled) if status = "" => "Not Started"
const isStatusInEnum = (<any>Object).values(PROJECT_STATUS_CODES).includes(projectSummaryStatusCode);

if (!isStatusInEnum) return false;
const projectSummaryStatus = projectSummaryStatusCode as PROJECT_STATUS_CODES;

const disabledStatuses = [PROJECT_STATUS_CODES.WDN, PROJECT_STATUS_CODES.COM];

const enabledStatuses = systemFlag === SystemFlagEnum.core
? [PROJECT_STATUS_CODES.DFT, PROJECT_STATUS_CODES.ASG, PROJECT_STATUS_CODES.UNR, PROJECT_STATUS_CODES.CHR, PROJECT_STATUS_CODES.OHD, PROJECT_STATUS_CODES.SUB]
: [PROJECT_STATUS_CODES.DFT, PROJECT_STATUS_CODES.CHR];
: [PROJECT_STATUS_CODES.DFT, PROJECT_STATUS_CODES.CHR, ...(!confirmationOfSubmission ? [PROJECT_STATUS_CODES.ASG] : [])];

if (disabledStatuses.includes(projectSummaryStatus)) return true;
return !enabledStatuses.includes(projectSummaryStatus);

},
(systemFlag: SystemFlagEnum, projectSummaryStatusCode: string) => `${systemFlag}_${projectSummaryStatusCode}`);

export const areAuthFieldsDisabled = memoize((systemFlag: SystemFlagEnum, projectSummaryStatusCode: string) => {
const fieldsDisabled = areFieldsDisabled(systemFlag, projectSummaryStatusCode);
export const areAuthFieldsDisabled = memoize((systemFlag: SystemFlagEnum, projectSummaryStatusCode: string, confirmationOfSubmission?: boolean) => {
const fieldsDisabled = areFieldsDisabled(systemFlag, projectSummaryStatusCode, confirmationOfSubmission);
if (fieldsDisabled) return true;

const extraDisabledStatuses = [PROJECT_STATUS_CODES.CHR, PROJECT_STATUS_CODES.UNR];
const authDisabled = extraDisabledStatuses.includes(projectSummaryStatusCode as PROJECT_STATUS_CODES)
return authDisabled;
}, (systemFlag: SystemFlagEnum, projectSummaryStatusCode: string) => `${systemFlag}_${projectSummaryStatusCode}`);

export const areAuthEnvFieldsDisabled = memoize((systemFlag, projectSummaryStatusCode) => {
const authFieldsDisabled = areAuthFieldsDisabled(systemFlag, projectSummaryStatusCode);
export const areAuthEnvFieldsDisabled = memoize((systemFlag: SystemFlagEnum, projectSummaryStatusCode: string, confirmationOfSubmission?: boolean) => {
const authFieldsDisabled = areAuthFieldsDisabled(systemFlag, projectSummaryStatusCode, confirmationOfSubmission);
if (authFieldsDisabled) return true;

const extraDisabledStatuses = systemFlag === SystemFlagEnum.core
Expand All @@ -56,7 +52,6 @@ export const areDocumentFieldsDisabled = memoize((systemFlag: SystemFlagEnum, pr

if (disabledStatuses.includes(projectSummaryStatus)) return true;
return !enabledStatuses.includes(projectSummaryStatus);

},
(systemFlag: SystemFlagEnum, projectSummaryStatusCode: string) => `${systemFlag}_${projectSummaryStatusCode}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ export interface IProjectSummaryForm extends Omit<IProjectSummary, "authorizatio
legal_land_desc: string;
facility_pid_pin_crown_file_no: string;
zoning: boolean;
confirmation_of_submission?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,9 @@ def update(self,

# Update simple properties.
# If we assign a project lead update status to Assigned and vice versa Submitted.
if project_lead_party_guid and project.project_lead_party_guid is None:
if project_lead_party_guid and project.project_lead_party_guid is None and self.status_code == status_code:
self.status_code = "ASG"
elif project_lead_party_guid is None and project.project_lead_party_guid:
elif project_lead_party_guid is None and project.project_lead_party_guid and self.status_code == status_code:
self.status_code = "SUB"
else:
self.status_code = status_code
Expand Down Expand Up @@ -1327,7 +1327,7 @@ def send_project_summary_email(self, mine, message) -> None:
'COM': [PERM_RECL_EMAIL, project_lead_email]
}

send_ms_email = self.status_code != "DFT"
send_ms_email = self.status_code != "DFT" and self.status_code != "ASG"

emli_recipients = emli_emails.get(self.status_code)
cc = [MDS_EMAIL]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from app.api.activity.utils import trigger_notification
from app.api.projects.project.project_util import notify_file_updates
from decimal import Decimal
from app.api.activity.models.activity_notification import ActivityRecipients

PAGE_DEFAULT = 1
PER_PAGE_DEFAULT = 25
Expand Down Expand Up @@ -206,7 +207,7 @@ def put(self, project_guid, project_summary_guid):
project = Project.find_by_project_guid(project_guid)
data = self.parser.parse_args()
is_historic = data.get('is_historic')

activity_recipients = ActivityRecipients.all_users
project_summary_validation = project_summary.validate_project_summary(data, is_historic)
if any(project_summary_validation[i] != [] for i in project_summary_validation):
current_app.logger.error(f'Project Summary schema validation failed with errors: {project_summary_validation}')
Expand Down Expand Up @@ -280,6 +281,7 @@ def put(self, project_guid, project_summary_guid):

if project_summary.status_code == 'ASG':
message = f'{project.project_title} for {project.mine_name} has been assigned'
activity_recipients = ActivityRecipients.core_users

if project_summary.status_code == 'CHR':
message = f'Changes have been requested by the ministry for {project.project_title} at {project.mine_name}'
Expand All @@ -295,12 +297,12 @@ def put(self, project_guid, project_summary_guid):

if project_summary.status_code == 'COM':
message = f'The status of the project description {project.project_title} for {project.mine_name} has been completed'

project_summary.send_project_summary_email(mine, message)
trigger_notification(message, ActivityType.major_mine_desc_submitted, project.mine, 'ProjectSummary',
project_summary.project_summary_guid, extra_data)


if message != '':
project_summary.send_project_summary_email(mine, message)
trigger_notification(message, ActivityType.major_mine_desc_submitted, project.mine, 'ProjectSummary',
project_summary.project_summary_guid, extra_data, None, activity_recipients)

# notify on document updates
if has_new_documents:
notify_file_updates(project, mine, project_summary.status_code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,10 @@ def test_sub_to_asg(mock_send_template_email, test_client, db_session, auth_head
"message": f'{updated_project_summary_title} for {project_summary.project.mine_name} has been assigned',
"core_project_summary_link": f'{Config.CORE_WEB_URL}/pre-applications/{project_summary.project.project_guid}/overview'
}

minespace_context = {
"mine": {
"mine_name": project_summary.mine_name,
"mine_no": project_summary.project.mine_no,
},
"message": f'{updated_project_summary_title} for {project_summary.project.mine_name} has been assigned',
"minespace_project_summary_link": f'{Config.MINESPACE_PROD_URL}/projects/{project_summary.project.project_guid}/overview',
"ema_auth_link": f'{Config.EMA_AUTH_LINK}',
}

# ARGS: subject, recipients, body, context, cc (ignore comparison with ANY)
emli_call = call(f'Project Description Notification for {project_summary.mine_name}', ANY, ANY, emli_context, cc=[MDS_EMAIL])
ms_call = call(f'Project Description Notification for {project_summary.mine_name}', ANY, ANY, minespace_context, cc=[MDS_EMAIL])

assert put_resp.status_code == 200
calls = [emli_call, ms_call]
calls = [emli_call]
mock_send_template_email.assert_has_calls(calls, True)
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_delete_project_summary_bad_status_code(test_client, db_session, auth_he
def test_update_project_summary_assign_project_lead(test_client, db_session, auth_headers):
'''Assigning a project lead will change status code to ASG'''
project = ProjectFactory(project_summary=0)
project_summary = ProjectSummaryFactory(project=project)
project_summary = ProjectSummaryFactory(project=project, set_status_code='DFT')
party = PartyFactory(person=True)

data = {}
Expand Down
6 changes: 6 additions & 0 deletions services/core-web/cypress/e2e/majorprojects.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ describe("Major Projects", () => {
it("should upload and download a document successfully", () => {
const fileName = "dummy.pdf";

cy.get('body').then((element) => {
if (element.find("button[data-cy=view-project-description-details-button]").length > 0) {
cy.contains("View Project Description Details").click();
}
})

cy.contains("Document Upload").click();

cy.contains("Edit Project Description").click();
Expand Down
16 changes: 3 additions & 13 deletions services/core-web/src/components/mine/Projects/ProjectSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
AMS_STATUS_CODES_SUCCESS,
AMS_STATUS_CODE_FAIL,
AMS_ENVIRONMENTAL_MANAGEMENT_ACT_TYPES,
SystemFlagEnum,
} from "@mds/common";
import { getMineById } from "@mds/common/redux/reducers/mineReducer";
import withFeatureFlag from "@mds/common/providers/featureFlags/withFeatureFlag";
Expand All @@ -37,7 +36,6 @@ import ProjectSummaryForm, {
} from "@mds/common/components/projectSummary/ProjectSummaryForm";
import { fetchRegions } from "@mds/common/redux/slices/regionsSlice";
import { clearProjectSummary } from "@mds/common/redux/actions/projectActions";
import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors";
import { cancelConfirmWrapper } from "@mds/common/components/forms/RenderCancelButton";
import { fetchActivities } from "@mds/common/redux/actionCreators/activityActionCreator";
import { getUserInfo } from "@mds/common/redux/selectors/authenticationSelectors";
Expand All @@ -54,10 +52,6 @@ export const ProjectSummary: FC = () => {
mode: string;
}>();
const userInfo = useSelector(getUserInfo);

const systemFlag = useSelector(getSystemFlag);
const isCore = systemFlag === SystemFlagEnum.core;

const mine = useSelector((state) => getMineById(state, mineGuid));
const formattedProjectSummary = useSelector(getFormattedProjectSummary);
const project = useSelector(getProject);
Expand Down Expand Up @@ -215,19 +209,15 @@ export const ProjectSummary: FC = () => {

if (!status_code || isNewProject) {
status_code = "DFT";
} else if (!newActiveTab) {
if (isCore) {
status_code = formValues.status_code;
} else {
status_code = "SUB";
}
} else if (!newActiveTab && status_code === "DFT") {
status_code = "SUB";
is_historic = false;
if (amsFeatureEnabled) {
message = null;
}
}

if (isCore && !isNewProject) {
if (!isNewProject && newActiveTab) {
status_code = formValues.status_code;
}

Expand Down

0 comments on commit 9c52a18

Please sign in to comment.