update permission (#279)

This commit is contained in:
Cilibiu Bogdan
2018-04-05 12:16:25 +03:00
committed by Denys Vuika
parent d65116fef8
commit fbaa07be11
5 changed files with 11 additions and 105 deletions

View File

@@ -299,54 +299,6 @@ describe('PageComponent', () => {
});
});
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);
});
});
describe('canUpdate()', () => {
it('should return true if node can be edited', () => {
const selection = [ { entry: {
@@ -364,22 +316,4 @@ describe('PageComponent', () => {
expect(component.canUpdate(selection)).toBe(false);
});
});
describe('canUpdateShared()', () => {
it('should return true if shared node can be edited', () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['update']
} } ];
expect(component.canUpdateShared(selection)).toBe(true);
});
it(`should return false if shared node cannot be edited`, () => {
const selection = [ { entry: {
allowableOperationsOnTarget: ['other-permission']
} } ];
expect(component.canUpdateShared(selection)).toBe(false);
});
});
});

View File

@@ -112,26 +112,14 @@ 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'));
}
canUpdate(selection: Array<MinimalNodeEntity> = []): boolean {
return selection.every(node => node.entry && this.nodeHasPermission(node.entry, 'update'));
}
canUpdateShared(selection: Array<MinimalNodeEntity> = []): boolean {
return selection.every(node => node.entry && this.nodeSharedHasPermission(node.entry, 'update'));
}
canPreviewFile(selection: Array<MinimalNodeEntity>): boolean {
return this.isFileSelected(selection);
}
@@ -148,18 +136,10 @@ export abstract class PageComponent {
return this.isFileSelected(selection) && this.nodeHasPermission(selection[0].entry, 'update');
}
canUpdateFileShared(selection: Array<MinimalNodeEntity>): boolean {
return this.isFileSelected(selection) && this.nodeSharedHasPermission(selection[0].entry, 'update');
}
canManageVersions(selection: Array<MinimalNodeEntity>): boolean {
return this.canUpdateFile(selection);
}
canManageVersionsOfShared(selection: Array<MinimalNodeEntity>): boolean {
return this.canUpdateFileShared(selection);
}
nodeHasPermission(node: MinimalNodeEntryEntity, permission: string): boolean {
if (node && permission) {
const { allowableOperations = [] } = <any>(node || {});
@@ -172,18 +152,6 @@ 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

@@ -64,7 +64,7 @@
<button
mat-menu-item
*ngIf="canMoveShared(documentList.selection)"
*ngIf="permission.check(documentList.selection, ['delete'])"
[app-move-node]="documentList.selection">
<mat-icon color="primary">library_books</mat-icon>
<span>{{ 'APP.ACTIONS.MOVE' | translate }}</span>
@@ -72,7 +72,7 @@
<button
mat-menu-item
*ngIf="canDelete(documentList.selection)"
*ngIf="permission.check(documentList.selection, ['delete'])"
[appUnshareNode]="documentList.selection"
(links-unshared)="refresh()">
<mat-icon color="primary">stop_screen_share</mat-icon>
@@ -81,7 +81,7 @@
<button
mat-menu-item
*ngIf="canDeleteShared(documentList.selection)"
*ngIf="permission.check(documentList.selection, ['delete'])"
[app-delete-node]="documentList.selection">
<mat-icon color="primary">delete</mat-icon>
<span>{{ 'APP.ACTIONS.DELETE' | translate }}</span>
@@ -89,7 +89,7 @@
<button
mat-menu-item
*ngIf="canManageVersionsOfShared(documentList.selection)"
*ngIf="permission.check(documentList.selection[0], ['update'])"
[app-node-versions]="documentList.selection">
<mat-icon color="primary">storage</mat-icon>
<span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span>
@@ -195,8 +195,8 @@
</div>
<adf-content-metadata-card
[readOnly]="!canUpdateShared(documentList.selection)"
[displayEmpty]="canUpdateShared(documentList.selection)"
[readOnly]="!permission.check(documentList.selection, ['update'])"
[displayEmpty]="permission.check(documentList.selection, ['update'])"
[preset]="'custom'"
[node]="infoInstance.node">
</adf-content-metadata-card>
@@ -204,7 +204,7 @@
<adf-info-drawer-tab label="Versions">
<ng-container *ngIf="isFileSelected(documentList.selection);else choose_document_template">
<ng-container *ngIf="canManageVersionsOfShared(documentList.selection); else no_permission_to_versions">
<ng-container *ngIf="permission.check(documentList.selection[0], ['update']); else no_permission_to_versions">
<adf-version-manager *ngIf="infoInstance.node"
[node]="infoInstance.node">
</adf-version-manager>

View File

@@ -42,6 +42,7 @@ import { MatMenuModule, MatSnackBarModule, MatIconModule } from '@angular/materi
import { DocumentListService } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { NodeInfoDirective } from '../../common/directives/node-info.directive';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { SharedFilesComponent } from './shared-files.component';
@@ -96,6 +97,7 @@ describe('SharedFilesComponent', () => {
LogService,
NotificationService,
ContentManagementService,
NodePermissionService,
ContentService,
NodesApiService,
DocumentListService,

View File

@@ -31,6 +31,7 @@ import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { PageComponent } from '../page.component';
@Component({
@@ -49,6 +50,7 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes
private route: ActivatedRoute,
private content: ContentManagementService,
private apiService: AlfrescoApiService,
public permission: NodePermissionService,
preferences: UserPreferencesService) {
super(preferences);