shared nodes actions permission (#224)

This commit is contained in:
Cilibiu Bogdan 2018-03-06 18:17:06 +02:00 committed by Denys Vuika
parent a401b3d90a
commit a9d98fbe83
3 changed files with 71 additions and 3 deletions

View File

@ -298,4 +298,52 @@ describe('PageComponent', () => {
expect(component.nodeHasPermission(node, 'some-operation')).toBe(false);
});
});
describe('canDeleteShared()', () => {
it('should return true if shared node can be deleted', () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['delete']
} } ];
expect(component.canDeleteShared(selection)).toBe(true);
});
it(`should return false if shared node doesn't have permission`, () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['something']
} } ];
expect(component.canDeleteShared(selection)).toBe(false);
});
it(`should return false if shared node doesn't have permissions property`, () => {
const selection = [ { entry: { } } ];
expect(component.canDeleteShared(selection)).toBe(false);
});
});
describe('canMoveShared()', () => {
it('should return true if shared node can be moved', () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['delete']
} } ];
expect(component.canMoveShared(selection)).toBe(true);
});
it(`should return false if shared node doesn't have permission`, () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['something']
} } ];
expect(component.canMoveShared(selection)).toBe(false);
});
it(`should return false if shared node doesn't have permissions property`, () => {
const selection = [ { entry: { } } ];
expect(component.canMoveShared(selection)).toBe(false);
});
});
});

View File

@ -111,10 +111,18 @@ export abstract class PageComponent {
return selection.every(node => node.entry && this.nodeHasPermission(node.entry, 'delete'));
}
canDeleteShared(selection: Array<MinimalNodeEntity> = []): boolean {
return selection.every(node => node.entry && this.nodeSharedHasPermission(node.entry, 'delete'));
}
canMove(selection: Array<MinimalNodeEntity>): boolean {
return this.canDelete(selection);
}
canMoveShared(selection: Array<MinimalNodeEntity> = []): boolean {
return selection.every(node => node.entry && this.nodeSharedHasPermission(node.entry, 'delete'));
}
canPreviewFile(selection: Array<MinimalNodeEntity>): boolean {
return this.isFileSelected(selection);
}
@ -127,7 +135,7 @@ export abstract class PageComponent {
return this.isFileSelected(selection);
}
nodeHasPermission(node: MinimalNodeEntryEntity, permission: string) {
nodeHasPermission(node: MinimalNodeEntryEntity, permission: string): boolean {
if (node && permission) {
const { allowableOperations = [] } = <any>(node || {});
@ -139,6 +147,18 @@ export abstract class PageComponent {
return false;
}
nodeSharedHasPermission(node: MinimalNodeEntryEntity, permission: string): boolean {
if (node && permission) {
const { allowableOperationsOnTarget } = <any>(node || {});
if (allowableOperationsOnTarget && allowableOperationsOnTarget.indexOf(permission) > -1) {
return true;
}
}
return false;
}
onChangePageSize(event: Pagination): void {
this.preferences.paginationSize = event.maxItems;
}

View File

@ -50,7 +50,7 @@
<button
mat-menu-item
*ngIf="canMove(documentList.selection)"
*ngIf="canMoveShared(documentList.selection)"
[app-move-node]="documentList.selection">
<mat-icon>library_books</mat-icon>
<span>{{ 'APP.ACTIONS.MOVE' | translate }}</span>
@ -67,7 +67,7 @@
<button
mat-menu-item
*ngIf="canDelete(documentList.selection)"
*ngIf="canDeleteShared(documentList.selection)"
[app-delete-node]="documentList.selection">
<mat-icon>delete</mat-icon>
<span>{{ 'APP.ACTIONS.DELETE' | translate }}</span>