Skip to content

Commit

Permalink
[MDS-5985] validation fix for legacy major projects (#3197)
Browse files Browse the repository at this point in the history
* validation fix for legacy major projects

* adding to project summary factory to attempt to fix pr error

* adjustments to project summary tests to attempt to fix pr errors
  • Loading branch information
asinn134 authored Jul 26, 2024
1 parent 8488702 commit e6ac057
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE project_summary
ADD COLUMN IF NOT EXISTS is_historic boolean DEFAULT false NOT NULL;

UPDATE project_summary
SET is_historic = true
WHERE status_code = 'SUB';
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface IProjectSummary {
mrc_review_required?: boolean;
project_lead_party_guid?: string;
agent?: IParty;
is_historic: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ProjectSummary(SoftDeleteMixin, AuditMixin, Base):

applicant_party_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('party.party_guid'), nullable=True)
payment_contact_party_guid = db.Column(UUID(as_uuid=True), db.ForeignKey('party.party_guid'), nullable=True)
is_historic = db.Column(db.Boolean, nullable=False)

project_guid = db.Column(
UUID(as_uuid=True), db.ForeignKey('project.project_guid'), nullable=False)
Expand Down Expand Up @@ -466,7 +467,7 @@ def validate_project_party(cls, party, section):
return True

@classmethod
def validate_mine_component_offsite_infrastructure(self, data):
def validate_mine_component_offsite_infrastructure(self, data, do_full_validation):
draft_mine_offsite_schema = {
'facility_desc': {
'nullable': True,
Expand Down Expand Up @@ -499,10 +500,9 @@ def validate_mine_component_offsite_infrastructure(self, data):
},
}

status_code = data.get('status_code')
zoning = data.get('zoning')

mine_offsite_schema = submission_mine_offsite_schema if status_code == 'SUB' else draft_mine_offsite_schema
mine_offsite_schema = submission_mine_offsite_schema if do_full_validation else draft_mine_offsite_schema

if zoning == False:
mine_offsite_schema |= {
Expand Down Expand Up @@ -562,7 +562,7 @@ def validate_legal_land(self, data):
return True

@classmethod
def validate_location_access(self, data):
def validate_location_access(self, data, do_full_validation):
draft_location_access_schema = {
'facility_latitude': {
'nullable': True,
Expand Down Expand Up @@ -655,7 +655,6 @@ def validate_location_access(self, data):
}
}

status_code = data.get('status_code')
facility_latitude = data.get('facility_latitude', None)
facility_longitude = data.get('facility_longitude', None)
facility_coords_source = data.get('facility_coords_source', None)
Expand All @@ -668,7 +667,7 @@ def validate_location_access(self, data):
'facility_longitude': float(facility_longitude)}

location_access_schema = draft_location_access_schema
if status_code == 'SUB':
if do_full_validation:
location_access_schema = submission_location_access_schema
if facility_pid_pin_crown_file_no == None and legal_land_desc != None:
location_access_schema |= {
Expand Down Expand Up @@ -763,7 +762,7 @@ def validate_project_summary_surface_level_data(self, data):
return True

@classmethod
def validate_project_summary(cls, data):
def validate_project_summary(cls, data, is_historic):
status_code = data.get('status_code')
ams_authorizations = data.get('ams_authorizations', None)
authorizations = data.get('authorizations', [])
Expand Down Expand Up @@ -809,8 +808,10 @@ def validate_project_summary(cls, data):
'declaration': [],
}

do_full_validation = True if (status_code == 'SUB' and is_historic != True) else False

# Validate Authorizations Involved
if (status_code == 'SUB'
if (do_full_validation
and len(ams_authorizations.get('amendments', [])) == 0
and len(ams_authorizations.get('new', [])) == 0
and len(authorizations) == 0):
Expand All @@ -835,48 +836,48 @@ def validate_project_summary(cls, data):
errors_found['authorizations'].append(ams_authorization_new_validation)

# Validate Applicant Information
if status_code == 'SUB' and applicant == None:
if do_full_validation and applicant == None:
errors_found['applicant_info'].append('Applicant Information not provided')
elif applicant != None:
applicant_validation = ProjectSummary.validate_project_party(applicant, 'applicant')
if applicant_validation != True:
errors_found['applicant_info'].append(applicant_validation)

# Validate Agent
if status_code == 'SUB' and is_agent == None:
if do_full_validation and is_agent == None:
errors_found['agent'].append("Is applicant an agent not provided")
elif is_agent == True:
agent_validation = ProjectSummary.validate_project_party(agent, 'agent')
if agent_validation != True:
errors_found['agent'].append(agent_validation)

# Validate Mine Components and Offsite Infrastructure
if status_code == 'SUB' and facility_operator == None:
if do_full_validation and facility_operator == None:
errors_found['mine_component_and_offsite'].append('Facility address info not provided')
elif facility_operator != None:
mine_offsite_party_validation = ProjectSummary.validate_project_party(facility_operator,
'mine_component_and_offsite')
if mine_offsite_party_validation != True:
errors_found['mine_component_and_offsite'].append(mine_offsite_party_validation)

mine_offsite_validation = ProjectSummary.validate_mine_component_offsite_infrastructure(data)
mine_offsite_validation = ProjectSummary.validate_mine_component_offsite_infrastructure(data, do_full_validation)
if mine_offsite_validation != True:
errors_found['mine_component_and_offsite'].append(mine_offsite_validation)

# Validate Location, Access and Land Use
if status_code == 'SUB' and is_legal_land_owner == None:
if do_full_validation and is_legal_land_owner == None:
errors_found['location_access_land_use'].append('Is the Applicant the Legal Land Owner not provided')
elif is_legal_land_owner == False:
legal_land_validation = ProjectSummary.validate_legal_land(data)
if legal_land_validation != True:
errors_found['location_access_land_use'].append(legal_land_validation)

location_access_validation = ProjectSummary.validate_location_access(data)
location_access_validation = ProjectSummary.validate_location_access(data, do_full_validation)
if location_access_validation != True:
errors_found['location_access_land_use'].append(location_access_validation)

# Validate Declaration
if status_code == 'SUB':
if do_full_validation:
declaration_validation = ProjectSummary.validate_declaration(data)
if declaration_validation != True:
errors_found['declaration'].append(declaration_validation)
Expand Down Expand Up @@ -905,7 +906,8 @@ def create(cls,
authorizations=[],
ams_authorizations=None,
submission_date=None,
add_to_session=True):
add_to_session=True,
is_historic=False):

project_summary = cls(
project_summary_description=project_summary_description,
Expand All @@ -915,7 +917,8 @@ def create(cls,
expected_permit_receipt_date=expected_permit_receipt_date,
expected_project_start_date=expected_project_start_date,
status_code=status_code,
submission_date=submission_date)
submission_date=submission_date,
is_historic=is_historic)

if add_to_session:
project_summary.save(commit=False)
Expand Down Expand Up @@ -997,7 +1000,9 @@ def update(self,
company_alias=None,
regional_district_id=None,
payment_contact=None,
add_to_session=True):
is_historic=False,
add_to_session=True
):

# Update simple properties.
# If we assign a project lead update status to Assigned and vice versa Submitted.
Expand Down Expand Up @@ -1025,6 +1030,7 @@ def update(self,
self.is_billing_address_same_as_mailing_address = is_billing_address_same_as_mailing_address
self.is_billing_address_same_as_legal_address = is_billing_address_same_as_legal_address
self.company_alias = company_alias
self.is_historic = is_historic

# TODO - Turn this on when document removal is activated on the front end.
# Get the GUIDs of the updated documents.
Expand Down Expand Up @@ -1253,4 +1259,4 @@ def send_project_summary_email(self, mine):
}

EmailService.send_template_email(subject, emli_recipients, emli_body, emli_context, cc=cc)
EmailService.send_template_email(subject, minespace_recipients, minespace_body, minespace_context, cc=cc)
EmailService.send_template_email(subject, minespace_recipients, minespace_body, minespace_context, cc=cc)
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ class ProjectSummaryResource(Resource, UserMixin):
required=False
)

parser.add_argument('is_historic', type=bool, store_missing=False, required=True)

@api.doc(
description='Get a Project Description.',
params={
Expand Down Expand Up @@ -202,8 +204,9 @@ def put(self, project_guid, project_summary_guid):
project_summary = ProjectSummary.find_by_project_summary_guid(project_summary_guid)
project = Project.find_by_project_guid(project_guid)
data = self.parser.parse_args()

project_summary_validation = project_summary.validate_project_summary(data)
is_historic = data.get('is_historic')

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}')
raise BadRequest(project_summary_validation)
Expand Down Expand Up @@ -249,7 +252,8 @@ def put(self, project_guid, project_summary_guid):
data.get('contacts'),
data.get('company_alias'),
data.get('regional_district_id'),
data.get('payment_contact'))
data.get('payment_contact'),
is_historic)

project_summary.save()
if prev_status == 'DFT' and project_summary.status_code == 'SUB':
Expand Down Expand Up @@ -290,4 +294,4 @@ def delete(self, project_guid, project_summary_guid):
return None, 204

raise BadRequest(
'Project description must have status code of "DRAFT" to be eligible for deletion.')
'Project description must have status code of "DRAFT" to be eligible for deletion.')
1 change: 1 addition & 0 deletions services/core-api/app/api/projects/response_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def format(self, value):
'municipality': fields.Nested(MUNICIPALITY_MODEL),
'regional_district_id': fields.Integer,
'payment_contact': fields.Nested(PARTY),
'is_historic': fields.Boolean,
})

REQUIREMENTS_MODEL = api.model(
Expand Down
1 change: 1 addition & 0 deletions services/core-api/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ class Params:
documents = []
authorizations = []
deleted_ind = False
is_historic = False

expected_draft_irt_submission_date = None
expected_permit_application_date = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def test_put_project_summary(test_client, db_session, auth_headers):
data['project_summary_title'] = 'Test Project Title - Updated'
data['project_summary_description'] = project_summary.project_summary_description
data['status_code'] = 'DFT'
data['is_historic'] = False

put_resp = test_client.put(
f'/projects/{project_summary.project.project_guid}/project-summaries/{project_summary.project_summary_guid}',
Expand Down Expand Up @@ -80,6 +81,7 @@ def test_update_project_summary_assign_project_lead(test_client, db_session, aut
data['status_code'] = 'DFT'
data['confirmation_of_submission'] = True
data['project_lead_party_guid'] = party.party_guid
data['is_historic'] = False

put_resp = test_client.put(
f'/projects/{project.project_guid}/project-summaries/{project_summary.project_summary_guid}',
Expand All @@ -101,6 +103,7 @@ def test_submit_project_summary_without_ams_auths(test_client, db_session, auth_
data['mine_guid'] = project_summary.project.mine_guid
data['status_code'] = 'SUB'
data['project_lead_party_guid'] = party.party_guid
data['is_historic'] = False

# Basic info data
data['project_summary_title'] = project_summary.project_summary_title
Expand Down Expand Up @@ -164,6 +167,7 @@ def test_update_project_summary_bad_request_with_validation_errors(test_client,
data['status_code'] = 'SUB'
data['project_lead_party_guid'] = party.party_guid
data['documents'] = []
data['is_historic'] = False

# Basic info data
data['project_summary_title'] = project_summary.project_summary_title
Expand Down Expand Up @@ -225,6 +229,7 @@ def test_update_project_summary_validation_success(test_client, db_session, auth
data['status_code'] = 'SUB'
data['project_lead_party_guid'] = party.party_guid
data['documents'] = []
data['is_historic'] = False

# Basic info data
data['project_summary_title'] = project_summary.project_summary_title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ export const ProjectSummary: FC = () => {
: "Successfully submitted a project description to the Province of British Columbia.";

let status_code = formattedProjectSummary.status_code;
let is_historic = formattedProjectSummary.is_historic;

if (!status_code || isNewProject) {
status_code = "DFT";
} else if (!newActiveTab) {
status_code = "SUB";
is_historic = false;
if (amsFeatureEnabled) {
message = null;
}
Expand All @@ -210,7 +213,7 @@ export const ProjectSummary: FC = () => {
await handleCreateProjectSummary(values, message);
}
if (projectGuid && projectSummaryGuid) {
await handleUpdateProjectSummary(values, message);
await handleUpdateProjectSummary({ ...values, is_historic }, message);
handleTabChange(newActiveTab);
setIsLoaded(true);
}
Expand Down
12 changes: 12 additions & 0 deletions services/core-web/src/styles/components/Forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
padding-left: 10px;
}

.ant-checkbox-group-item {
min-width: 0;

&>span {
max-width: 100%;
}
}

// copied corresponding styles from .has-error .ant-input, added border details
.has-error .ant-checkbox-group,
.has-error .ant-checkbox-group:hover {
Expand Down Expand Up @@ -141,4 +149,8 @@
&:hover {
color: $violet;
}
}

.form-item-hidden {
max-width: 100%;
}
4 changes: 4 additions & 0 deletions services/core-web/src/styles/generic/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,8 @@ img.lessOpacity {

.plain-link {
text-decoration: none;
}

.grey-box {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,24 @@ export const ProjectSummaryPage = () => {
: "Successfully submitted a project description to the Province of British Columbia.";

let status_code = projectSummary.status_code;
let is_historic = projectSummary.is_historic;
if (!status_code || !isEditMode) {
status_code = "DFT";
} else if (!newActiveTab) {
status_code = "SUB";
is_historic = false;
if (amsFeatureEnabled) {
message = null;
}
}

const values = { ...formValues, status_code: status_code };
const values = { ...formValues, status_code };
try {
if (!isEditMode) {
await handleCreateProjectSummary(values, message);
}
if (projectGuid && projectSummaryGuid) {
await handleUpdateProjectSummary(values, message);
await handleUpdateProjectSummary({ ...values, is_historic }, message);
handleTabChange(newActiveTab);
setIsLoaded(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
padding-left: 10px;
}

.ant-checkbox-group-item {
min-width: 0;

&>span {
max-width: 100%;
}
}

// Divider

.ant-divider:not(.ant-divider-plain) {
Expand Down

0 comments on commit e6ac057

Please sign in to comment.