DocumentList - Check permissions on delete folder/file (#1808)

* Add check permission on delete folder/file

* Provide a way to disable the action when if there is no permission

* Improve the code using the external permission inside the folder/document action service

* Add basic documentation.
 - How disable the button when the permission is missing
 - How to show a notification message when the permission is missing

* Resize the image

* Change the value to true for demo purpose

* Update folder-actions.service.ts

* Update document-actions.service.ts
This commit is contained in:
Maurizio Vitale
2017-04-11 13:43:33 +01:00
committed by Mario Romano
parent ab3d18e5c1
commit f6102dfc07
20 changed files with 460 additions and 32 deletions

View File

@@ -19,9 +19,14 @@ import { Injectable } from '@angular/core';
import { ContentActionHandler } from '../models/content-action.model';
import { DocumentListService } from './document-list.service';
import { AlfrescoContentService } from 'ng2-alfresco-core';
import { PermissionModel } from '../models/permissions.model';
import { Subject } from 'rxjs/Rx';
@Injectable()
export class DocumentActionsService {
permissionEvent: Subject<PermissionModel> = new Subject<PermissionModel>();
private handlers: { [id: string]: ContentActionHandler; } = {};
constructor(private documentListService?: DocumentListService,
@@ -82,13 +87,28 @@ export class DocumentActionsService {
return false;
}
private deleteNode(obj: any, target?: any) {
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
this.documentListService.deleteNode(obj.entry.id).subscribe(() => {
if (target && typeof target.reload === 'function') {
target.reload();
}
});
private deleteNode(obj: any, target?: any, permission?: string) {
if (this.canExecuteAction(obj)) {
if (this.hasPermission(obj.entry, permission)) {
this.documentListService.deleteNode(obj.entry.id).subscribe(() => {
if (target && typeof target.reload === 'function') {
target.reload();
}
});
} else {
this.permissionEvent.next(new PermissionModel({type: 'content', action: 'delete', permission: permission}));
}
}
}
private hasPermission(node: any, permission: string): boolean {
if (this.hasPermissions(node)) {
return node.allowableOperations.find(permision => permision === permission) ? true : false;
}
return false;
}
private hasPermissions(node: any): boolean {
return node && node.allowableOperations ? true : false;
}
}