From 520e6a3baf3462d99cc2a766d60b4e8a9cbe2bb6 Mon Sep 17 00:00:00 2001 From: Ian Liu <81595625+ianliuwk1019@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:18:37 -0700 Subject: [PATCH] fix: #692 Admin FOM should not be editable when commenting open. (#693) * fix: add isCommentingOpen state * adjust admin add/edit form condition for some fields so that it should not be editable during commenting open * Add Timber Sales Manager clientId for fake user access for testing. * Dummy touch for api for deployment. * rename variable * Adjust disabled condition based on further clearification. * Add business rules for update --------- Co-authored-by: Craig Yu --- .../fom-add-edit/fom-add-edit.component.html | 441 +++++++++++------- .../fom-add-edit/fom-add-edit.component.ts | 50 +- admin/src/core/services/mock-user.ts | 1 + .../app/modules/project/project.service.ts | 24 +- api/src/main.ts | 2 +- 5 files changed, 341 insertions(+), 177 deletions(-) diff --git a/admin/src/app/foms/fom-add-edit/fom-add-edit.component.html b/admin/src/app/foms/fom-add-edit/fom-add-edit.component.html index ea683bfdf..7b7799848 100644 --- a/admin/src/app/foms/fom-add-edit/fom-add-edit.component.html +++ b/admin/src/app/foms/fom-add-edit/fom-add-edit.component.html @@ -37,7 +37,8 @@

{{isCreate ? 'Add New' : 'Edit'}} FOM {{isCreate ? '' : '
-
+
+ {{isCreate ? 'Add New' : 'Edit'}} FOM {{isCreate ? '' : ' [value]="originalProjectResponse.id" />
+ +
-
+
+ +
+ +
+
-
- -
-
+ +
-
+
{{isCreate ? 'Add New' : 'Edit'}} FOM {{isCreate ? '' : ' />
+
- +
- + +
+ +
+ {{getErrorMessage('opStartDate', 'required')}} +
+
+ -
- {{getErrorMessage('opStartDate', 'required')}} -
+ +
- + +
+ +
+ {{getErrorMessage('opEndDate', 'required')}} +
+
+ {{getErrorMessage('opEndDate', 'minDate')}} +
+
-
- {{getErrorMessage('opEndDate', 'required')}} -
-
- {{getErrorMessage('opEndDate', 'minDate')}} -
- - - + +
+ +
+ {{getErrorMessage('projectPlanCode', 'required')}} +
+
+ -
- {{getErrorMessage('projectPlanCode', 'required')}} -
- + +
- - + +
+
{{getErrorMessage('fspId', 'required')}}
+
{{getErrorMessage('fspId', 'numeric')}}
+
+
+ -
-
{{getErrorMessage('fspId', 'required')}}
-
{{getErrorMessage('fspId', 'numeric')}}
-
- +
- - + +
+
+ {{getErrorMessage('woodlotLicenseNumber', 'required')}} +
+
+ {{getErrorMessage('woodlotLicenseNumber', 'woodlotFormat')}} +
+
+
+ -
-
- {{getErrorMessage('woodlotLicenseNumber', 'required')}} -
-
- {{getErrorMessage('woodlotLicenseNumber', 'woodlotFormat')}} -
-
+
- -
- {{getErrorMessage('district', 'required')}} +
+ +
+ {{getErrorMessage('district', 'required')}} +
+
+ +
+
+ +
+ {{getErrorMessage('name', 'required')}} +
+
+ {{getErrorMessage('name', 'minLength')}} +
+
-
- {{getErrorMessage('name', 'required')}} -
-
- {{getErrorMessage('name', 'minLength')}} -
+ +
- - {{isCreate ? 'Add New' : 'Edit'}} FOM {{isCreate ? '' : '
+ +
-
+ +
- + {{descriptionLimit-fg.get('description').value?.length}} characters remaining. +
+ {{getErrorMessage('description', 'required')}} +
+
+ - {{descriptionLimit-fg.get('description').value?.length}} characters remaining. -
- {{getErrorMessage('description', 'required')}} -
+ disabled + [value]="fg.get('description').value" + >
-
+ +
Newspaper Public Notice diff --git a/admin/src/app/foms/fom-add-edit/fom-add-edit.component.ts b/admin/src/app/foms/fom-add-edit/fom-add-edit.component.ts index 1887fa540..87c38d966 100644 --- a/admin/src/app/foms/fom-add-edit/fom-add-edit.component.ts +++ b/admin/src/app/foms/fom-add-edit/fom-add-edit.component.ts @@ -38,11 +38,11 @@ type ApplicationPageType = 'create' | 'edit'; @Component({ standalone: true, imports: [ - NgIf, - FormsModule, - ReactiveFormsModule, - BsDatepickerModule, - NgClass, + NgIf, + FormsModule, + ReactiveFormsModule, + BsDatepickerModule, + NgClass, NgFor, AppFormControlDirective, NewlinesPipe, @@ -68,6 +68,9 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { public initialPublicDocument: any[] = []; public districtIdSelect: any = null; public forestClientSelect: any = null; + public isInitialState: boolean = true; + public isCommentingOpenState: boolean = false; + public isCommentingClosedState: boolean = false; public isPublishState: boolean = false; files: any[] = []; maxFileSize: number = MAX_FILEUPLOAD_SIZE.DOCUMENT; @@ -97,12 +100,12 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { private scrollToFragment: string = null; private snackBarRef: MatSnackBarRef = null; private ngUnsubscribe: Subject = new Subject(); - + // bsDatepicker config object readonly bsConfig = { - dateInputFormat: 'YYYY', - minMode: 'year', - minDate: moment().toDate(), + dateInputFormat: 'YYYY', + minMode: 'year', + minDate: moment().toDate(), maxDate: moment().add(7, 'years').toDate(), // current + 7 years containerClass: 'theme-dark-blue' } as Partial @@ -127,7 +130,7 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { get isCreate() { return this.state === 'create'; } - + get isLoading() { return this.stateSvc.loading; } @@ -169,7 +172,9 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { } this.forestClientSelect = this.originalProjectResponse.forestClient.id; - + this.isInitialState = this.originalProjectResponse.workflowState.code === WorkflowStateEnum.Initial; + this.isCommentingOpenState = this.originalProjectResponse.workflowState.code === WorkflowStateEnum.CommentOpen; + this.isCommentingClosedState = this.originalProjectResponse.workflowState.code === WorkflowStateEnum.CommentClosed; this.isPublishState = this.originalProjectResponse.workflowState.code === WorkflowStateEnum.Published; this.attachmentResolverSvc.getAttachments(this.originalProjectResponse.id) @@ -335,11 +340,11 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { this.fg.get('forestClient').setValue(forestClientField.value); this.forestClientSelect = parseInt(forestClientField.value.id); - // 'TIMBER SALES MANAGER' name field is required (to be validated) based on forestClient name - // conditionally. Due to it's validation is annotation-based in fom-add-edit.form.ts + // 'TIMBER SALES MANAGER' name field is required (to be validated) based on forestClient name + // conditionally. Due to it's validation is annotation-based in fom-add-edit.form.ts // (using @rxweb/reactive-form-validators), when forestClient is changed, bctsMgrName does not get // rerenderred (no ngIf, ngFor etc on this field). - // Just trigger the dynamic form field (with enable()) is probably easier than using 'ChangeDetectorRef'. + // Just trigger the dynamic form field (with enable()) is probably easier than using 'ChangeDetectorRef'. this.fg.get('bctsMgrName').enable(); } @@ -356,7 +361,7 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { } /* - * Closed Date cannot be before (30 days after Comment Opening Date) + * Closed Date cannot be before (30 days after Comment Opening Date) * if FOM status is in 'Commenting Open". */ validateClosedDate(closedDate: Date): void { @@ -437,6 +442,17 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { return item; } + getDistrictDesc(districtId) { + const desc = this.districts.filter((item) => { + return item.id == districtId + })[0]["name"]; + return desc; + } + + getformatedDate(field, format = 'YYYY') { + return moment(this.fg.get(field).value).format(format); + } + /** * Additional setup for form control. */ @@ -457,7 +473,7 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { const commentingClosedDateField = fg.get('commentingClosedDate'); const closeDatePipe = this.datePipe.transform(fg.value.commentingClosedDate,'yyyy-MM-dd'); commentingClosedDateField.setValue(closeDatePipe); - if ((user.isMinistry && !user.isForestClient) || + if ((user.isMinistry && !user.isForestClient) || commentingOpenDateField.value == null) { commentingClosedDateField.disable(); } @@ -479,4 +495,4 @@ export class FomAddEditComponent implements OnInit, AfterViewInit, OnDestroy { return control?.touched || control?.dirty; } -} \ No newline at end of file +} diff --git a/admin/src/core/services/mock-user.ts b/admin/src/core/services/mock-user.ts index 87e9ce0d3..524e5032c 100644 --- a/admin/src/core/services/mock-user.ts +++ b/admin/src/core/services/mock-user.ts @@ -53,5 +53,6 @@ export function getFakeAllAccessUser(): User { user.isForestClient = true; user.clientIds.push('00001011') user.clientIds.push('00001012'); + user.clientIds.push('00132188'); return user; } diff --git a/api/src/app/modules/project/project.service.ts b/api/src/app/modules/project/project.service.ts index 570e0993c..d2c97ce4b 100644 --- a/api/src/app/modules/project/project.service.ts +++ b/api/src/app/modules/project/project.service.ts @@ -131,9 +131,29 @@ export class ProjectService extends DataService, Pr } } - // Cannot change commenting closed date when state is COMMENT_CLOSED. + // When COMMENT_CLOSED, cannot change: "Start of Operation", "End of Operation", "FSP ID", "District", + // "FOM Name", "Timber Sales Manager Name", "Description" + if (WorkflowStateEnum.COMMENT_OPEN == entity.workflowStateCode) { + if (entity.operationStartYear !== dto.operationStartYear || + entity.operationEndYear !== dto.operationEndYear || + entity.fspId !== dto.fspId || + entity.districtId !== dto.districtId || + entity.name !== dto.name || + entity.bctsMgrName !== dto.bctsMgrName || + entity.description !== dto.description + ) { + this.logger.debug(`Cannot change "Start of Operation", "End of Operation", "FSP ID", "District", + "FOM Name", "Timber Sales Manager Name", "Description" for state ${entity.workflowStateCode}.`); + return false; + } + } + + // When COMMENT_CLOSED, cannot change "commenting open date" "commenting closed date", "district". if (WorkflowStateEnum.COMMENT_CLOSED == entity.workflowStateCode) { - if (entity.commentingClosedDate !== dto.commentingClosedDate) { + if (entity.commentingOpenDate !== dto.commentingOpenDate || + entity.commentingClosedDate !== dto.commentingClosedDate || + entity.districtId !== dto.districtId + ) { this.logger.debug(`Cannot change commenting closed date for state ${entity.workflowStateCode}.`); return false; } diff --git a/api/src/main.ts b/api/src/main.ts index 787f2e5e9..da9079581 100644 --- a/api/src/main.ts +++ b/api/src/main.ts @@ -189,4 +189,4 @@ if (process.argv.length > 2 && standaloneRunTestDataMigrations(); } else { startApi(); -} \ No newline at end of file +} \ No newline at end of file