Skip to content

Commit

Permalink
[ACS-6002] Add permissions displaying Site Permissions outside of Sit…
Browse files Browse the repository at this point in the history
…es (#8952)

* [ACS-6002] added additional check for site

* [ACS-6002] changed type

* [ACS-6002] rebase
  • Loading branch information
nikita-web-ua authored Oct 5, 2023
1 parent 441d800 commit 93fe295
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,83 @@ export const fakeReadOnlyNodeInherited = {
}
};

export const fakeNodeWithoutSite: any = {
aspectNames: [
'cm:auditable',
'cm:taggable',
'cm:author',
'cm:titled',
'app:uifacets'
],
createdAt: '2017-11-16T16:29:38.638+0000',
path: {
name: '/Company Home/User Homes/user/documentLibrary',
isComplete: true,
elements: [
{
id: '2be275a1-b00d-4e45-83d8-66af43ac2252',
name: 'Company Home',
nodeType: 'cm:folder'
},
{
id: '1be10a97-6eb9-4b60-b6c6-1673900e9631',
name: 'User Homes',
nodeType: 'cm:folder'
},
{
id: 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
name: 'user',
nodeType: 'cm:folder'
},
{
id: '71626fae-0c04-4d0c-a129-20fa4c178716',
name: 'documentLibrary',
nodeType: 'cm:folder'
}
]
},
isFolder: true,
isFile: false,
createdByUser: {
id: 'System',
displayName: 'System'
},
modifiedAt: '2018-03-21T03:17:58.783+0000',
permissions: {
locallySet: [
{
authorityId: 'GROUP_EVERYONE',
name: 'Contributor',
accessStatus: 'ALLOWED'
}
],
settable: [
'Contributor',
'Collaborator',
'Coordinator',
'Editor',
'Consumer'
],
isInheritanceEnabled: false
},
modifiedByUser: {
id: 'admin',
displayName: 'PedroH Hernandez'
},
name: 'test',
id: 'f472543f-7218-403d-917b-7a5861257244',
nodeType: 'cm:folder',
properties: {
'cm:title': 'test',
'cm:author': 'yagud',
'cm:taggable': [
'e8c8fbba-03ba-4fa6-86b1-f7ad7c296409'
],
'cm:description': 'sleepery',
'app:icon': 'space-icon-default'
}
};

export const fakeNodeWithOnlyLocally: any = {
aspectNames: [
'cm:auditable',
Expand All @@ -273,19 +350,23 @@ export const fakeNodeWithOnlyLocally: any = {
elements: [
{
id: '2be275a1-b00d-4e45-83d8-66af43ac2252',
name: 'Company Home'
name: 'Company Home',
nodeType: 'cm:folder'
},
{
id: '1be10a97-6eb9-4b60-b6c6-1673900e9631',
name: 'Sites'
name: 'Sites',
nodeType: 'st:sites'
},
{
id: 'e002c740-b8f9-482a-a554-8fff4e4c9dc0',
name: 'testsite'
name: 'testsite',
nodeType: 'st:site'
},
{
id: '71626fae-0c04-4d0c-a129-20fa4c178716',
name: 'documentLibrary'
name: 'documentLibrary',
nodeType: 'cm:folder'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import { NodePermissionService } from './node-permission.service';
import { SearchService } from '../../search/services/search.service';
import { Node, PermissionElement } from '@alfresco/js-api';
import { of, throwError } from 'rxjs';
import { fakeEmptyResponse, fakeNodeWithOnlyLocally, fakeSiteRoles, fakeSiteNodeResponse,
fakeNodeToRemovePermission, fakeNodeWithoutPermissions } from '../../mock/permission-list.component.mock';
import {
fakeNodeWithOnlyLocally, fakeSiteRoles, fakeSiteNodeResponse,
fakeNodeToRemovePermission, fakeNodeWithoutPermissions, fakeNodeWithoutSite
} from '../../mock/permission-list.component.mock';
import { fakeAuthorityResults } from '../../mock/add-permission.component.mock';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -79,10 +81,11 @@ describe('NodePermissionService', () => {
});
});

it('should return a list of settable if node has no site', (done) => {
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeEmptyResponse));
it('should not call search api and return a list of settable if node has no site', (done) => {
spyOn(searchApiService, 'searchByQueryBody');

service.getNodeRoles(fakeNodeWithOnlyLocally).subscribe((roleArray: string[]) => {
service.getNodeRoles(fakeNodeWithoutSite).subscribe((roleArray: string[]) => {
expect(searchApiService.searchByQueryBody).not.toHaveBeenCalled();
expect(roleArray).not.toBeNull();
expect(roleArray.length).toBe(5);
expect(roleArray[0]).toBe('Contributor');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { EcmUserModel } from '../../common/models/ecm-user.model';
import { Group, GroupMemberEntry, GroupMemberPaging, GroupsApi, Node, PathElement, PermissionElement, SearchRequest } from '@alfresco/js-api';
import {
Group,
GroupMemberEntry,
GroupMemberPaging,
GroupsApi,
Node,
PathElement,
PermissionElement,
ResultSetPaging,
SearchRequest
} from '@alfresco/js-api';
import { SearchService } from '../../search/services/search.service';
import { Injectable } from '@angular/core';
import { forkJoin, from, Observable, of, throwError } from 'rxjs';
Expand Down Expand Up @@ -50,17 +60,16 @@ export class NodePermissionService {
* @returns Array of strings representing the roles
*/
getNodeRoles(node: Node): Observable<string[]> {
const searchRequest = this.buildRetrieveSiteQueryBody(node.path.elements);
return this.searchApiService.searchByQueryBody(searchRequest).pipe(
switchMap((siteNodeList: any) => {
if (siteNodeList.list.entries.length > 0) {
if (node.path.elements.some(el => (el.nodeType === 'st:site' || el.nodeType === 'st:sites'))) {
const searchRequest = this.buildRetrieveSiteQueryBody(node.path.elements);
return this.searchApiService.searchByQueryBody(searchRequest).pipe(
switchMap((siteNodeList: ResultSetPaging) => {
const siteName = siteNodeList.list.entries[0].entry.name;
return this.getGroupMembersBySiteName(siteName);
} else {
return of(node.permissions?.settable);
}
})
);
}));
} else {
return of(node.permissions?.settable);
}
}

/**
Expand Down

0 comments on commit 93fe295

Please sign in to comment.