-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MDS-6205] Permit condition specific reports (#3302)
* addressed code quality concern from sonarcloud update PermitConditions.spec.tsx.snap update conditions to fix propogation issue update RenderRadioButtons.spec.js.snap Add report prop to permit condition form and disable button if report exists This commit introduces a new optional `report` prop to the `AddReportToPermitConditionForm` component, allowing it to use an existing report if available. Additionally, it modifies the permit condition layer to disable the "Add Report" button when a report already exists for the sub-condition, and ensures permits are refetched after adding a new report. Rename component and update references Renamed `AddRequestToPermitConditionForm` to `AddReportToPermitConditionForm` to better reflect its purpose. Also updated all references and added a default export for consistency. Added a snapshot test for the form component. Add report handling to permit conditions Enhanced permit conditions to include associated reports. Updated the UI to display report-related information and modified relevant constants, styles, and selectors accordingly. update interfaces to accomodate permit reports added permit condition specific report form updated action buttons on specific permit conditions and updated interface to expand and show action buttons when clicking into a condition. update backend to accomodate new permit condition specific details for mine reports migrate mine_report table with new permit specific details * revert backend changes * create new mine_report_permit_requirement.py table and updated permit return to include these. * Rename form and update permit requirement logic Renamed `AddReporttoPermitConditionForm` to `ReportPermitRequirementForm`. Updated the form to use new `mineReportPermitRequirement` structure. Enhanced `MineReportPermitRequirement` model with soft delete and additional fields like `initial_due_date` and `ministry_recipient`. * added ts-ignore * updated text for adding a report requirement * make view mode RenderDate formatting conditional * address PR comments and added backend resource test. * renamed migration and added cols to buttons on permit conditions * update snap * update permitAmendment factory to create auth end date as date instead of datetime * update mine_report_permit_requirement response model to not break swagger * Enhance permit condition editing permissions Added feature flag check to control permit condition editing. Updated PermitConditionLayer component to respect user permissions and feature availability. Simplified getMineReportPermitRequirements selector for clarity. * Remove unused imports and add new test case for MineReportPermit Removed `ValidationError` and `Raw` imports from `helpers.py` as they were not being used. Added a test case in `test_expected_auth.py` for `MineReportPermitRequirementResource` to ensure proper resource handling and permissions.
- Loading branch information
1 parent
ad07a9c
commit 7670a16
Showing
33 changed files
with
1,687 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.11.7 | ||
3.11.9 |
39 changes: 39 additions & 0 deletions
39
migrations/sql/V2024.11.30.15.10__create_mine_report_permit_requirement_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- Create the cim_or_cpo_type ENUM type | ||
CREATE TYPE cim_or_cpo_type AS ENUM ('CIM', 'CPO', 'BOTH'); | ||
|
||
-- Create the ministry_recipient_type ENUM type | ||
CREATE TYPE ministry_recipient_type AS ENUM ('MMO', 'HS', 'RO', 'MOE'); | ||
|
||
-- Create the new permit_report_requirement table | ||
CREATE TABLE mine_report_permit_requirement | ||
( | ||
mine_report_permit_requirement_id SERIAL PRIMARY KEY, | ||
update_user VARCHAR(255) NOT NULL, | ||
update_timestamp timestamp with time zone DEFAULT now() NOT NULL, | ||
initial_due_date DATE, | ||
due_date_period_months INTEGER NOT NULL, | ||
create_user VARCHAR(255) NOT NULL, | ||
create_timestamp timestamp with time zone DEFAULT now() NOT NULL, | ||
active_ind BOOLEAN DEFAULT true NOT NULL, | ||
deleted_ind BOOLEAN DEFAULT false NOT NULL, | ||
cim_or_cpo cim_or_cpo_type, | ||
ministry_recipient ministry_recipient_type[], | ||
permit_condition_id INTEGER NOT NULL, | ||
permit_amendment_id INTEGER NOT NULL, | ||
CONSTRAINT fk_permit_amendment | ||
FOREIGN KEY (permit_amendment_id) | ||
REFERENCES permit_amendment (permit_amendment_id), | ||
CONSTRAINT fk_permit_condition | ||
FOREIGN KEY (permit_condition_id) | ||
REFERENCES permit_conditions (permit_condition_id) | ||
); | ||
|
||
COMMENT ON TABLE mine_report_permit_requirement IS 'Captures the report requirements laid out in permit conditions which can have permit required reports submitted against'; | ||
|
||
|
||
-- Add a new column `mine_report_permit_requirement_id` to the `mine_report` table | ||
ALTER TABLE mine_report | ||
ADD COLUMN mine_report_permit_requirement_id INTEGER, | ||
ADD CONSTRAINT fk_mine_report_permit_requirement | ||
FOREIGN KEY (mine_report_permit_requirement_id) | ||
REFERENCES mine_report_permit_requirement (mine_report_permit_requirement_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
services/common/src/interfaces/permits/mineReportPermitRequirements.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface IMineReportPermitRequirement { | ||
mine_report_permit_requirement_id: number; | ||
cim_or_cpo: string; | ||
ministry_recipient: string[]; | ||
permit_condition_id: number; | ||
due_date_period_months: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
services/common/src/redux/slices/mineReportPermitRequirementSlice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createAppSlice } from "@mds/common/redux/createAppSlice"; | ||
import { hideLoading, showLoading } from "react-redux-loading-bar"; | ||
import CustomAxios from "@mds/common/redux/customAxios"; | ||
import { ENVIRONMENT, MINE_REPORT_PERMIT_REQUIREMENT } from "@mds/common/constants"; | ||
import { IMineReportPermitRequirement } from "@mds/common/interfaces"; | ||
|
||
const createRequestHeader = REQUEST_HEADER.createRequestHeader; | ||
export const mineReportPermitRequirementReducerType = "mineReportPermitRequirement"; | ||
|
||
interface IMineReportPermitRequirementState {} | ||
|
||
const initialState: IMineReportPermitRequirementState = {}; | ||
|
||
const mineReportPermitRequirementSlice = createAppSlice({ | ||
name: mineReportPermitRequirementReducerType, | ||
initialState, | ||
reducers: (create) => ({ | ||
createMineReportPermitRequirement: create.asyncThunk( | ||
async ( | ||
payload: { | ||
mineGuid: string; | ||
values: IMineReportPermitRequirement; | ||
}, | ||
thunkApi | ||
) => { | ||
const headers = createRequestHeader(); | ||
thunkApi.dispatch(showLoading()); | ||
|
||
const response = await CustomAxios({ | ||
errorToastMessage: "default", | ||
}).post( | ||
`${ENVIRONMENT.apiUrl}${MINE_REPORT_PERMIT_REQUIREMENT(payload.mineGuid)}`, | ||
payload.values, | ||
headers | ||
); | ||
|
||
thunkApi.dispatch(hideLoading()); | ||
return response.data; | ||
} | ||
), | ||
}), | ||
}); | ||
|
||
export const { createMineReportPermitRequirement } = mineReportPermitRequirementSlice.actions; | ||
export const mineReportPermitRequirementReducer = mineReportPermitRequirementSlice.reducer; | ||
export default mineReportPermitRequirementReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
services/core-api/app/api/mines/reports/models/mine_report_permit_requirement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from datetime import date | ||
from enum import Enum | ||
from typing import Optional | ||
|
||
from sqlalchemy.dialects.postgresql import ARRAY | ||
from sqlalchemy.schema import FetchedValue | ||
|
||
from app.api.utils.models_mixins import Base, AuditMixin, SoftDeleteMixin | ||
from app.extensions import db | ||
|
||
|
||
class CimOrCpo(str, Enum): | ||
CIM = "CIM" | ||
CPO = "CPO" | ||
BOTH = "BOTH" | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
|
||
class OfficeDestination(str, Enum): | ||
MMO = "MMO" | ||
HS = "HS" | ||
RO = "RO" | ||
MOE = "MOE" | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
|
||
class MineReportPermitRequirement(SoftDeleteMixin, Base, AuditMixin): | ||
__tablename__ = "mine_report_permit_requirement" | ||
|
||
mine_report_permit_requirement_id: int = db.Column(db.Integer, primary_key=True, server_default=FetchedValue()) | ||
due_date_period_months: int = db.Column(db.Integer, nullable=False) | ||
initial_due_date: Optional[date] = db.Column(db.Date, nullable=True) | ||
active_ind: bool = db.Column(db.Boolean, nullable=False, server_default=FetchedValue()) | ||
cim_or_cpo: Optional[CimOrCpo] = db.Column(db.Enum(CimOrCpo, name='cim_or_cpo_type'), nullable=True) | ||
ministry_recipient: Optional[list[OfficeDestination]] = db.Column( | ||
ARRAY(db.Enum(OfficeDestination, name='ministry_recipient_type')), nullable=True) | ||
permit_condition_id: int = db.Column(db.Integer, db.ForeignKey('permit_conditions.permit_condition_id')) | ||
permit_amendment_id: int = db.Column(db.Integer, db.ForeignKey('permit_amendment.permit_amendment_id')) | ||
|
||
def __repr__(self): | ||
return '<MineReportPermitRequirement %r>' % self.permit_report_requirement_id | ||
|
||
@classmethod | ||
def find_by_permit_report_requirement_id(cls, _id) -> "MineReportPermitRequirement": | ||
try: | ||
return cls.query.filter_by(permit_report_requirement_id=_id).first() | ||
except ValueError: | ||
return None | ||
|
||
@classmethod | ||
def find_by_report_name(cls, _report_name) -> "MineReportPermitRequirement": | ||
try: | ||
return cls.query.filter_by(report_name=_report_name).all() | ||
except ValueError: | ||
return None | ||
|
||
@classmethod | ||
def get_all(cls) -> list["MineReportPermitRequirement"]: | ||
try: | ||
return cls.query.all() | ||
except ValueError: | ||
return None | ||
|
||
@classmethod | ||
def create(cls, | ||
due_date_period_months: int, | ||
initial_due_date: date, | ||
cim_or_cpo: Optional[CimOrCpo], | ||
ministry_recipient: Optional[list[OfficeDestination]], | ||
permit_condition_id: int, | ||
permit_amendment_id: int) -> "MineReportPermitRequirement": | ||
|
||
mine_report_permit_requirement = cls( | ||
due_date_period_months=due_date_period_months, | ||
initial_due_date=initial_due_date, | ||
cim_or_cpo=cim_or_cpo, | ||
ministry_recipient=ministry_recipient, | ||
permit_condition_id=permit_condition_id, | ||
permit_amendment_id=permit_amendment_id | ||
) | ||
|
||
mine_report_permit_requirement.save(commit=True) | ||
return mine_report_permit_requirement |
Oops, something went wrong.