mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
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:
committed by
Mario Romano
parent
ab3d18e5c1
commit
f6102dfc07
@@ -101,6 +101,62 @@ describe('DocumentActionsService', () => {
|
||||
expect(service.getHandler('delete')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should not delete the file node if there are no permissions', (done) => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
service.permissionEvent.subscribe((permission) => {
|
||||
expect(permission).toBeDefined();
|
||||
expect(permission.type).toEqual('content');
|
||||
expect(permission.action).toEqual('delete');
|
||||
done();
|
||||
});
|
||||
|
||||
let file = new FileNode();
|
||||
service.getHandler('delete')(file);
|
||||
|
||||
});
|
||||
|
||||
it('should delete the file node if there is the delete permission', () => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = [permission];
|
||||
service.getHandler('delete')(fileWithPermission, null, permission);
|
||||
|
||||
expect(documentListService.deleteNode).toHaveBeenCalledWith(file.entry.id);
|
||||
});
|
||||
|
||||
it('should not delete the file node if there is no delete permission', (done) => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
service.permissionEvent.subscribe((permission) => {
|
||||
expect(permission).toBeDefined();
|
||||
expect(permission.type).toEqual('content');
|
||||
expect(permission.action).toEqual('delete');
|
||||
done();
|
||||
});
|
||||
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = ['create', 'update'];
|
||||
service.getHandler('delete')(fileWithPermission, null, permission);
|
||||
});
|
||||
|
||||
it('should delete the file node if there is the delete and others permission ', () => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = ['create', 'update', permission];
|
||||
service.getHandler('delete')(fileWithPermission, null, permission);
|
||||
|
||||
expect(documentListService.deleteNode).toHaveBeenCalledWith(file.entry.id);
|
||||
});
|
||||
|
||||
it('should register download action', () => {
|
||||
expect(service.getHandler('download')).toBeDefined();
|
||||
});
|
||||
@@ -152,8 +208,11 @@ describe('DocumentActionsService', () => {
|
||||
it('should delete file node', () => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
service.getHandler('delete')(file);
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = [permission];
|
||||
service.getHandler('delete')(fileWithPermission, null, permission);
|
||||
|
||||
expect(documentListService.deleteNode).toHaveBeenCalledWith(file.entry.id);
|
||||
});
|
||||
@@ -165,8 +224,11 @@ describe('DocumentActionsService', () => {
|
||||
service.getHandler('delete')(folder);
|
||||
expect(documentListService.deleteNode).not.toHaveBeenCalled();
|
||||
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
service.getHandler('delete')(file);
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = [permission];
|
||||
service.getHandler('delete')(fileWithPermission, null, permission);
|
||||
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -184,8 +246,11 @@ describe('DocumentActionsService', () => {
|
||||
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||
|
||||
let target = jasmine.createSpyObj('obj', ['reload']);
|
||||
let permission = 'delete';
|
||||
let file = new FileNode();
|
||||
service.getHandler('delete')(file, target);
|
||||
let fileWithPermission: any = file;
|
||||
fileWithPermission.entry.allowableOperations = [permission];
|
||||
service.getHandler('delete')(fileWithPermission, target, permission);
|
||||
|
||||
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||
expect(target.reload).toHaveBeenCalled();
|
||||
|
Reference in New Issue
Block a user