[ADF-2432] Creating component to display node permission (#3106)

* [ADF-2432] start adding demo shell changes for permissions

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

* [ADF-2432] added permissions to node query|

* [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] added peer review changes

* [ADF-2432] added license header to mock file
This commit is contained in:
Vito
2018-03-21 22:02:40 +00:00
committed by Eugenio Romano
parent ae8b7419a0
commit 99e694ef98
26 changed files with 602 additions and 8 deletions

View File

@@ -0,0 +1,28 @@
<div id="adf-permission-display-container" class="adf-display-permission-container">
<adf-datatable [rows]="permissionList" class="adf-datatable-permission">
<data-columns>
<data-column key="icon" type="icon" [sortable]="false">
</data-column>
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.AUTHORITY_ID' | translate}}" key="authorityId"></data-column>
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.NAME' | translate}}" key="name"></data-column>
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.INHERITED' | translate}}" key="isInherited">
<ng-template let-entry="$implicit">
<mat-chip-list>
<mat-chip *ngIf="!!entry.data.getValue(entry.row, entry.col) else locally_set_chip"
id="adf-permission-inherited-label"
color="primary" selected="true">{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.INHERITED' | translate}}</mat-chip>
</mat-chip-list>
<ng-template #locally_set_chip>
<mat-chip-list>
<mat-chip id="adf-permission-locallyset-label"
color="accent" selected="true">
{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.LOCALLY_SET' | translate}}
</mat-chip>
</mat-chip-list>
</ng-template>
</ng-template>
</data-column>
</data-columns>
</adf-datatable>
</div>

View File

@@ -0,0 +1,15 @@
@mixin adf-permission-list-theme($theme) {
.adf{
&-display-permission-container {
display: flex;
justify-content: space-around;
}
&-datatable-permission {
display: flex;
flex-basis: 38%;
}
}
}

View File

@@ -0,0 +1,81 @@
/*!
* @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 { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PermissionListComponent } from './permission-list.component';
import { NodesApiService } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
import { fakeNodeWithPermissions, fakeNodeInheritedOnly, fakeNodeWithOnlyLocally} from '../../../mock/permission-list.component.mock';
describe('PermissionDisplayComponent', () => {
let fixture: ComponentFixture<PermissionListComponent>;
let component: PermissionListComponent;
let element: HTMLElement;
let nodeService: NodesApiService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
PermissionListComponent
],
providers: [NodesApiService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(PermissionListComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
nodeService = TestBed.get(NodesApiService);
});
}));
afterEach(async(() => {
fixture.destroy();
TestBed.resetTestingModule();
}));
it('should be able to render the component', async() => {
fixture.detectChanges();
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
});
it('should show the node permissions', async() => {
component.nodeId = 'fake-node-id';
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithPermissions));
fixture.detectChanges();
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
expect(element.querySelectorAll('.adf-datatable-row').length).toBe(4);
});
it('should show inherited label for inherited permissions', async() => {
component.nodeId = 'fake-node-id';
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeInheritedOnly));
fixture.detectChanges();
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
expect(element.querySelector('#adf-permission-inherited-label')).toBeDefined();
expect(element.querySelector('#adf-permission-inherited-label')).not.toBeNull();
});
it('should show locally set label for locally set permissions', async() => {
component.nodeId = 'fake-node-id';
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
fixture.detectChanges();
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
expect(element.querySelector('#adf-permission-locallyset-label')).toBeDefined();
expect(element.querySelector('#adf-permission-locallyset-label')).not.toBeNull();
});
});

View File

@@ -0,0 +1,64 @@
/*!
* @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, ViewEncapsulation, Input, OnInit } from '@angular/core';
import { NodesApiService } from '@alfresco/adf-core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { PermissionDisplayModel } from '../../models/permission.model';
@Component({
selector: 'adf-permission-list',
templateUrl: './permission-list.component.html',
styleUrls: ['./permission-list.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class PermissionListComponent implements OnInit {
@Input()
nodeId: string = '';
permissionList: PermissionDisplayModel[];
constructor(private nodeService: NodesApiService) {
}
ngOnInit() {
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
this.permissionList = this.getPermissionList(node);
});
}
private getPermissionList(node: MinimalNodeEntryEntity): PermissionDisplayModel[] {
let allPermissions: PermissionDisplayModel[] = [];
if (node.permissions.locallySet) {
node.permissions.locallySet.map((element) => {
let permission = new PermissionDisplayModel(element);
allPermissions.push(permission);
});
}
if (node.permissions.inherited) {
node.permissions.inherited.map((element) => {
let permissionInherited = new PermissionDisplayModel(element);
permissionInherited.isInherited = true;
allPermissions.push(permissionInherited);
});
}
return allPermissions;
}
}