mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2553] added select box and updating role (#3148)
* [ADF-2553] start adding dropdown * [ADF-2553] added select box and updating role * [ADF-2553] added some fixes * [ADF-2554] added test for component phase 1 * [ADF-2553] fixed error and added tests * [ADF-2553] added documentation and improved api call
This commit is contained in:
38
docs/content-services/node-permission.service.md
Normal file
38
docs/content-services/node-permission.service.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
Added: v2.0.0
|
||||||
|
Status: Active
|
||||||
|
---
|
||||||
|
# Node Permission service
|
||||||
|
|
||||||
|
Manages the role permissions for the content nodes
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
- `getNodeRoles(node: MinimalNodeEntryEntity): Observable<string[]>`
|
||||||
|
Gets a list of roles for the current node.
|
||||||
|
- `node` - the target node
|
||||||
|
- `updatePermissionRoles(node: MinimalNodeEntryEntity, updatedPermissionRole: PermissionElement): Observable<MinimalNodeEntryEntity>`
|
||||||
|
Update the given permission for the related node
|
||||||
|
- `node` - the target node
|
||||||
|
- `updatedPermissionRole` the permission role to update/add
|
||||||
|
|
||||||
|
- `getGroupMemeberByGroupName(groupName: string, opts?: any): Observable<GroupMemberPaging>`
|
||||||
|
Perform a call to the groups api to retrieve all the members related to that group name.
|
||||||
|
- `groupName` the members group name
|
||||||
|
- `opts` additional parameters to perform the call
|
||||||
|
|
||||||
|
|
||||||
|
## Details
|
||||||
|
|
||||||
|
Content Services supports
|
||||||
|
This service needs the support for the groups api fo content services that is available from version 5.2.1
|
||||||
|
|
||||||
|
See the
|
||||||
|
[Groups API](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/GroupssApi.md)
|
||||||
|
in the Alfresco JS API for more information about the types returned by Tag
|
||||||
|
service methods and for the implementation of the REST API the service is
|
||||||
|
based on.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [Permission list component](permission-list.component.md)
|
@@ -23,7 +23,15 @@ Shows node permissions as a table.
|
|||||||
| ---- | ---- | ------------- | ----------- |
|
| ---- | ---- | ------------- | ----------- |
|
||||||
| nodeId | `string` | `null` | ID of the node whose permissions you want to show. |
|
| nodeId | `string` | `null` | ID of the node whose permissions you want to show. |
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---- | ---- | ----------- |
|
||||||
|
| update | `PermissionElement` | Emitted when the permission is updated. |
|
||||||
|
|
||||||
## Details
|
## Details
|
||||||
|
|
||||||
This component uses a [Datatable component](../core/datatable.component.md) to show the
|
This component uses a [Datatable component](../core/datatable.component.md) to show the
|
||||||
permissions retrieved from the [Node service](../core/node.service.md).
|
permissions retrieved from the [Node service](../core/node.service.md).
|
||||||
|
For the locallyset permissions a role dropdown will be showed allowing the user to change it.
|
||||||
|
When user select a new value, the permission role is automatically updated and the `update` event is thrown.
|
@@ -234,7 +234,7 @@
|
|||||||
"PERMISSION_DISPLAY": {
|
"PERMISSION_DISPLAY": {
|
||||||
"INHERITED" : "Inherited",
|
"INHERITED" : "Inherited",
|
||||||
"AUTHORITY_ID" : "Authority ID",
|
"AUTHORITY_ID" : "Authority ID",
|
||||||
"NAME": "Name",
|
"ROLE": "Role",
|
||||||
"LOCALLY_SET" : "Locally set"
|
"LOCALLY_SET" : "Locally set"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,28 @@ export const fakeNodeWithPermissions: any = {
|
|||||||
'app:uifacets'
|
'app:uifacets'
|
||||||
],
|
],
|
||||||
'createdAt': '2017-11-16T16:29:38.638+0000',
|
'createdAt': '2017-11-16T16:29:38.638+0000',
|
||||||
|
'path': {
|
||||||
|
'name': '/Company Home/Sites/testsite/documentLibrary',
|
||||||
|
'isComplete': true,
|
||||||
|
'elements': [
|
||||||
|
{
|
||||||
|
'id': '2be275a1-b00d-4e45-83d8-66af43ac2252',
|
||||||
|
'name': 'Company Home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '1be10a97-6eb9-4b60-b6c6-1673900e9631',
|
||||||
|
'name': 'Sites'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
|
||||||
|
'name': 'testsite'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '71626fae-0c04-4d0c-a129-20fa4c178716',
|
||||||
|
'name': 'documentLibrary'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
'isFolder': true,
|
'isFolder': true,
|
||||||
'isFile': false,
|
'isFile': false,
|
||||||
'createdByUser': {
|
'createdByUser': {
|
||||||
@@ -87,6 +109,28 @@ export const fakeNodeInheritedOnly: any = {
|
|||||||
'app:uifacets'
|
'app:uifacets'
|
||||||
],
|
],
|
||||||
'createdAt': '2017-11-16T16:29:38.638+0000',
|
'createdAt': '2017-11-16T16:29:38.638+0000',
|
||||||
|
'path': {
|
||||||
|
'name': '/Company Home/Sites/testsite/documentLibrary',
|
||||||
|
'isComplete': true,
|
||||||
|
'elements': [
|
||||||
|
{
|
||||||
|
'id': '2be275a1-b00d-4e45-83d8-66af43ac2252',
|
||||||
|
'name': 'Company Home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '1be10a97-6eb9-4b60-b6c6-1673900e9631',
|
||||||
|
'name': 'Sites'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
|
||||||
|
'name': 'testsite'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '71626fae-0c04-4d0c-a129-20fa4c178716',
|
||||||
|
'name': 'documentLibrary'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
'isFolder': true,
|
'isFolder': true,
|
||||||
'isFile': false,
|
'isFile': false,
|
||||||
'createdByUser': {
|
'createdByUser': {
|
||||||
@@ -133,6 +177,7 @@ export const fakeNodeInheritedOnly: any = {
|
|||||||
'app:icon': 'space-icon-default'
|
'app:icon': 'space-icon-default'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fakeNodeWithOnlyLocally: any = {
|
export const fakeNodeWithOnlyLocally: any = {
|
||||||
'aspectNames': [
|
'aspectNames': [
|
||||||
'cm:auditable',
|
'cm:auditable',
|
||||||
@@ -142,6 +187,28 @@ export const fakeNodeWithOnlyLocally: any = {
|
|||||||
'app:uifacets'
|
'app:uifacets'
|
||||||
],
|
],
|
||||||
'createdAt': '2017-11-16T16:29:38.638+0000',
|
'createdAt': '2017-11-16T16:29:38.638+0000',
|
||||||
|
'path': {
|
||||||
|
'name': '/Company Home/Sites/testsite/documentLibrary',
|
||||||
|
'isComplete': true,
|
||||||
|
'elements': [
|
||||||
|
{
|
||||||
|
'id': '2be275a1-b00d-4e45-83d8-66af43ac2252',
|
||||||
|
'name': 'Company Home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '1be10a97-6eb9-4b60-b6c6-1673900e9631',
|
||||||
|
'name': 'Sites'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
|
||||||
|
'name': 'testsite'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'id': '71626fae-0c04-4d0c-a129-20fa4c178716',
|
||||||
|
'name': 'documentLibrary'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
'isFolder': true,
|
'isFolder': true,
|
||||||
'isFile': false,
|
'isFile': false,
|
||||||
'createdByUser': {
|
'createdByUser': {
|
||||||
@@ -183,3 +250,109 @@ export const fakeNodeWithOnlyLocally: any = {
|
|||||||
'app:icon': 'space-icon-default'
|
'app:icon': 'space-icon-default'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fakeSiteNodeResponse: any = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 1,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 1,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'context': {},
|
||||||
|
'entries': [
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'isLink': false,
|
||||||
|
'isFile': false,
|
||||||
|
'createdByUser': {
|
||||||
|
'id': 'admin',
|
||||||
|
'displayName': 'Administrator'
|
||||||
|
},
|
||||||
|
'modifiedAt': '2018-03-22T15:40:10.093+0000',
|
||||||
|
'nodeType': 'st:site',
|
||||||
|
'parentId': '1be10a97-6eb9-4b60-b6c6-1673900e9631',
|
||||||
|
'aspectNames': [
|
||||||
|
'cm:tagscope',
|
||||||
|
'cm:titled',
|
||||||
|
'cm:auditable'
|
||||||
|
],
|
||||||
|
'createdAt': '2018-03-22T15:39:50.821+0000',
|
||||||
|
'isFolder': true,
|
||||||
|
'search': {
|
||||||
|
'score': 10.292057
|
||||||
|
},
|
||||||
|
'modifiedByUser': {
|
||||||
|
'id': 'admin',
|
||||||
|
'displayName': 'Administrator'
|
||||||
|
},
|
||||||
|
'name': 'testsite',
|
||||||
|
'location': 'nodes',
|
||||||
|
'id': 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
|
||||||
|
'properties': {
|
||||||
|
'st:siteVisibility': 'PUBLIC',
|
||||||
|
'cm:title': 'TEST_SITE',
|
||||||
|
'st:sitePreset': 'site-dashboard'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fakeSiteRoles: any = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 4,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 4,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'entries': [
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'displayName': 'site_testsite_SiteCollaborator',
|
||||||
|
'id': 'GROUP_site_testsite_SiteCollaborator',
|
||||||
|
'memberType': 'GROUP'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'displayName': 'site_testsite_SiteConsumer',
|
||||||
|
'id': 'GROUP_site_testsite_SiteConsumer',
|
||||||
|
'memberType': 'GROUP'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'displayName': 'site_testsite_SiteContributor',
|
||||||
|
'id': 'GROUP_site_testsite_SiteContributor',
|
||||||
|
'memberType': 'GROUP'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'entry': {
|
||||||
|
'displayName': 'site_testsite_SiteManager',
|
||||||
|
'id': 'GROUP_site_testsite_SiteManager',
|
||||||
|
'memberType': 'GROUP'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fakeEmptyResponse: any = {
|
||||||
|
'list': {
|
||||||
|
'pagination': {
|
||||||
|
'count': 0,
|
||||||
|
'hasMoreItems': false,
|
||||||
|
'totalItems': 0,
|
||||||
|
'skipCount': 0,
|
||||||
|
'maxItems': 100
|
||||||
|
},
|
||||||
|
'context': {},
|
||||||
|
'entries': []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@@ -4,7 +4,22 @@
|
|||||||
<data-column key="icon" type="icon" [sortable]="false">
|
<data-column key="icon" type="icon" [sortable]="false">
|
||||||
</data-column>
|
</data-column>
|
||||||
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.AUTHORITY_ID' | translate}}" key="authorityId"></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.ROLE' | translate}}" key="name">
|
||||||
|
<ng-template let-entry="$implicit">
|
||||||
|
<mat-form-field *ngIf="!entry.row.getValue('isInherited') else show_only_label">
|
||||||
|
<mat-select id="adf-select-role-permission"
|
||||||
|
value="{{entry.data.getValue(entry.row, entry.col)}}"
|
||||||
|
(selectionChange)="saveNewRole($event, entry.row.obj)">
|
||||||
|
<mat-option *ngFor="let role of settableRoles" [value]="role">
|
||||||
|
{{ role }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
<ng-template #show_only_label>
|
||||||
|
<span>{{entry.data.getValue(entry.row, entry.col)}}</span>
|
||||||
|
</ng-template>
|
||||||
|
</ng-template>
|
||||||
|
</data-column>
|
||||||
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.INHERITED' | translate}}" key="isInherited">
|
<data-column title="{{'PERMISSION_MANAGER.PERMISSION_DISPLAY.INHERITED' | translate}}" key="isInherited">
|
||||||
<ng-template let-entry="$implicit">
|
<ng-template let-entry="$implicit">
|
||||||
<mat-chip-list>
|
<mat-chip-list>
|
||||||
|
@@ -17,9 +17,16 @@
|
|||||||
|
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { PermissionListComponent } from './permission-list.component';
|
import { PermissionListComponent } from './permission-list.component';
|
||||||
import { NodesApiService } from '@alfresco/adf-core';
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { NodesApiService, SearchService } from '@alfresco/adf-core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { fakeNodeWithPermissions, fakeNodeInheritedOnly, fakeNodeWithOnlyLocally } from '../../../mock/permission-list.component.mock';
|
import { NodePermissionService } from '../../services/node-permission.service';
|
||||||
|
import { fakeNodeWithPermissions,
|
||||||
|
fakeNodeInheritedOnly,
|
||||||
|
fakeNodeWithOnlyLocally,
|
||||||
|
fakeSiteNodeResponse,
|
||||||
|
fakeSiteRoles,
|
||||||
|
fakeEmptyResponse } from '../../../mock/permission-list.component.mock';
|
||||||
|
|
||||||
describe('PermissionDisplayComponent', () => {
|
describe('PermissionDisplayComponent', () => {
|
||||||
|
|
||||||
@@ -27,18 +34,22 @@ describe('PermissionDisplayComponent', () => {
|
|||||||
let component: PermissionListComponent;
|
let component: PermissionListComponent;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
let nodeService: NodesApiService;
|
let nodeService: NodesApiService;
|
||||||
|
let nodePermissionService: NodePermissionService;
|
||||||
|
let searchApiService: SearchService;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
PermissionListComponent
|
PermissionListComponent
|
||||||
],
|
],
|
||||||
providers: [NodesApiService]
|
providers: [NodesApiService, NodePermissionService]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
fixture = TestBed.createComponent(PermissionListComponent);
|
fixture = TestBed.createComponent(PermissionListComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
nodeService = TestBed.get(NodesApiService);
|
nodeService = TestBed.get(NodesApiService);
|
||||||
|
nodePermissionService = TestBed.get(NodePermissionService);
|
||||||
|
searchApiService = TestBed.get(SearchService);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -47,35 +58,126 @@ describe('PermissionDisplayComponent', () => {
|
|||||||
TestBed.resetTestingModule();
|
TestBed.resetTestingModule();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to render the component', async() => {
|
it('should be able to render the component', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show the node permissions', async() => {
|
it('should show the node permissions', () => {
|
||||||
component.nodeId = 'fake-node-id';
|
component.nodeId = 'fake-node-id';
|
||||||
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithPermissions));
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithPermissions));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeEmptyResponse));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
||||||
expect(element.querySelectorAll('.adf-datatable-row').length).toBe(4);
|
expect(element.querySelectorAll('.adf-datatable-row').length).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show inherited label for inherited permissions', async() => {
|
it('should show inherited label for inherited permissions', () => {
|
||||||
component.nodeId = 'fake-node-id';
|
component.nodeId = 'fake-node-id';
|
||||||
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeInheritedOnly));
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeInheritedOnly));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeEmptyResponse));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
||||||
expect(element.querySelector('#adf-permission-inherited-label')).toBeDefined();
|
expect(element.querySelector('#adf-permission-inherited-label')).toBeDefined();
|
||||||
expect(element.querySelector('#adf-permission-inherited-label')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-inherited-label')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show locally set label for locally set permissions', async() => {
|
describe('when it is a locally set permission', () => {
|
||||||
|
|
||||||
|
it('should show locally set label for locally set permissions', () => {
|
||||||
component.nodeId = 'fake-node-id';
|
component.nodeId = 'fake-node-id';
|
||||||
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
|
||||||
|
spyOn(nodePermissionService, 'getGroupMemeberByGroupName').and.returnValue(Observable.of(fakeSiteRoles));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeSiteNodeResponse));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-display-container')).not.toBeNull();
|
||||||
expect(element.querySelector('#adf-permission-locallyset-label')).toBeDefined();
|
expect(element.querySelector('#adf-permission-locallyset-label')).toBeDefined();
|
||||||
expect(element.querySelector('#adf-permission-locallyset-label')).not.toBeNull();
|
expect(element.querySelector('#adf-permission-locallyset-label')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should show a dropdown with the possible roles', async(() => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
|
||||||
|
spyOn(nodePermissionService, 'getGroupMemeberByGroupName').and.returnValue(Observable.of(fakeSiteRoles));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeSiteNodeResponse));
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).toBeDefined();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).not.toBeNull();
|
||||||
|
const selectBox = fixture.debugElement.query(By.css(('#adf-select-role-permission .mat-select-trigger')));
|
||||||
|
selectBox.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
let options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||||
|
expect(options).not.toBeNull();
|
||||||
|
expect(options.length).toBe(4);
|
||||||
|
expect(options[0].nativeElement.innerText).toContain('SiteCollaborator');
|
||||||
|
expect(options[1].nativeElement.innerText).toContain('SiteConsumer');
|
||||||
|
expect(options[2].nativeElement.innerText).toContain('SiteContributor');
|
||||||
|
expect(options[3].nativeElement.innerText).toContain('SiteManager');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should show the settable roles if the node is not in any site', async(() => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeEmptyResponse));
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).toBeDefined();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).not.toBeNull();
|
||||||
|
const selectBox = fixture.debugElement.query(By.css(('#adf-select-role-permission .mat-select-trigger')));
|
||||||
|
selectBox.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
let options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||||
|
expect(options).not.toBeNull();
|
||||||
|
expect(options.length).toBe(5);
|
||||||
|
expect(options[0].nativeElement.innerText).toContain('Contributor');
|
||||||
|
expect(options[1].nativeElement.innerText).toContain('Collaborator');
|
||||||
|
expect(options[2].nativeElement.innerText).toContain('Coordinator');
|
||||||
|
expect(options[3].nativeElement.innerText).toContain('Editor');
|
||||||
|
expect(options[4].nativeElement.innerText).toContain('Consumer');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should update the role when another value is chosen', async(() => {
|
||||||
|
component.nodeId = 'fake-node-id';
|
||||||
|
spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithOnlyLocally));
|
||||||
|
spyOn(nodeService, 'updateNode').and.returnValue(Observable.of({id: 'fake-updated-node'}));
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeEmptyResponse));
|
||||||
|
component.update.subscribe((updatedPermission) => {
|
||||||
|
expect(updatedPermission).not.toBeNull();
|
||||||
|
expect(updatedPermission.name).toBe('Editor');
|
||||||
|
expect(updatedPermission.authorityId).toBe('GROUP_EVERYONE');
|
||||||
|
expect(updatedPermission.accessStatus).toBe('ALLOWED');
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).toBeDefined();
|
||||||
|
expect(element.querySelector('#adf-select-role-permission')).not.toBeNull();
|
||||||
|
const selectBox = fixture.debugElement.query(By.css(('#adf-select-role-permission .mat-select-trigger')));
|
||||||
|
selectBox.triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
let options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||||
|
expect(options).not.toBeNull();
|
||||||
|
expect(options.length).toBe(5);
|
||||||
|
options[3].triggerEventHandler('click', {});
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(nodeService.updateNode).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -15,10 +15,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, ViewEncapsulation, Input, OnInit } from '@angular/core';
|
import { Component, ViewEncapsulation, Input, OnInit, EventEmitter, Output } from '@angular/core';
|
||||||
import { NodesApiService } from '@alfresco/adf-core';
|
import { NodesApiService } from '@alfresco/adf-core';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, PermissionElement } from 'alfresco-js-api';
|
||||||
import { PermissionDisplayModel } from '../../models/permission.model';
|
import { PermissionDisplayModel } from '../../models/permission.model';
|
||||||
|
import { NodePermissionService } from '../../services/node-permission.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-permission-list',
|
selector: 'adf-permission-list',
|
||||||
@@ -31,9 +32,15 @@ export class PermissionListComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
nodeId: string = '';
|
nodeId: string = '';
|
||||||
|
|
||||||
permissionList: PermissionDisplayModel[];
|
@Output()
|
||||||
|
update: EventEmitter<PermissionElement> = new EventEmitter();
|
||||||
|
|
||||||
constructor(private nodeService: NodesApiService) {
|
permissionList: PermissionDisplayModel[];
|
||||||
|
settableRoles: any[];
|
||||||
|
actualNode: MinimalNodeEntryEntity;
|
||||||
|
|
||||||
|
constructor(private nodeService: NodesApiService,
|
||||||
|
private nodePermissionService: NodePermissionService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +54,11 @@ export class PermissionListComponent implements OnInit {
|
|||||||
|
|
||||||
private fetchNodePermissions() {
|
private fetchNodePermissions() {
|
||||||
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
|
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
|
||||||
|
this.actualNode = node;
|
||||||
this.permissionList = this.getPermissionList(node);
|
this.permissionList = this.getPermissionList(node);
|
||||||
|
this.nodePermissionService.getNodeRoles(node).subscribe((settableList: string[]) => {
|
||||||
|
this.settableRoles = settableList;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,4 +80,20 @@ export class PermissionListComponent implements OnInit {
|
|||||||
return allPermissions;
|
return allPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveNewRole(event: any, permissionRow: PermissionDisplayModel) {
|
||||||
|
let updatedPermissionRole: PermissionElement = this.buildUpdatedPermission(event.value, permissionRow);
|
||||||
|
this.nodePermissionService.updatePermissionRoles(this.actualNode, updatedPermissionRole)
|
||||||
|
.subscribe((node: MinimalNodeEntryEntity) => {
|
||||||
|
this.update.emit(updatedPermissionRole);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildUpdatedPermission(newRole: string, permissionRow: PermissionDisplayModel): PermissionElement {
|
||||||
|
let permissionRole: PermissionElement = {};
|
||||||
|
permissionRole.accessStatus = permissionRow.accessStatus;
|
||||||
|
permissionRole.name = newRole;
|
||||||
|
permissionRole.authorityId = permissionRow.authorityId;
|
||||||
|
return permissionRole;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,19 +15,22 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class PermissionDisplayModel {
|
import { PermissionElement } from 'alfresco-js-api';
|
||||||
accessStatus: string;
|
|
||||||
authorityId: string;
|
export class PermissionDisplayModel implements PermissionElement {
|
||||||
name: string;
|
|
||||||
|
authorityId?: string;
|
||||||
|
name?: string;
|
||||||
|
accessStatus?: PermissionElement.AccessStatusEnum;
|
||||||
isInherited: boolean = false;
|
isInherited: boolean = false;
|
||||||
icon: string;
|
icon: string;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
this.accessStatus = obj.accessStatus;
|
|
||||||
this.authorityId = obj.authorityId;
|
this.authorityId = obj.authorityId;
|
||||||
this.name = obj.name;
|
this.name = obj.name;
|
||||||
this.isInherited = obj.isInherited;
|
this.accessStatus = obj.accessStatus;
|
||||||
|
this.isInherited = obj.isInherited !== null && obj.isInherited !== undefined ? obj.isInherited : false;
|
||||||
this.icon = obj.icon ? obj.icon : 'lock_open';
|
this.icon = obj.icon ? obj.icon : 'lock_open';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ import { MaterialModule } from '../material.module';
|
|||||||
import { PermissionListComponent } from './components/permission-list/permission-list.component';
|
import { PermissionListComponent } from './components/permission-list/permission-list.component';
|
||||||
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
|
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
|
||||||
import { InheritPermissionDirective } from './components/inherited-button.directive';
|
import { InheritPermissionDirective } from './components/inherited-button.directive';
|
||||||
|
import { NodePermissionService } from './services/node-permission.service';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -38,6 +39,9 @@ import { InheritPermissionDirective } from './components/inherited-button.direct
|
|||||||
PermissionListComponent,
|
PermissionListComponent,
|
||||||
InheritPermissionDirective
|
InheritPermissionDirective
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
NodePermissionService
|
||||||
|
],
|
||||||
exports: [
|
exports: [
|
||||||
PermissionListComponent,
|
PermissionListComponent,
|
||||||
InheritPermissionDirective
|
InheritPermissionDirective
|
||||||
|
@@ -17,5 +17,5 @@
|
|||||||
|
|
||||||
export * from './components/permission-list/permission-list.component';
|
export * from './components/permission-list/permission-list.component';
|
||||||
export * from './components/inherited-button.directive';
|
export * from './components/inherited-button.directive';
|
||||||
|
export * from './services/node-permission.service';
|
||||||
export * from './models/permission.model';
|
export * from './models/permission.model';
|
||||||
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*!
|
||||||
|
* @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, TestBed } from '@angular/core/testing';
|
||||||
|
import { NodePermissionService } from './node-permission.service';
|
||||||
|
import { AlfrescoApiService, SearchService, NodesApiService } from '@alfresco/adf-core';
|
||||||
|
import { MinimalNodeEntryEntity, PermissionElement } from 'alfresco-js-api';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { fakeEmptyResponse, fakeNodeWithOnlyLocally, fakeSiteRoles, fakeSiteNodeResponse } from '../../mock/permission-list.component.mock';
|
||||||
|
|
||||||
|
describe('NodePermissionService', () => {
|
||||||
|
|
||||||
|
let service: NodePermissionService,
|
||||||
|
nodeService: NodesApiService,
|
||||||
|
searchApiService: SearchService;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
AlfrescoApiService,
|
||||||
|
NodePermissionService, SearchService, NodesApiService
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = TestBed.get(NodePermissionService);
|
||||||
|
searchApiService = TestBed.get(SearchService);
|
||||||
|
nodeService = TestBed.get(NodesApiService);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
function returnUpdatedNode(nodeId, nodeBody) {
|
||||||
|
let fakeNode: MinimalNodeEntryEntity = {};
|
||||||
|
fakeNode.id = 'fake-updated-node';
|
||||||
|
fakeNode.permissions = nodeBody.permissions;
|
||||||
|
return Observable.of(fakeNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should return a list of roles taken from the site groups', async(() => {
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeSiteNodeResponse));
|
||||||
|
spyOn(service, 'getGroupMemeberByGroupName').and.returnValue(Observable.of(fakeSiteRoles));
|
||||||
|
|
||||||
|
service.getNodeRoles(fakeNodeWithOnlyLocally).subscribe((roleArray: string[]) => {
|
||||||
|
expect(roleArray).not.toBeNull();
|
||||||
|
expect(roleArray.length).toBe(4);
|
||||||
|
expect(roleArray[0]).toBe('SiteCollaborator');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should return a list of settable if node has no site', async(() => {
|
||||||
|
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(Promise.resolve(fakeEmptyResponse));
|
||||||
|
|
||||||
|
service.getNodeRoles(fakeNodeWithOnlyLocally).subscribe((roleArray: string[]) => {
|
||||||
|
expect(roleArray).not.toBeNull();
|
||||||
|
expect(roleArray.length).toBe(5);
|
||||||
|
expect(roleArray[0]).toBe('Contributor');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be able to update a locally set permission role', async(() => {
|
||||||
|
const fakeAccessStatus: any = 'DENIED';
|
||||||
|
const fakePermission: PermissionElement = {
|
||||||
|
'authorityId': 'GROUP_EVERYONE',
|
||||||
|
'name': 'Contributor',
|
||||||
|
'accessStatus' : fakeAccessStatus
|
||||||
|
};
|
||||||
|
|
||||||
|
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||||
|
|
||||||
|
service.updatePermissionRoles(fakeNodeWithOnlyLocally, fakePermission).subscribe((node: MinimalNodeEntryEntity) => {
|
||||||
|
expect(node).not.toBeNull();
|
||||||
|
expect(node.id).toBe('fake-updated-node');
|
||||||
|
expect(node.permissions.locallySet.length).toBe(1);
|
||||||
|
expect(node.permissions.locallySet[0].authorityId).toBe(fakePermission.authorityId);
|
||||||
|
expect(node.permissions.locallySet[0].name).toBe(fakePermission.name);
|
||||||
|
expect(node.permissions.locallySet[0].accessStatus).toBe(fakePermission.accessStatus);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { Injectable } from '@angular/core';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { AlfrescoApiService, SearchService, NodesApiService } from '@alfresco/adf-core';
|
||||||
|
import { QueryBody, MinimalNodeEntryEntity, PathElement, GroupMemberEntry, GroupsPaging, GroupMemberPaging, PermissionElement } from 'alfresco-js-api';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NodePermissionService {
|
||||||
|
|
||||||
|
constructor(private apiService: AlfrescoApiService,
|
||||||
|
private searchApiService: SearchService,
|
||||||
|
private nodeService: NodesApiService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
getNodeRoles(node: MinimalNodeEntryEntity): Observable<string[]> {
|
||||||
|
const retrieveSiteQueryBody: QueryBody = this.buildRetrieveSiteQueryBody(node.path.elements);
|
||||||
|
return Observable.fromPromise(this.searchApiService.searchByQueryBody(retrieveSiteQueryBody))
|
||||||
|
.switchMap((siteNodeList: any) => {
|
||||||
|
if ( siteNodeList.list.entries.length > 0 ) {
|
||||||
|
let siteName = siteNodeList.list.entries[0].entry.name;
|
||||||
|
return this.getGroupMembersBySiteName(siteName);
|
||||||
|
} else {
|
||||||
|
return Observable.of(node.permissions.settable);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePermissionRoles(node: MinimalNodeEntryEntity, updatedPermissionRole: PermissionElement): Observable<MinimalNodeEntryEntity> {
|
||||||
|
let permissionBody = { permissions: { locallySet: []} };
|
||||||
|
const index = node.permissions.locallySet.map((permission) => permission.authorityId).indexOf(updatedPermissionRole.authorityId);
|
||||||
|
permissionBody.permissions.locallySet = permissionBody.permissions.locallySet.concat(node.permissions.locallySet);
|
||||||
|
if (index !== -1) {
|
||||||
|
permissionBody.permissions.locallySet[index] = updatedPermissionRole;
|
||||||
|
} else {
|
||||||
|
permissionBody.permissions.locallySet.push(updatedPermissionRole);
|
||||||
|
}
|
||||||
|
return this.nodeService.updateNode(node.id, permissionBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
private getGroupMembersBySiteName(siteName: string): Observable<string[]> {
|
||||||
|
const groupName = 'GROUP_site_' + siteName;
|
||||||
|
return this.getGroupMemeberByGroupName(groupName)
|
||||||
|
.map((res: GroupsPaging) => {
|
||||||
|
let displayResult: string[] = [];
|
||||||
|
res.list.entries.forEach((member: GroupMemberEntry) => {
|
||||||
|
displayResult.push(this.formattedRoleName(member.entry.displayName, 'site_' + siteName));
|
||||||
|
});
|
||||||
|
return displayResult;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getGroupMemeberByGroupName(groupName: string, opts?: any): Observable<GroupMemberPaging> {
|
||||||
|
return Observable.fromPromise(this.apiService.groupsApi.getGroupMembers(groupName, opts));
|
||||||
|
}
|
||||||
|
|
||||||
|
private formattedRoleName(displayName, siteName): string {
|
||||||
|
return displayName.replace(siteName + '_', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildRetrieveSiteQueryBody(nodePath: PathElement[]): QueryBody {
|
||||||
|
const pathNames = nodePath.map((node: PathElement) => 'name: "' + node.name + '"');
|
||||||
|
const buildedPathNames = pathNames.join(' OR ');
|
||||||
|
return {
|
||||||
|
'query': {
|
||||||
|
'query': buildedPathNames
|
||||||
|
},
|
||||||
|
'paging': {
|
||||||
|
'maxItems': 100,
|
||||||
|
'skipCount': 0
|
||||||
|
},
|
||||||
|
'include': ['aspectNames', 'properties'],
|
||||||
|
'filterQueries': [
|
||||||
|
{
|
||||||
|
'query':
|
||||||
|
"TYPE:'st:site'"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
|
|||||||
import {
|
import {
|
||||||
AlfrescoApi, ContentApi, FavoritesApi, NodesApi,
|
AlfrescoApi, ContentApi, FavoritesApi, NodesApi,
|
||||||
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi,
|
PeopleApi, RenditionsApi, SharedlinksApi, SitesApi,
|
||||||
VersionsApi, ClassesApi, SearchApi
|
VersionsApi, ClassesApi, SearchApi, GroupsApi
|
||||||
} from 'alfresco-js-api';
|
} from 'alfresco-js-api';
|
||||||
import * as alfrescoApi from 'alfresco-js-api';
|
import * as alfrescoApi from 'alfresco-js-api';
|
||||||
import { AppConfigService } from '../app-config/app-config.service';
|
import { AppConfigService } from '../app-config/app-config.service';
|
||||||
@@ -74,6 +74,10 @@ export class AlfrescoApiService {
|
|||||||
return this.getInstance().core.classesApi;
|
return this.getInstance().core.classesApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get groupsApi(): GroupsApi {
|
||||||
|
return this.getInstance().core.groupsApi;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(protected appConfig: AppConfigService,
|
constructor(protected appConfig: AppConfigService,
|
||||||
protected storage: StorageService) {
|
protected storage: StorageService) {
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user