mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
rename old hasPermission as allowableOperation and introduce the real hasPermissions (#4294)
This commit is contained in:
@@ -17,16 +17,16 @@
|
||||
|
||||
import { ChangeDetectorRef, Component, ElementRef, SimpleChange } from '@angular/core';
|
||||
import { ContentService } from './../services/content.service';
|
||||
import { NodePermissionDirective, NodePermissionSubject } from './node-permission.directive';
|
||||
import { CheckAllowableOperationDirective, NodeAllowableOperationSubject } from './check-allowable-operation.directive';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-text-subject'
|
||||
})
|
||||
class TestComponent implements NodePermissionSubject {
|
||||
class TestComponent implements NodeAllowableOperationSubject {
|
||||
disabled: boolean = false;
|
||||
}
|
||||
|
||||
describe('NodePermissionDirective', () => {
|
||||
describe('CheckAllowableOperationDirective', () => {
|
||||
|
||||
let changeDetectorMock: ChangeDetectorRef;
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('NodePermissionDirective', () => {
|
||||
describe('HTML nativeElement as subject', () => {
|
||||
|
||||
it('updates element once it is loaded', () => {
|
||||
const directive = new NodePermissionDirective(null, null, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'updateElement').and.stub();
|
||||
|
||||
const nodes = [{}, {}];
|
||||
@@ -48,7 +48,7 @@ describe('NodePermissionDirective', () => {
|
||||
});
|
||||
|
||||
it('updates element on nodes change', () => {
|
||||
const directive = new NodePermissionDirective(null, null, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'updateElement').and.stub();
|
||||
|
||||
const nodes = [{}, {}];
|
||||
@@ -59,7 +59,7 @@ describe('NodePermissionDirective', () => {
|
||||
});
|
||||
|
||||
it('updates element only on subsequent change', () => {
|
||||
const directive = new NodePermissionDirective(null, null, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'updateElement').and.stub();
|
||||
|
||||
const nodes = [{}, {}];
|
||||
@@ -72,7 +72,7 @@ describe('NodePermissionDirective', () => {
|
||||
it('enables decorated element', () => {
|
||||
const renderer = jasmine.createSpyObj('renderer', ['removeAttribute']);
|
||||
const elementRef = new ElementRef({});
|
||||
const directive = new NodePermissionDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
|
||||
directive.enableElement();
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('NodePermissionDirective', () => {
|
||||
it('disables decorated element', () => {
|
||||
const renderer = jasmine.createSpyObj('renderer', ['setAttribute']);
|
||||
const elementRef = new ElementRef({});
|
||||
const directive = new NodePermissionDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(elementRef, renderer, null, changeDetectorMock);
|
||||
|
||||
directive.disableElement();
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('NodePermissionDirective', () => {
|
||||
});
|
||||
|
||||
it('disables element when nodes not available', () => {
|
||||
const directive = new NodePermissionDirective(null, null, null, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, null, changeDetectorMock);
|
||||
spyOn(directive, 'disableElement').and.stub();
|
||||
|
||||
directive.nodes = null;
|
||||
@@ -102,9 +102,9 @@ describe('NodePermissionDirective', () => {
|
||||
|
||||
it('enables element when all nodes have expected permission', () => {
|
||||
const contentService = new ContentService(null, null, null, null);
|
||||
spyOn(contentService, 'hasPermission').and.returnValue(true);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||
|
||||
const directive = new NodePermissionDirective(null, null, contentService, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock);
|
||||
spyOn(directive, 'enableElement').and.stub();
|
||||
|
||||
directive.nodes = <any> [{}, {}];
|
||||
@@ -115,9 +115,9 @@ describe('NodePermissionDirective', () => {
|
||||
|
||||
it('disables element when one of the nodes have no permission', () => {
|
||||
const contentService = new ContentService(null, null, null, null);
|
||||
spyOn(contentService, 'hasPermission').and.returnValue(false);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
|
||||
|
||||
const directive = new NodePermissionDirective(null, null, contentService, changeDetectorMock);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock);
|
||||
spyOn(directive, 'disableElement').and.stub();
|
||||
|
||||
directive.nodes = <any> [{}, {}];
|
||||
@@ -131,12 +131,12 @@ describe('NodePermissionDirective', () => {
|
||||
|
||||
it('disables decorated component', () => {
|
||||
const contentService = new ContentService(null, null, null, null);
|
||||
spyOn(contentService, 'hasPermission').and.returnValue(false);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(false);
|
||||
spyOn(changeDetectorMock, 'detectChanges');
|
||||
|
||||
let testComponent = new TestComponent();
|
||||
testComponent.disabled = false;
|
||||
const directive = new NodePermissionDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
directive.nodes = <any> [{}, {}];
|
||||
|
||||
directive.updateElement();
|
||||
@@ -147,12 +147,12 @@ describe('NodePermissionDirective', () => {
|
||||
|
||||
it('enables decorated component', () => {
|
||||
const contentService = new ContentService(null, null, null, null);
|
||||
spyOn(contentService, 'hasPermission').and.returnValue(true);
|
||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||
spyOn(changeDetectorMock, 'detectChanges');
|
||||
|
||||
let testComponent = new TestComponent();
|
||||
testComponent.disabled = true;
|
||||
const directive = new NodePermissionDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
const directive = new CheckAllowableOperationDirective(null, null, contentService, changeDetectorMock, testComponent);
|
||||
directive.nodes = <any> [{}, {}];
|
||||
|
||||
directive.updateElement();
|
@@ -22,19 +22,19 @@ import { NodeEntry } from '@alfresco/js-api';
|
||||
import { ContentService } from './../services/content.service';
|
||||
import { EXTENDIBLE_COMPONENT } from './../interface/injection.tokens';
|
||||
|
||||
export interface NodePermissionSubject {
|
||||
export interface NodeAllowableOperationSubject {
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[adf-node-permission]'
|
||||
selector: '[adf-check-allowable-operation]'
|
||||
})
|
||||
export class NodePermissionDirective implements OnChanges {
|
||||
export class CheckAllowableOperationDirective implements OnChanges {
|
||||
|
||||
/** Node permission to check (create, delete, update, updatePermissions,
|
||||
* !create, !delete, !update, !updatePermissions).
|
||||
*/
|
||||
@Input('adf-node-permission')
|
||||
@Input('adf-check-allowable-operation')
|
||||
permission: string = null;
|
||||
|
||||
/** Nodes to check permission for. */
|
||||
@@ -48,7 +48,7 @@ export class NodePermissionDirective implements OnChanges {
|
||||
|
||||
@Host()
|
||||
@Optional()
|
||||
@Inject(EXTENDIBLE_COMPONENT) private parentComponent?: NodePermissionSubject) {
|
||||
@Inject(EXTENDIBLE_COMPONENT) private parentComponent?: NodeAllowableOperationSubject) {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
@@ -60,10 +60,10 @@ export class NodePermissionDirective implements OnChanges {
|
||||
/**
|
||||
* Updates disabled state for the decorated element
|
||||
*
|
||||
* @memberof NodePermissionDirective
|
||||
* @memberof CheckAllowableOperationDirective
|
||||
*/
|
||||
updateElement(): boolean {
|
||||
let enable = this.hasPermission(this.nodes, this.permission);
|
||||
let enable = this.hasAllowableOperations(this.nodes, this.permission);
|
||||
|
||||
if (enable) {
|
||||
this.enable();
|
||||
@@ -95,7 +95,7 @@ export class NodePermissionDirective implements OnChanges {
|
||||
/**
|
||||
* Enables decorated element
|
||||
*
|
||||
* @memberof NodePermissionDirective
|
||||
* @memberof CheckAllowableOperationDirective
|
||||
*/
|
||||
enableElement(): void {
|
||||
this.renderer.removeAttribute(this.elementRef.nativeElement, 'disabled');
|
||||
@@ -104,7 +104,7 @@ export class NodePermissionDirective implements OnChanges {
|
||||
/**
|
||||
* Disables decorated element
|
||||
*
|
||||
* @memberof NodePermissionDirective
|
||||
* @memberof CheckAllowableOperationDirective
|
||||
*/
|
||||
disableElement(): void {
|
||||
this.renderer.setAttribute(this.elementRef.nativeElement, 'disabled', 'true');
|
||||
@@ -115,11 +115,11 @@ export class NodePermissionDirective implements OnChanges {
|
||||
*
|
||||
* @param nodes Node collection to check
|
||||
* @param permission Permission to check for each node
|
||||
* @memberof NodePermissionDirective
|
||||
* @memberof CheckAllowableOperationDirective
|
||||
*/
|
||||
hasPermission(nodes: NodeEntry[], permission: string): boolean {
|
||||
hasAllowableOperations(nodes: NodeEntry[], permission: string): boolean {
|
||||
if (nodes && nodes.length > 0) {
|
||||
return nodes.every((node) => this.contentService.hasPermission(node.entry, permission));
|
||||
return nodes.every((node) => this.contentService.hasAllowableOperations(node.entry, permission));
|
||||
}
|
||||
|
||||
return false;
|
@@ -23,7 +23,7 @@ import { HighlightDirective } from './highlight.directive';
|
||||
import { LogoutDirective } from './logout.directive';
|
||||
import { NodeDeleteDirective } from './node-delete.directive';
|
||||
import { NodeFavoriteDirective } from './node-favorite.directive';
|
||||
import { NodePermissionDirective } from './node-permission.directive';
|
||||
import { CheckAllowableOperationDirective } from './check-allowable-operation.directive';
|
||||
import { NodeRestoreDirective } from './node-restore.directive';
|
||||
import { UploadDirective } from './upload.directive';
|
||||
import { NodeDownloadDirective } from './node-download.directive';
|
||||
@@ -38,7 +38,7 @@ import { NodeDownloadDirective } from './node-download.directive';
|
||||
LogoutDirective,
|
||||
NodeDeleteDirective,
|
||||
NodeFavoriteDirective,
|
||||
NodePermissionDirective,
|
||||
CheckAllowableOperationDirective,
|
||||
NodeRestoreDirective,
|
||||
NodeDownloadDirective,
|
||||
UploadDirective
|
||||
@@ -48,7 +48,7 @@ import { NodeDownloadDirective } from './node-download.directive';
|
||||
LogoutDirective,
|
||||
NodeDeleteDirective,
|
||||
NodeFavoriteDirective,
|
||||
NodePermissionDirective,
|
||||
CheckAllowableOperationDirective,
|
||||
NodeRestoreDirective,
|
||||
NodeDownloadDirective,
|
||||
UploadDirective
|
||||
|
@@ -44,7 +44,7 @@ class TestComponent {
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
<div id="delete-component" [adf-node-permission]="selection"
|
||||
<div id="delete-component" [adf-check-allowable-operation]="selection"
|
||||
[adf-delete]="selection"
|
||||
(delete)="onDelete($event)">
|
||||
</div>`
|
||||
@@ -335,7 +335,7 @@ describe('NodeDeleteDirective', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not enable the button if adf-node-permission is present', (done) => {
|
||||
it('should not enable the button if adf-check-allowable-operation is present', (done) => {
|
||||
elementWithPermissions.nativeElement.disabled = false;
|
||||
componentWithPermissions.selection = [];
|
||||
|
||||
|
@@ -76,7 +76,7 @@ export class NodeDeleteDirective implements OnChanges {
|
||||
if (!this.selection || (this.selection && this.selection.length === 0)) {
|
||||
this.setDisableAttribute(true);
|
||||
} else {
|
||||
if (!this.elementRef.nativeElement.hasAttribute('adf-node-permission')) {
|
||||
if (!this.elementRef.nativeElement.hasAttribute('adf-check-allowable-operation')) {
|
||||
this.setDisableAttribute(false);
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ export * from './highlight.directive';
|
||||
export * from './logout.directive';
|
||||
export * from './node-delete.directive';
|
||||
export * from './node-favorite.directive';
|
||||
export * from './node-permission.directive';
|
||||
export * from './check-allowable-operation.directive';
|
||||
export * from './node-restore.directive';
|
||||
export * from './node-download.directive';
|
||||
export * from './upload.directive';
|
||||
|
Reference in New Issue
Block a user