diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php index 05165360ee6f0255e56580cb802a594d7e403e30..54dc566ff155f65b8434b428d8bb28bfd75a233b 100755 --- a/src/app/entity/controllers/ListInstanceController.php +++ b/src/app/entity/controllers/ListInstanceController.php @@ -71,13 +71,19 @@ class ListInstanceController } $listInstances = ListInstanceModel::getVisaCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'users.id', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]); + $itemsRemoved = []; foreach ($listInstances as $key => $value) { $listInstances[$key]['item_id'] = $listInstances[$key]['id']; $listInstances[$key]['item_type'] = 'user'; $listInstances[$key]['labelToDisplay'] = $listInstances[$key]['item_firstname'].' '.$listInstances[$key]['item_lastname']; + if (!PrivilegeController::hasPrivilege(['privilegeId' => 'visa_documents', 'userId' => $value['id']]) && !PrivilegeController::hasPrivilege(['privilegeId' => 'sign_document', 'userId' => $value['id']])) { + $itemsRemoved[] = $listInstances[$key]['labelToDisplay']; + unset($listInstances[$key]); + continue; + } } - return $response->withJson($listInstances); + return $response->withJson(['circuit' => $listInstances, 'itemsRemoved' => $itemsRemoved]); } public function getOpinionCircuitByResId(Request $request, Response $response, array $aArgs) @@ -87,13 +93,19 @@ class ListInstanceController } $listInstances = ListInstanceModel::getAvisCircuitByResId(['select' => ['listinstance_id', 'sequence', 'item_id', 'item_type', 'users.id', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment'], 'id' => $aArgs['resId']]); + $itemsRemoved = []; foreach ($listInstances as $key => $value) { $listInstances[$key]['item_id'] = $listInstances[$key]['id']; $listInstances[$key]['item_type'] = 'user'; $listInstances[$key]['labelToDisplay'] = $listInstances[$key]['item_firstname'].' '.$listInstances[$key]['item_lastname']; + if (!PrivilegeController::hasPrivilege(['privilegeId' => 'avis_documents', 'userId' => $value['id']]) && !PrivilegeController::hasPrivilege(['privilegeId' => 'sign_document', 'userId' => $value['id']])) { + $itemsRemoved[] = $listInstances[$key]['labelToDisplay']; + unset($listInstances[$key]); + continue; + } } - return $response->withJson($listInstances); + return $response->withJson(['circuit' => $listInstances, 'itemsRemoved' => $itemsRemoved]); } public function getParallelOpinionByResId(Request $request, Response $response, array $aArgs) diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index 7e0a0bcc643421481e0adca2d8565bd0a39040c9..f560aab8bb9075087ae2893778c4cbd360c2c0a4 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -583,14 +583,26 @@ class ListTemplateController } $circuit = $circuit[0]; + $itemsRemoved = []; $listTemplateItems = ListTemplateItemModel::get(['select' => ['*'], 'where' => ['list_template_id = ?'], 'data' => [$circuit['id']]]); foreach ($listTemplateItems as $key => $value) { $listTemplateItems[$key]['labelToDisplay'] = UserModel::getLabelledUserById(['id' => $value['item_id']]); $listTemplateItems[$key]['descriptionToDisplay'] = UserModel::getPrimaryEntityById(['id' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; + + if ($queryParams['circuit'] == 'visaCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'visa_documents', 'userId' => $value['item_id']]) && !PrivilegeController::hasPrivilege(['privilegeId' => 'sign_document', 'userId' => $value['item_id']])) { + $itemsRemoved[] = $listTemplateItems[$key]['labelToDisplay']; + unset($listTemplateItems[$key]); + continue; + } elseif ($queryParams['circuit'] == 'opinionCircuit' && !PrivilegeController::hasPrivilege(['privilegeId' => 'avis_documents', 'userId' => $value['item_id']])) { + $itemsRemoved[] = $listTemplateItems[$key]['labelToDisplay']; + unset($listTemplateItems[$key]); + continue; + } } - $circuit['items'] = $listTemplateItems; - return $response->withJson(['circuit' => $circuit]); + $circuit['items'] = array_values($listTemplateItems); + + return $response->withJson(['circuit' => $circuit, 'itemsRemoved' => $itemsRemoved]); } private static function controlItems(array $args) diff --git a/src/frontend/app/avis/avis-workflow.component.ts b/src/frontend/app/avis/avis-workflow.component.ts index 534b3a723e4a5c2d7dfde5b26afd817e98997417..46d59aeca84f33a4858135c622f6667ad9f04b72 100644 --- a/src/frontend/app/avis/avis-workflow.component.ts +++ b/src/frontend/app/avis/avis-workflow.component.ts @@ -204,6 +204,11 @@ export class AvisWorkflowComponent implements OnInit { return new Promise((resolve, reject) => { this.http.get(`../../rest/resources/${this.resId}/defaultCircuit?circuit=opinion`).pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), filter((data: any) => !this.functions.empty(data.circuit)), tap((data: any) => { if (!this.functions.empty(data.circuit)) { @@ -268,21 +273,32 @@ export class AvisWorkflowComponent implements OnInit { this.loading = true; this.avisWorkflow.items = []; return new Promise((resolve, reject) => { - this.http.get("../../rest/resources/" + resId + "/opinionCircuit") - .subscribe((data: any) => { - data.forEach((element: any) => { - this.avisWorkflow.items.push( - { - ...element, - difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id' - }); - }); - this.avisWorkflowClone = JSON.parse(JSON.stringify(this.avisWorkflow.items)) - this.loading = false; - resolve(true); - }, (err: any) => { - this.notify.handleErrors(err); - }); + this.http.get("../../rest/resources/" + resId + "/opinionCircuit").pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), + filter((data: any) => !this.functions.empty(data.circuit)), + tap((data: any) => { + data.circuit.forEach((element: any) => { + this.avisWorkflow.items.push( + { + ...element, + difflist_type: this.mode === 'circuit' ? 'AVIS_CIRCUIT' : 'entity_id' + }); + }); + this.avisWorkflowClone = JSON.parse(JSON.stringify(this.avisWorkflow.items)) + }), + finalize(() => { + this.loading = false; + resolve(true); + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); }); } @@ -315,6 +331,11 @@ export class AvisWorkflowComponent implements OnInit { this.loading = true; this.avisWorkflow.items = []; this.http.get("../../rest/resources/" + resId + "/defaultCircuit?circuit=opinion").pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), filter((data: any) => !this.functions.empty(data.circuit)), tap((data: any) => { data.circuit.items.forEach((element: any) => { diff --git a/src/frontend/app/visa/visa-workflow.component.ts b/src/frontend/app/visa/visa-workflow.component.ts index a27d4bd13f60258c6f69ca2d4a353cb8330f3e85..ee8519797fcbc7fe85896d01b754a2ff020a4617 100644 --- a/src/frontend/app/visa/visa-workflow.component.ts +++ b/src/frontend/app/visa/visa-workflow.component.ts @@ -87,6 +87,9 @@ export class VisaWorkflowComponent implements OnInit { return new Promise((resolve, reject) => { this.http.get(route) .subscribe((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } if (data.listTemplates[0]) { this.visaWorkflow.items = data.listTemplates[0].items.map((item: any) => { return { @@ -188,6 +191,11 @@ export class VisaWorkflowComponent implements OnInit { return new Promise((resolve, reject) => { this.http.get(`../../rest/resources/${this.resId}/defaultCircuit?circuit=visa`).pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), filter((data: any) => !this.functions.empty(data.circuit)), tap((data: any) => { if (!this.functions.empty(data.circuit)) { @@ -254,9 +262,15 @@ export class VisaWorkflowComponent implements OnInit { this.loading = true; this.visaWorkflow.items = []; return new Promise((resolve, reject) => { - this.http.get("../../rest/resources/" + resId + "/visaCircuit") - .subscribe((data: any) => { - data.forEach((element: any) => { + this.http.get("../../rest/resources/" + resId + "/visaCircuit").pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), + filter((data: any) => !this.functions.empty(data.circuit)), + tap((data: any) => { + data.circuit.forEach((element: any) => { this.visaWorkflow.items.push( { ...element, @@ -264,11 +278,16 @@ export class VisaWorkflowComponent implements OnInit { }); }); this.visaWorkflowClone = JSON.parse(JSON.stringify(this.visaWorkflow.items)) + }), + finalize(() => { this.loading = false; resolve(true); - }, (err: any) => { - this.notify.handleErrors(err); - }); + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); }); } @@ -276,6 +295,11 @@ export class VisaWorkflowComponent implements OnInit { this.loading = true; this.visaWorkflow.items = []; this.http.get("../../rest/resources/" + resId + "/defaultCircuit?circuit=visaCircuit").pipe( + tap((data: any) => { + if (!this.functions.empty(data.itemsRemoved)) { + this.notify.error(this.lang.itemRemovedFromVisaTemplate + ' : ' + data.itemsRemoved.join(', ')); + } + }), filter((data: any) => !this.functions.empty(data.circuit)), tap((data: any) => { data.circuit.items.forEach((element: any) => { diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index 8eafc2b3af7e7395fa807b729f9d36b07bf5d630..6f0acb28e600aa6ae83b68d81ae25c1e5f1057b9 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -1477,6 +1477,7 @@ export const LANG_EN = { "NOTE_version": "Annotated version", "SIGN_version": "Original version", "versions": "Versions", + "itemRemovedFromVisaTemplate": "The following users have been removed because they cannot make the action", "documentSignedMsg": "The document has been signed, you can't edit this document", "banAutocompleteInput": "Autocomplete BAN input", "noMailContact" : "No (external) contact linked to this mail", diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index e2359868b03d1186d06785dff4d7a55b3b474be3..d2557ee02b8443c6b2294a45b21189714da5e999 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -1516,6 +1516,7 @@ export const LANG_FR = { "NOTE_version": "Version annotée", "SIGN_version": "Version original", "versions": "Versions", + "itemRemovedFromVisaTemplate": "Les utilisateurs suivants ont été retirés car ils n'ont pas le droit de faire l'action", "documentSignedMsg": "Le document a été signé, vous ne pouvez pas editer ce document", "banAutocompleteInput": "Champ autocomplete BAN", "noMailContact" : "Aucun contact (externe) attaché pour ce courrier", diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index 60b6aa7a16ef8586cf1602459b8ed0e111d65205..2264b312aeac0a327729e722975ffaf20c3066d5 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -1502,6 +1502,7 @@ export const LANG_NL = { "NOTE_version": "Annotated version", //_TO_TRANSLATE "SIGN_version": "Original version", //_TO_TRANSLATE "versions": "Versions", //_TO_TRANSLATE + "itemRemovedFromVisaTemplate": "The following users have been removed because they cannot make the action", //_TO_TRANSLATE "documentSignedMsg": "The document has been signed, you can't edit this document", //_TO_TRANSLATE "banAutocompleteInput": "Autocomplete BAN input", //_TO_TRANSLATE "noMailContact" : "No (external) contact linked to this mail", //_TO_TRANSLATE