From 93fe29503a6d04acdcc83a338f7ef31cbf874310 Mon Sep 17 00:00:00 2001 From: Mykyta Maliarchuk <84377976+nikita-web-ua@users.noreply.github.com> Date: Thu, 5 Oct 2023 10:40:47 +0200 Subject: [PATCH] [ACS-6002] Add permissions displaying Site Permissions outside of Sites (#8952) * [ACS-6002] added additional check for site * [ACS-6002] changed type * [ACS-6002] rebase --- .../mock/permission-list.component.mock.ts | 89 ++++++++++++++++++- .../services/node-permission.service.spec.ts | 13 +-- .../services/node-permission.service.ts | 29 +++--- 3 files changed, 112 insertions(+), 19 deletions(-) diff --git a/lib/content-services/src/lib/mock/permission-list.component.mock.ts b/lib/content-services/src/lib/mock/permission-list.component.mock.ts index 94cefeb5a9b..d45c89b9aac 100644 --- a/lib/content-services/src/lib/mock/permission-list.component.mock.ts +++ b/lib/content-services/src/lib/mock/permission-list.component.mock.ts @@ -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', @@ -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' } ] }, diff --git a/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts b/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts index ac9ec0500be..eb7b8299353 100644 --- a/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts +++ b/lib/content-services/src/lib/permission-manager/services/node-permission.service.spec.ts @@ -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'; @@ -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'); diff --git a/lib/content-services/src/lib/permission-manager/services/node-permission.service.ts b/lib/content-services/src/lib/permission-manager/services/node-permission.service.ts index a341a716e71..997a76933df 100644 --- a/lib/content-services/src/lib/permission-manager/services/node-permission.service.ts +++ b/lib/content-services/src/lib/permission-manager/services/node-permission.service.ts @@ -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'; @@ -50,17 +60,16 @@ export class NodePermissionService { * @returns Array of strings representing the roles */ getNodeRoles(node: Node): Observable { - 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); + } } /**