mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2826] added a check for duplicate permission add (#3265)
* [ADF-2556] first step to create add people or group to permissions * [ADF-2556] creating a dialog with user results * [ADF-2556] integrated service for add and remove permission from node * [ADF-2556] fixed behaviour and style for add user group * [ADF-2556] added some refactoring for dialog service * [ADF-2556] refactoring the dependencies of the components * [ADF-2556] added some fix and a new key for dialog * [ADF-2556] start adding test for node permission service * [ADF-2556] added test for add permission panel component * [ADf-2556] adding tests for new add permission component * [ADF-2556] fixed tests and added documentation * [ADF-2556] fixed documentation for add-node components * [ADF-2556] added peer review changes * [ADF-2826] added a check for duplicate permission add * [ADF-2826] removed fdescribe * [ADF-2826] applied peer review changes
This commit is contained in:
@@ -264,14 +264,17 @@
|
||||
"ROLE": "Role",
|
||||
"LOCALLY_SET": "Locally set",
|
||||
"NO_PERMISSIONS": "No permissions"
|
||||
},
|
||||
"ADD-PERMISSION": {
|
||||
"SEARCH" : "Search",
|
||||
"TYPE-MESSAGE" : "Type something to start searching groups or people",
|
||||
"NO-RESULT": "No result found for this search",
|
||||
"ADD-ACTION" : "ADD",
|
||||
"CLOSE-ACTION" : "CLOSE",
|
||||
"BASE-DIALOG-TITLE" : "Search a group or people to add..."
|
||||
}
|
||||
},
|
||||
"ADD-PERMISSION": {
|
||||
"SEARCH": "Search",
|
||||
"TYPE-MESSAGE": "Type something to start searching groups or people",
|
||||
"NO-RESULT": "No result found for this search",
|
||||
"ADD-ACTION": "ADD",
|
||||
"CLOSE-ACTION": "CLOSE",
|
||||
"BASE-DIALOG-TITLE": "Search a group or people to add..."
|
||||
},
|
||||
"ERROR": {
|
||||
"DUPLICATE-PERMISSION": "One or more of the permission you set is already present : {{list}}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ export class AddPermissionDialogComponent {
|
||||
@ViewChild('addPermission')
|
||||
addPermissionComponent: AddPermissionComponent;
|
||||
|
||||
currentSelection: MinimalNodeEntity[] = [];
|
||||
private currentSelection: MinimalNodeEntity[] = [];
|
||||
|
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: AddPermissionDialogData) {
|
||||
}
|
||||
|
@@ -148,4 +148,35 @@ describe('NodePermissionService', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be fail when user select the same authority and role to add', async(() => {
|
||||
const fakeNodeCopy = Object.assign(fakeNodeWithOnlyLocally);
|
||||
|
||||
const fakeDuplicateAuthority: any = [{
|
||||
'entry': {
|
||||
'isFolder': false,
|
||||
'search': {
|
||||
'score': 0.3541112
|
||||
},
|
||||
'isFile': false,
|
||||
'name': 'GROUP_EVERYONE',
|
||||
'location': 'nodes',
|
||||
'id': 'GROUP_EVERYONE',
|
||||
'nodeType': 'cm:authorityContainer',
|
||||
'properties': {
|
||||
'cm:authorityName': 'GROUP_EVERYONE'
|
||||
},
|
||||
'parentId': '030d833e-da8e-4f5c-8ef9-d809638bd04b'
|
||||
}
|
||||
}];
|
||||
|
||||
service.updateLocallySetPermissions(fakeNodeCopy, fakeDuplicateAuthority, ['Contributor'])
|
||||
.subscribe((node: MinimalNodeEntryEntity) => {
|
||||
|
||||
}, (errorMessage) => {
|
||||
expect(errorMessage).not.toBeNull();
|
||||
expect(errorMessage).toBeDefined();
|
||||
expect(errorMessage).toBe('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION');
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { AlfrescoApiService, SearchService, NodesApiService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, SearchService, NodesApiService, TranslationService } from '@alfresco/adf-core';
|
||||
import { QueryBody, MinimalNodeEntryEntity, MinimalNodeEntity, PathElement, GroupMemberEntry, GroupsPaging, GroupMemberPaging, PermissionElement } from 'alfresco-js-api';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import { of } from 'rxjs/observable/of';
|
||||
@@ -28,7 +28,8 @@ export class NodePermissionService {
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private searchApiService: SearchService,
|
||||
private nodeService: NodesApiService) {
|
||||
private nodeService: NodesApiService,
|
||||
private translation: TranslationService) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,6 @@ export class NodePermissionService {
|
||||
* @returns Node with updated permission
|
||||
*/
|
||||
updatePermissionRole(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);
|
||||
@@ -82,10 +82,33 @@ export class NodePermissionService {
|
||||
updateLocallySetPermissions(node: MinimalNodeEntryEntity, nodes: MinimalNodeEntity[], nodeRole: string[]): Observable<MinimalNodeEntryEntity> {
|
||||
let permissionBody = { permissions: { locallySet: []} };
|
||||
const permissionList = this.transformNodeToPermissionElement(nodes, nodeRole[0]);
|
||||
const duplicatedPermissions = this.getDuplicatedPermissions(node.permissions.locallySet, permissionList);
|
||||
if (duplicatedPermissions.length > 0) {
|
||||
const list = duplicatedPermissions.map((permission) => 'authority -> ' + permission.authorityId + ' / role -> ' + permission.name).join(', ');
|
||||
const duplicatePermissionMessage: string = this.translation.instant('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION', {list});
|
||||
return Observable.throw(duplicatePermissionMessage);
|
||||
}
|
||||
permissionBody.permissions.locallySet = node.permissions.locallySet ? node.permissions.locallySet.concat(permissionList) : permissionList;
|
||||
return this.nodeService.updateNode(node.id, permissionBody);
|
||||
}
|
||||
|
||||
private getDuplicatedPermissions(nodeLocallySet: PermissionElement[], permissionListAdded: PermissionElement[]): PermissionElement[] {
|
||||
let duplicatePermissions: PermissionElement[] = [];
|
||||
permissionListAdded.forEach((permission: PermissionElement) => {
|
||||
const duplicate = nodeLocallySet.find((localPermission) => this.isEqualPermission(localPermission, permission));
|
||||
if (duplicate) {
|
||||
duplicatePermissions.push(duplicate);
|
||||
}
|
||||
});
|
||||
return duplicatePermissions;
|
||||
}
|
||||
|
||||
private isEqualPermission(oldPermission: PermissionElement, newPermission: PermissionElement): boolean {
|
||||
return oldPermission.accessStatus === newPermission.accessStatus &&
|
||||
oldPermission.authorityId === newPermission.authorityId &&
|
||||
oldPermission.name === newPermission.name;
|
||||
}
|
||||
|
||||
private transformNodeToPermissionElement(nodes: MinimalNodeEntity[], nodeRole: any): PermissionElement[] {
|
||||
return nodes.map((node) => {
|
||||
let newPermissionElement: PermissionElement = <PermissionElement> {
|
||||
|
Reference in New Issue
Block a user