diff --git a/rest/index.php b/rest/index.php index 1be738274aeb412853db85bd5fd5ef4fbdb86f95..713829ba3c6d3ecd031702e3577793187935cc4e 100755 --- a/rest/index.php +++ b/rest/index.php @@ -79,7 +79,6 @@ $app->get('/attachments/{id}/content', \Attachment\controllers\AttachmentControl $app->get('/attachments/{id}/originalContent', \Attachment\controllers\AttachmentController::class . ':getOriginalFileContent'); $app->get('/attachments/{id}/thumbnail', \Attachment\controllers\AttachmentController::class . ':getThumbnailContent'); $app->put('/attachments/{id}/inSendAttachment', \Attachment\controllers\AttachmentController::class . ':setInSendAttachment'); -$app->get('/attachments/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow'); $app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); $app->put('/attachments/{id}/sign', \SignatureBook\controllers\SignatureBookController::class . ':signAttachment'); $app->put('/attachments/{id}/unsign', \SignatureBook\controllers\SignatureBookController::class . ':unsignAttachment'); @@ -548,6 +547,7 @@ $app->post('/resources/{resId}/messageExchange', \MessageExchange\controllers\Se $app->get('/messageExchangesInitialization', \MessageExchange\controllers\SendMessageExchangeController::class . ':getInitialization'); //ExternalSignatoryBooks +$app->get('/documents/{id}/maarchParapheurWorkflow', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getWorkflow'); $app->get('/maarchParapheur/user/{id}/picture', \ExternalSignatoryBook\controllers\MaarchParapheurController::class . ':getUserPicture'); $app->get('/externalSignatureBooks/enabled', \ExternalSignatoryBook\controllers\ExternalSignatureBookController::class . ':getEnabledSignatureBook'); $app->get('/externalSummary/{resId}', \ExternalSummary\controllers\SummaryController::class . ':getByResId'); diff --git a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php index bca481751c2e5535b4b61db0711c99af441bc0be..a7515448732996dc9ffaf3167750949f43e43592 100755 --- a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php +++ b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php @@ -963,17 +963,29 @@ class MaarchParapheurController public function getWorkflow(Request $request, Response $response, array $args) { - $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['res_id_master', 'status', 'external_id']]); - if (empty($attachment)) { - return $response->withStatus(400)->withJson(['errors' => 'Attachment does not exist']); - } - if (!ResController::hasRightByResId(['resId' => [$attachment['res_id_master']], 'userId' => $GLOBALS['id']])) { - return $response->withStatus(400)->withJson(['errors' => 'Attachment out of perimeter']); + $queryParams = $request->getQueryParams(); + + if ($queryParams['type'] == 'resource') { + if (!ResController::hasRightByResId(['resId' => [$args['id']], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(400)->withJson(['errors' => 'Attachment out of perimeter']); + } + $resource = ResModel::getById(['resId' => $args['id'], 'select' => ['external_id']]); + if (empty($resource)) { + return $response->withStatus(400)->withJson(['errors' => 'Resource does not exist']); + } + } else { + $resource = AttachmentModel::getById(['id' => $args['id'], 'select' => ['res_id_master', 'status', 'external_id']]); + if (empty($resource)) { + return $response->withStatus(400)->withJson(['errors' => 'Attachment does not exist']); + } + if (!ResController::hasRightByResId(['resId' => [$resource['res_id_master']], 'userId' => $GLOBALS['id']])) { + return $response->withStatus(400)->withJson(['errors' => 'Resource does not exist']); + } } - $externalId = json_decode($attachment['external_id'], true); + $externalId = json_decode($resource['external_id'], true); if (empty($externalId['signatureBookId'])) { - return $response->withStatus(400)->withJson(['errors' => 'Attachment is not linked to Maarch Parapheur']); + return $response->withStatus(400)->withJson(['errors' => 'Resource is not linked to Maarch Parapheur']); } $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/visa/xml/remoteSignatoryBooks.xml']); diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index aebabf6ebd0dd5b63b2b7e162e7a1c11cf03b448..122d2d4b68fa8bb81e2537c7f4f1faea6a87475e 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -832,13 +832,18 @@ class ResController extends ResourceControlController return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } - $authorizedFields = ['destination', 'status']; + $authorizedFields = ['destination', 'status', 'externalId']; if (!in_array($args['fieldId'], $authorizedFields)) { return $response->withStatus(403)->withJson(['errors' => 'Field out of perimeter']); } + $mapping = [ + 'destination' => 'destination', + 'status' => 'status', + 'externalId' => 'external_id' + ]; $resource = ResModel::getById([ - 'select' => [$args['fieldId']], + 'select' => [$mapping[$args['fieldId']]], 'resId' => $args['resId'] ]); if (empty($resource)) { @@ -849,6 +854,8 @@ class ResController extends ResourceControlController if ($args['fieldId'] == 'destination' && !empty($queryParams['alt']) && !empty($resource['destination'])) { $entity = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['id']]); $resource['destination'] = $entity['id']; + } elseif ($args['fieldId'] == 'externalId') { + $resource['externalId'] = json_decode($resource['external_id'], true); } return $response->withJson(['field' => $resource[$args['fieldId']]]); diff --git a/src/frontend/app/attachments/attachments-list.component.html b/src/frontend/app/attachments/attachments-list.component.html index 884bf167fe893546c86bcf6e60cbe99ea7bf7e13..6da94830136ba328e1a18723fc4509de0ccbedf4 100644 --- a/src/frontend/app/attachments/attachments-list.component.html +++ b/src/frontend/app/attachments/attachments-list.component.html @@ -91,4 +91,4 @@ <button mat-fab class="addPj" [class.addPjPanel]="target === 'panel'" [class.addPjProcess]="target === 'process'" color="primary" [title]="lang.addAttachment" (click)="createAttachment()"> <mat-icon class="fa fa-plus"></mat-icon> </button> -</ng-template> \ No newline at end of file +</ng-template> diff --git a/src/frontend/app/attachments/attachments-list.component.ts b/src/frontend/app/attachments/attachments-list.component.ts index a77ad55c729c1dce945da8028dac27ff2aa89cc3..4e233ef01f7549bde4e3e63223a27f0597bcc117 100644 --- a/src/frontend/app/attachments/attachments-list.component.ts +++ b/src/frontend/app/attachments/attachments-list.component.ts @@ -229,6 +229,6 @@ export class AttachmentsListComponent implements OnInit { } openMaarchParapheurWorkflow(attachment: any) { - this.dialog.open(VisaWorkflowModalComponent, { panelClass: 'maarch-modal', data: { attachment: attachment } }); + this.dialog.open(VisaWorkflowModalComponent, { panelClass: 'maarch-modal', data: { id: attachment.resId, type: 'attachment' } }); } } diff --git a/src/frontend/app/viewer/document-viewer.component.html b/src/frontend/app/viewer/document-viewer.component.html index 485dc6741ba82db3e963467e7fd483f66d9e01a8..cf3c48eb8237fb9819b69d606246fe9b48607b31 100644 --- a/src/frontend/app/viewer/document-viewer.component.html +++ b/src/frontend/app/viewer/document-viewer.component.html @@ -58,6 +58,10 @@ <mat-icon color="primary" class="fas fa-external-link-alt"></mat-icon> <span>{{lang.openInExternalModal}}</span> </button> + <button mat-menu-item *ngIf="(file.contentView !== undefined || base64 !== null) && resId != null && mode !== 'attachment' && externalId.signatureBookId" (click)="openMaarchParapheurWorkflow()"> + <mat-icon color="primary" class="fas fa-list-ol"></mat-icon> + <span>{{lang.externalVisaWorkflow}}</span> + </button> <button mat-menu-item *ngIf="editMode && resId === null" (click)="docToUpload.click()"> <mat-icon color="primary" class="fa fa-file-upload"></mat-icon> <span>{{lang.uploadAnOtherFile}}</span> @@ -120,4 +124,4 @@ [title]="lang.unsign" style="position: fixed;z-index: 1;bottom: 100px;right: 150px;" (click)="unsignMainDocument()"> {{lang.removeSignature}} -</button> \ No newline at end of file +</button> diff --git a/src/frontend/app/viewer/document-viewer.component.ts b/src/frontend/app/viewer/document-viewer.component.ts index 9ea013ba9fa371731c91f223cdd40e61a71f7576..2db4d4f4af90b7eeef0bed920564e1f961966485 100644 --- a/src/frontend/app/viewer/document-viewer.component.ts +++ b/src/frontend/app/viewer/document-viewer.component.ts @@ -16,6 +16,7 @@ import { EcplOnlyofficeViewerComponent } from '../../plugins/onlyoffice-api-js/o import { FunctionsService } from '../../service/functions.service'; import { DocumentViewerModalComponent } from './modal/document-viewer-modal.component'; import { PrivilegeService } from '../../service/privileges.service'; +import {VisaWorkflowModalComponent} from "../visa/modal/visa-workflow-modal.component"; @Component({ @@ -59,6 +60,7 @@ export class DocumentViewerComponent implements OnInit { listTemplates: any[] = []; + externalId: any = {}; templateListForm = new FormControl(); @@ -569,6 +571,15 @@ export class DocumentViewerComponent implements OnInit { return of(false); } ); + this.http.get(`../../rest/resources/${this.resId}/fields/externalId`).pipe( + tap((data: any) => { + this.externalId = data.field; + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); } } } @@ -961,4 +972,8 @@ export class DocumentViewerComponent implements OnInit { return true; } } + + openMaarchParapheurWorkflow() { + this.dialog.open(VisaWorkflowModalComponent, { panelClass: 'maarch-modal', data: { id: this.resId, type: 'resource' } }); + } } diff --git a/src/frontend/app/visa/modal/visa-workflow-modal.component.ts b/src/frontend/app/visa/modal/visa-workflow-modal.component.ts index ac7ca6209290710bd6ca0107d8b34377cd23b335..7d2d1fa4335f49d331b013740f831d7cdefbfac7 100644 --- a/src/frontend/app/visa/modal/visa-workflow-modal.component.ts +++ b/src/frontend/app/visa/modal/visa-workflow-modal.component.ts @@ -17,7 +17,7 @@ export class VisaWorkflowModalComponent { constructor(public http: HttpClient, @Inject(MAT_DIALOG_DATA) public data: any, public dialogRef: MatDialogRef<VisaWorkflowModalComponent>) { } ngOnInit(): void { - this.appVisaWorkflow.loadWorkflowMaarchParapheur(this.data.attachment.resId); + this.appVisaWorkflow.loadWorkflowMaarchParapheur(this.data.id, this.data.type); } } diff --git a/src/frontend/app/visa/visa-workflow.component.ts b/src/frontend/app/visa/visa-workflow.component.ts index e8cb7654d921a5dae861626f9f241fd8eef6f348..60c76fdf2655f1799a625e192eeafbb743518336 100644 --- a/src/frontend/app/visa/visa-workflow.component.ts +++ b/src/frontend/app/visa/visa-workflow.component.ts @@ -306,10 +306,10 @@ export class VisaWorkflowComponent implements OnInit { ).subscribe(); } - loadWorkflowMaarchParapheur(attachmentId: number) { + loadWorkflowMaarchParapheur(attachmentId: number, type: string) { this.loading = true; this.visaWorkflow.items = []; - this.http.get(`../../rest/attachments/${attachmentId}/maarchParapheurWorkflow`) + this.http.get(`../../rest/documents/${attachmentId}/maarchParapheurWorkflow?type=${type}`) .subscribe((data: any) => { data.workflow.forEach((element: any, key: any) => { const user = {