[ADF-2432] created directive for add/remove inherited permissions (#3111)

* [ADF-2432] permission display component - phase 1

* [ADF-2432] display permission table for node - phase 2

* [ADF-2432] fixed layout for display permissions

* [ADF-2432] added test and documentation for permission display

* [ADF-2432] fixed wrong rebase changes

* [ADF-2432] created directive for add/remove inherited permissions

* [ADF-2432] renamed folder and added inheriting directive

* [ADF-2432] removed old documentation

* [ADF-2432] added async to tests
This commit is contained in:
Vito
2018-03-22 14:56:32 +00:00
committed by Eugenio Romano
parent 2084748993
commit 10d437b30b
15 changed files with 272 additions and 8 deletions

View File

@@ -0,0 +1,41 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component } from '@angular/core';
@Component({
template: `
<button id="sample-button-permission" adf-inherit-permission [nodeId]="nodeId"
(updated)="onUpdate($event)"> PERMISSION </button>
<span id="update-notification" *ngIf="updatedNode"> NODE UPDATED </span>
`
})
export class SimpleInheritedPermissionTestComponent {
message: string = '';
nodeId: string = 'fake-node-id';
updatedNode: boolean = false;
constructor() {
}
onUpdate(node: any) {
this.updatedNode = node.permissions.isInheritanceEnabled;
}
}

View File

@@ -0,0 +1,102 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SimpleInheritedPermissionTestComponent } from '../../mock/inherited-permission.component.mock';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PermissionManagerModule } from '../../index';
import { NodesApiService } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
const fakeNodeWithInherit: any = { id: 'fake-id', permissions : {isInheritanceEnabled : true}};
const fakeNodeNoInherit: any = { id: 'fake-id', permissions : {isInheritanceEnabled : false}};
describe('InheritPermissionDirective', () => {
let fixture: ComponentFixture<SimpleInheritedPermissionTestComponent>;
let element: HTMLElement;
let component: SimpleInheritedPermissionTestComponent;
let nodeService: NodesApiService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
PermissionManagerModule
],
declarations: [
SimpleInheritedPermissionTestComponent
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(SimpleInheritedPermissionTestComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
nodeService = TestBed.get(NodesApiService);
});
}));
afterEach(async(() => {
fixture.destroy();
TestBed.resetTestingModule();
}));
it('should be able to render the simple component', async(() => {
fixture.detectChanges();
expect(element.querySelector('#sample-button-permission')).not.toBeNull();
expect(element.querySelector('#update-notification')).toBeNull();
}));
it('should be able to add inherited permission', async(() => {
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeNoInherit));
spyOn(nodeService, 'updateNode').and.callFake((nodeId, nodeBody) => {
if (nodeBody.permissions.isInheritanceEnabled) {
return Observable.of(fakeNodeWithInherit);
} else {
return Observable.of(fakeNodeNoInherit);
}
});
fixture.detectChanges();
const buttonPermission: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#sample-button-permission');
expect(buttonPermission).not.toBeNull();
expect(element.querySelector('#update-notification')).toBeNull();
buttonPermission.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#update-notification')).not.toBeNull();
});
}));
it('should be able to remove inherited permission', async(() => {
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithInherit));
spyOn(nodeService, 'updateNode').and.callFake((nodeId, nodeBody) => {
if (nodeBody.permissions.isInheritanceEnabled) {
return Observable.of(fakeNodeWithInherit);
} else {
return Observable.of(fakeNodeNoInherit);
}
});
component.updatedNode = true;
fixture.detectChanges();
const buttonPermission: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#sample-button-permission');
expect(buttonPermission).not.toBeNull();
expect(element.querySelector('#update-notification')).not.toBeNull();
buttonPermission.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#update-notification')).toBeNull();
});
}));
});

View File

@@ -0,0 +1,50 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* tslint:disable:no-input-rename */
import { Directive, Input, Output, EventEmitter } from '@angular/core';
import { NodesApiService } from '@alfresco/adf-core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@Directive({
selector: 'button[adf-inherit-permission], mat-button-toggle[adf-inherit-permission]',
host: {
'role': 'button',
'(click)': 'onInheritPermissionClicked()'
}
})
export class InheritPermissionDirective {
@Input()
nodeId: string;
@Output()
updated: EventEmitter<MinimalNodeEntryEntity> = new EventEmitter<MinimalNodeEntryEntity>();
constructor(private nodeService: NodesApiService) {
}
onInheritPermissionClicked() {
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
const nodeBody = { permissions : {isInheritanceEnabled : !node.permissions.isInheritanceEnabled} };
this.nodeService.updateNode(this.nodeId, nodeBody).subscribe((nodeUpdated: MinimalNodeEntryEntity) => {
this.updated.emit(nodeUpdated);
});
});
}
}

View File

@@ -38,6 +38,14 @@ export class PermissionListComponent implements OnInit {
}
ngOnInit() {
this.fetchNodePermissions();
}
reload() {
this.fetchNodePermissions();
}
private fetchNodePermissions() {
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
this.permissionList = this.getPermissionList(node);
});

View File

@@ -20,8 +20,9 @@ import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { MaterialModule } from '../material.module';
import { PermissionListComponent } from './components/permission-display/permission-list.component';
import { PermissionListComponent } from './components/permission-list/permission-list.component';
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
import { InheritPermissionDirective } from './components/inherited-button.directive';
@NgModule({
imports: [
@@ -34,10 +35,12 @@ import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
DataColumnModule
],
declarations: [
PermissionListComponent
PermissionListComponent,
InheritPermissionDirective
],
exports: [
PermissionListComponent
PermissionListComponent,
InheritPermissionDirective
]
})
export class PermissionManagerModule {}

View File

@@ -15,6 +15,7 @@
* limitations under the License.
*/
export * from './components/permission-display/permission-list.component';
export * from './components/permission-list/permission-list.component';
export * from './components/inherited-button.directive';
export * from './models/permission.model';

View File

@@ -14,7 +14,7 @@
@import '../content-node-selector/content-node-selector.component';
@import '../content-metadata/content-metadata.module';
@import '../permission-manager/components/permission-display/permission-list.component';
@import '../permission-manager/components/permission-list/permission-list.component';
@mixin adf-content-services-theme($theme) {
@include adf-breadcrumb-theme($theme);