From 73f7ca0a8390e90c5d5ba1162166b393b1ea6995 Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Wed, 16 Oct 2019 15:45:04 +0200 Subject: [PATCH] FEAT #12014 TIME 1:30 prevent clicking on delete button if needed --- src/app/folder/controllers/FolderController.php | 6 +++++- src/frontend/app/folder/folder-tree.component.html | 4 ++-- src/frontend/app/folder/folder-tree.component.ts | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/folder/controllers/FolderController.php b/src/app/folder/controllers/FolderController.php index 5799cc2216b..a2c5f7839cc 100755 --- a/src/app/folder/controllers/FolderController.php +++ b/src/app/folder/controllers/FolderController.php @@ -114,7 +114,8 @@ class FolderController if ($folder['public']) { $entitiesFolder = EntityFolderModel::getByFolderId(['folder_id' => $args['id'], 'select' => ['entities_folders.entity_id', 'entities_folders.edition', 'entities.entity_label']]); foreach ($entitiesFolder as $value) { - $folder['sharing']['entities'][] = ['entity_id' => $value['entity_id'], 'edition' => $value['edition'], 'label' => $value['entity_label']]; + $canDelete = FolderController::areChildrenInPerimeter(['folderId' => $args['id']]); + $folder['sharing']['entities'][] = ['entity_id' => $value['entity_id'], 'edition' => $value['edition'], 'canDelete' => $canDelete, 'label' => $value['entity_label']]; } } @@ -389,6 +390,9 @@ class FolderController if ($child['edition'] == false or $child['edition'] == null) { return false; } + if (!FolderController::areChildrenInPerimeter(['folderId' => $child['id']])) { + return false; + } } } return true; diff --git a/src/frontend/app/folder/folder-tree.component.html b/src/frontend/app/folder/folder-tree.component.html index b611762dadb..4f85dfb7031 100644 --- a/src/frontend/app/folder/folder-tree.component.html +++ b/src/frontend/app/folder/folder-tree.component.html @@ -55,7 +55,7 @@ <mat-menu #menu="matMenu"> <button mat-menu-item [disabled]="createItemNode || !node.canAdd" (click)="addNewItem(node)">{{lang.addSubFolder}}</button> - <button mat-menu-item (click)="deleteNode(node)" [disabled]="!node.edition">{{lang.delete}}</button> + <button mat-menu-item (click)="deleteNode(node)" [disabled]="!node.canDelete">{{lang.delete}}</button> <button mat-menu-item (click)="openFolderAdmin(node)" [disabled]="!node.edition">{{lang.update}}</button> </mat-menu> @@ -100,7 +100,7 @@ <mat-menu #menu="matMenu"> <button mat-menu-item [disabled]="createItemNode || !node.canAdd" (click)="addNewItem(node)">{{lang.addSubFolder}}</button> - <button mat-menu-item (click)="deleteNode(node)" [disabled]="!node.edition">{{lang.delete}}</button> + <button mat-menu-item (click)="deleteNode(node)" [disabled]="!node.canDelete">{{lang.delete}}</button> <button mat-menu-item (click)="openFolderAdmin(node)" [disabled]="!node.edition">{{lang.update}}</button> </mat-menu> diff --git a/src/frontend/app/folder/folder-tree.component.ts b/src/frontend/app/folder/folder-tree.component.ts index 58071578509..7ac8c68958e 100644 --- a/src/frontend/app/folder/folder-tree.component.ts +++ b/src/frontend/app/folder/folder-tree.component.ts @@ -425,9 +425,9 @@ export class FolderTreeComponent implements OnInit { exhaustMap(() => this.http.get("../../rest/folders/" + node.id)), tap((data: any) => { let canAdmin = false; - + let canDelete = false; let canAdd = true; - + const compare = data.folder.sharing.entities.filter((item: any) => userEntities.indexOf(item) > -1); const entitiesCompare = data.folder.sharing.entities.filter((item: any) => compare.indexOf(item.id)); @@ -436,12 +436,17 @@ export class FolderTreeComponent implements OnInit { if (element.edition === true) { canAdmin = true; } + if (element.canDelete === true) { + canDelete = true; + } }); if (data.folder.user_id !== currentUserId && node.public) { canAdd = false; } + node.edition = (canAdmin || data.folder.user_id === currentUserId) ? true : false; node.canAdd = node.edition; + node.canDelete = canDelete || data.folder.user_id === currentUserId; }), ).subscribe(); } -- GitLab