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 e420344423..78c228ab1f 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 @@ -15,495 +15,11 @@ * limitations under the License. */ -export const fakeNodeWithPermissions: any = { - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - 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, - isFile: false, - createdByUser: { - id: 'System', - displayName: 'System' - }, - modifiedAt: '2018-03-21T03:17:58.783+0000', - permissions: { - inherited: [ - { - authorityId: 'guest', - name: 'Read', - accessStatus: 'ALLOWED' - }, - { - authorityId: 'GROUP_EVERYONE', - name: 'Read', - accessStatus: 'ALLOWED' - } - ], - locallySet: [ - { - authorityId: 'GROUP_EVERYONE', - name: 'Contributor', - accessStatus: 'ALLOWED' - } - ], - settable: [ - 'Contributor', - 'Collaborator', - 'Coordinator', - 'Editor', - 'Consumer' - ], - isInheritanceEnabled: true - }, - 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' - } -}; +import { Node } from '@alfresco/js-api'; -export const fakeNodeInheritedOnly = { - allowableOperations: [ 'updatePermissions' ], - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - 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', - nodeType: 'st:site' - }, - { - id: '71626fae-0c04-4d0c-a129-20fa4c178716', - name: 'documentLibrary' - } - ] - }, - isFolder: true, - isFile: false, - createdByUser: { - id: 'System', - displayName: 'System' - }, - modifiedAt: '2018-03-21T03:17:58.783+0000', - permissions: { - inherited: [ - { - authorityId: 'guest', - name: 'Read', - accessStatus: 'ALLOWED' - }, - { - authorityId: 'GROUP_EVERYONE', - name: 'Read', - accessStatus: 'ALLOWED' - } - ], - settable: [ - 'Contributor', - 'Collaborator', - 'Coordinator', - 'Editor', - 'Consumer' - ], - isInheritanceEnabled: true - }, - 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 fakeReadOnlyNodeInherited = { - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - 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, - isFile: false, - createdByUser: { - id: 'System', - displayName: 'System' - }, - modifiedAt: '2018-03-21T03:17:58.783+0000', - permissions: { - inherited: [ - { - authorityId: 'guest', - name: 'Read', - accessStatus: 'ALLOWED' - }, - { - authorityId: 'GROUP_EVERYONE', - name: 'Read', - accessStatus: 'ALLOWED' - } - ], - settable: [ - 'Contributor', - 'Collaborator', - 'Coordinator', - 'Editor', - 'Consumer' - ], - isInheritanceEnabled: true - }, - 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 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', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - 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', - nodeType: 'cm:folder' - }, - { - id: '1be10a97-6eb9-4b60-b6c6-1673900e9631', - name: 'Sites', - nodeType: 'st:sites' - }, - { - id: 'e002c740-b8f9-482a-a554-8fff4e4c9dc0', - name: 'testsite', - nodeType: 'st:site' - }, - { - 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 fakeNodeToRemovePermission: any = { - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - 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, - isFile: false, - createdByUser: { - id: 'System', - displayName: 'System' - }, - modifiedAt: '2018-03-21T03:17:58.783+0000', - permissions: { - locallySet: [ - { - authorityId: 'GROUP_EVERYONE', - name: 'Contributor', - accessStatus: 'ALLOWED' - }, - { - authorityId: 'GROUP_FAKE_1', - name: 'Contributor', - accessStatus: 'ALLOWED' - }, - { - authorityId: 'FAKE_PERSON_1', - name: 'Contributor', - accessStatus: 'ALLOWED' - } - ], - settable: [ - 'Contributor', - 'Collaborator', - 'Coordinator', - 'Editor', - 'Consumer' - ], - isInheritanceEnabled: true - }, - 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 fakeNodeWithoutPermissions: any = { - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - createdAt: '2017-11-16T16:29:38.638+0000', +const fakeBaseNode = { + aspectNames: ['cm:auditable', 'cm:taggable', 'cm:author', 'cm:titled', 'app:uifacets'], + createdAt: new Date('2017-11-16T16:29:38.638+0000'), path: { name: '/Company Home/Sites/testsite/documentLibrary', isComplete: true, @@ -532,7 +48,268 @@ export const fakeNodeWithoutPermissions: any = { id: 'System', displayName: 'System' }, - modifiedAt: '2018-03-21T03:17:58.783+0000', + modifiedAt: new Date('2018-03-21T03:17:58.783+0000') +} as Node; + +export const fakeNodeWithPermissions: any = { + ...fakeBaseNode, + permissions: { + inherited: [ + { + authorityId: 'guest', + name: 'Read', + accessStatus: 'ALLOWED' + }, + { + authorityId: 'GROUP_EVERYONE', + name: 'Read', + accessStatus: 'ALLOWED' + } + ], + locallySet: [ + { + authorityId: 'GROUP_EVERYONE', + name: 'Contributor', + accessStatus: 'ALLOWED' + } + ], + settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'], + isInheritanceEnabled: true + }, + 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 fakeNodeInheritedOnly = { + allowableOperations: ['updatePermissions'], + ...fakeBaseNode, + 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', + nodeType: 'st:site' + }, + { + id: '71626fae-0c04-4d0c-a129-20fa4c178716', + name: 'documentLibrary' + } + ] + }, + permissions: { + inherited: [ + { + authorityId: 'guest', + name: 'Read', + accessStatus: 'ALLOWED' + }, + { + authorityId: 'GROUP_EVERYONE', + name: 'Read', + accessStatus: 'ALLOWED' + } + ], + settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'], + isInheritanceEnabled: true + }, + 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 fakeReadOnlyNodeInherited = { + ...fakeBaseNode, + permissions: { + inherited: [ + { + authorityId: 'guest', + name: 'Read', + accessStatus: 'ALLOWED' + }, + { + authorityId: 'GROUP_EVERYONE', + name: 'Read', + accessStatus: 'ALLOWED' + } + ], + settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'], + isInheritanceEnabled: true + }, + 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 fakeNodeWithoutSite: any = { + ...fakeBaseNode, + 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 = { + allowableOperations: ['updatePermissions'], + ...fakeBaseNode, + path: { + name: '/Company Home/Sites/testsite/documentLibrary', + isComplete: true, + elements: [ + { + id: '2be275a1-b00d-4e45-83d8-66af43ac2252', + name: 'Company Home', + nodeType: 'cm:folder' + }, + { + id: '1be10a97-6eb9-4b60-b6c6-1673900e9631', + name: 'Sites', + nodeType: 'st:sites' + }, + { + id: 'e002c740-b8f9-482a-a554-8fff4e4c9dc0', + name: 'testsite', + nodeType: 'st:site' + }, + { + id: '71626fae-0c04-4d0c-a129-20fa4c178716', + name: 'documentLibrary', + nodeType: 'cm:folder' + } + ] + }, + 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 fakeNodeToRemovePermission: any = { + ...fakeBaseNode, + permissions: { + locallySet: [ + { + authorityId: 'GROUP_EVERYONE', + name: 'Contributor', + accessStatus: 'ALLOWED' + }, + { + authorityId: 'GROUP_FAKE_1', + name: 'Contributor', + accessStatus: 'ALLOWED' + }, + { + authorityId: 'FAKE_PERSON_1', + name: 'Contributor', + accessStatus: 'ALLOWED' + } + ], + settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'], + isInheritanceEnabled: true + }, + 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 fakeNodeWithoutPermissions: any = { + ...fakeBaseNode, permissions: { locallySet: [], settable: [], @@ -548,9 +325,7 @@ export const fakeNodeWithoutPermissions: any = { properties: { 'cm:title': 'test', 'cm:author': 'yagud', - 'cm:taggable': [ - 'e8c8fbba-03ba-4fa6-86b1-f7ad7c296409' - ], + 'cm:taggable': ['e8c8fbba-03ba-4fa6-86b1-f7ad7c296409'], 'cm:description': 'sleepery', 'app:icon': 'space-icon-default' } @@ -578,11 +353,7 @@ export const fakeSiteNodeResponse: any = { modifiedAt: '2018-03-22T15:40:10.093+0000', nodeType: 'st:site', parentId: '1be10a97-6eb9-4b60-b6c6-1673900e9631', - aspectNames: [ - 'cm:tagscope', - 'cm:titled', - 'cm:auditable' - ], + aspectNames: ['cm:tagscope', 'cm:titled', 'cm:auditable'], createdAt: '2018-03-22T15:39:50.821+0000', isFolder: true, search: { @@ -663,15 +434,8 @@ export const fakeEmptyResponse: any = { }; export const fakeNodeLocalSiteManager = { - allowableOperations: [ 'updatePermissions' ], - aspectNames: [ - 'cm:auditable', - 'cm:taggable', - 'cm:author', - 'cm:titled', - 'app:uifacets' - ], - createdAt: '2017-11-16T16:29:38.638+0000', + allowableOperations: ['updatePermissions'], + ...fakeBaseNode, path: { name: '/Company Home/Sites/testsite/documentLibrary', isComplete: true, @@ -695,13 +459,6 @@ export const fakeNodeLocalSiteManager = { } ] }, - isFolder: true, - isFile: false, - createdByUser: { - id: 'System', - displayName: 'System' - }, - modifiedAt: '2018-03-21T03:17:58.783+0000', permissions: { locallySet: [ { @@ -715,13 +472,7 @@ export const fakeNodeLocalSiteManager = { accessStatus: 'ALLOWED' } ], - settable: [ - 'Contributor', - 'Collaborator', - 'Coordinator', - 'Editor', - 'Consumer' - ], + settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'], isInheritanceEnabled: false }, modifiedByUser: { @@ -734,9 +485,7 @@ export const fakeNodeLocalSiteManager = { properties: { 'cm:title': 'test', 'cm:author': 'yagud', - 'cm:taggable': [ - 'e8c8fbba-03ba-4fa6-86b1-f7ad7c296409' - ], + 'cm:taggable': ['e8c8fbba-03ba-4fa6-86b1-f7ad7c296409'], 'cm:description': 'sleepery', 'app:icon': 'space-icon-default' } diff --git a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.html b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.html index cf40715f8f..87164fa6ae 100644 --- a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.html +++ b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.html @@ -22,6 +22,7 @@ - + + - + + + [roles]="model.roles" + [isReadOnly]="!updatePermissionsAllowed"/> diff --git a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.scss b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.scss index d8e67f36a2..4d04bf4a6c 100644 --- a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.scss +++ b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.scss @@ -89,10 +89,6 @@ flex: 1 1 auto; padding: 0; } - - &-delete-selected-permission-icon { - color: var(--theme-grey-divider-color); - } } [aria-sort='Ascending'] adf-user-role-column, diff --git a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts index 469798d70f..a7e598ad9f 100644 --- a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts +++ b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.spec.ts @@ -16,7 +16,7 @@ */ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { of, throwError } from 'rxjs'; +import { of, Subject, throwError } from 'rxjs'; import { SearchService } from '../../../search/services/search.service'; import { PermissionListComponent } from './permission-list.component'; import { NodePermissionService } from '../../services/node-permission.service'; @@ -38,6 +38,11 @@ import { HarnessLoader } from '@angular/cdk/testing'; import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; import { MatSlideToggleHarness } from '@angular/material/slide-toggle/testing'; import { MatSelectHarness } from '@angular/material/select/testing'; +import { By } from '@angular/platform-browser'; +import { MatSlideToggle } from '@angular/material/slide-toggle'; +import { ContentService } from '../../../common/services/content.service'; +import { AllowableOperationsEnum, NodePermissionsModel, PermissionContainerComponent } from '@alfresco/adf-content-services'; +import { DebugElement } from '@angular/core'; describe('PermissionListComponent', () => { let loader: HarnessLoader; @@ -47,8 +52,10 @@ describe('PermissionListComponent', () => { let nodeService: NodesApiService; let nodePermissionService: NodePermissionService; let searchApiService: SearchService; + let contentService: ContentService; let getNodeSpy: jasmine.Spy; let searchQuerySpy: jasmine.Spy; + const fakeLocalPermission = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)); beforeEach(() => { @@ -61,6 +68,7 @@ describe('PermissionListComponent', () => { nodeService = TestBed.inject(NodesApiService); nodePermissionService = TestBed.inject(NodePermissionService); searchApiService = TestBed.inject(SearchService); + contentService = TestBed.inject(ContentService); spyOn(nodePermissionService, 'getGroupMemberByGroupName').and.returnValue(of(fakeSiteRoles)); getNodeSpy = spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeWithoutPermissions)); @@ -132,6 +140,7 @@ describe('PermissionListComponent', () => { it('should toggle the inherited button', async () => { getNodeSpy.and.returnValue(of(fakeNodeInheritedOnly)); + spyOn(contentService, 'hasAllowableOperations').and.returnValue(true); component.ngOnInit(); fixture.detectChanges(); @@ -142,6 +151,7 @@ describe('PermissionListComponent', () => { 'PERMISSION_MANAGER.LABELS.INHERITED-PERMISSIONS PERMISSION_MANAGER.LABELS.ON' ); expect(element.querySelector('span[title="total"]').textContent.trim()).toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE'); + expect(contentService.hasAllowableOperations).toHaveBeenCalledWith(fakeNodeInheritedOnly, AllowableOperationsEnum.UPDATEPERMISSIONS); spyOn(nodeService, 'updateNode').and.returnValue(of(fakeLocalPermission)); @@ -155,28 +165,18 @@ describe('PermissionListComponent', () => { it('should not toggle inherited button for read only users', async () => { getNodeSpy.and.returnValue(of(fakeReadOnlyNodeInherited)); + spyOn(contentService, 'hasAllowableOperations').and.returnValue(false); component.ngOnInit(); fixture.detectChanges(); await fixture.whenStable(); - const toggle = await loader.getHarness(MatSlideToggleHarness); - expect(await toggle.isChecked()).toBe(true); - + expect(fixture.debugElement.query(By.directive(MatSlideToggle))).toBeNull(); expect(element.querySelector('.adf-inherit-container h3').textContent.trim()).toBe( 'PERMISSION_MANAGER.LABELS.INHERITED-PERMISSIONS PERMISSION_MANAGER.LABELS.ON' ); expect(element.querySelector('span[title="total"]').textContent.trim()).toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE'); - - spyOn(nodeService, 'updateNode').and.returnValue(of(fakeLocalPermission)); - - await toggle.uncheck(); - - expect(element.querySelector('.adf-inherit-container h3').textContent.trim()).toBe( - 'PERMISSION_MANAGER.LABELS.INHERITED-PERMISSIONS PERMISSION_MANAGER.LABELS.ON' - ); - expect(element.querySelector('span[title="total"]').textContent.trim()).toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE'); - expect(document.querySelector('.adf-snackbar-message-content').textContent).toContain('PERMISSION_MANAGER.ERROR.NOT-ALLOWED'); + expect(contentService.hasAllowableOperations).toHaveBeenCalledWith(fakeReadOnlyNodeInherited, AllowableOperationsEnum.UPDATEPERMISSIONS); }); }); @@ -275,4 +275,116 @@ describe('PermissionListComponent', () => { expect(nodeService.updateNode).toHaveBeenCalledWith('f472543f-7218-403d-917b-7a5861257244', { permissions: { locallySet: [] } }); }); }); + + describe('Permission container', () => { + let data$: Subject; + let hasAllowableOperationsSpy: jasmine.Spy<(node: Node, allowableOperation: AllowableOperationsEnum | string) => boolean>; + + const getPermissionContainerComponent = (): PermissionContainerComponent => + fixture.debugElement.query(By.directive(PermissionContainerComponent)).componentInstance; + + beforeEach(() => { + data$ = new Subject(); + component.permissionList.data$ = data$; + hasAllowableOperationsSpy = spyOn(TestBed.inject(ContentService), 'hasAllowableOperations'); + component.ngOnInit(); + fixture.detectChanges(); + }); + + it('should have assigned isReadOnly to false if updating of permissions is allowed', () => { + hasAllowableOperationsSpy.and.returnValue(true); + data$.next({ + node: fakeNodeWithPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getPermissionContainerComponent().isReadOnly).toBe(false); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + + it('should have assigned isReadOnly to true if updating of permissions is not allowed', () => { + hasAllowableOperationsSpy.and.returnValue(false); + data$.next({ + node: fakeNodeWithoutPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getPermissionContainerComponent().isReadOnly).toBe(true); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithoutPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + }); + + describe('Toolbar actions', () => { + let data$: Subject; + let hasAllowableOperationsSpy: jasmine.Spy<(node: Node, allowableOperation: AllowableOperationsEnum | string) => boolean>; + + const getAddPermissionButton = (): DebugElement => fixture.debugElement.query(By.css('[data-automation-id="adf-add-permission-button"]')); + + const getDeletePermissionButton = (): DebugElement => + fixture.debugElement.query(By.css('[data-automation-id="adf-delete-selected-permission"]')); + + beforeEach(() => { + data$ = new Subject(); + component.permissionList.data$ = data$; + hasAllowableOperationsSpy = spyOn(TestBed.inject(ContentService), 'hasAllowableOperations'); + component.ngOnInit(); + fixture.detectChanges(); + }); + + it('should display add permission button if updating of permissions is allowed', () => { + hasAllowableOperationsSpy.and.returnValue(true); + data$.next({ + node: fakeNodeWithPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getAddPermissionButton()).not.toBeNull(); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + + it('should not display add permission button if updating of permissions is not allowed', () => { + hasAllowableOperationsSpy.and.returnValue(false); + data$.next({ + node: fakeNodeWithoutPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getAddPermissionButton()).toBeNull(); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithoutPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + + it('should display delete permission button if updating of permissions is allowed', () => { + hasAllowableOperationsSpy.and.returnValue(true); + data$.next({ + node: fakeNodeWithPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getDeletePermissionButton()).not.toBeNull(); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + + it('should not display delete permission button if updating of permissions is not allowed', () => { + hasAllowableOperationsSpy.and.returnValue(false); + data$.next({ + node: fakeNodeWithoutPermissions, + inheritedPermissions: [], + localPermissions: [] + } as NodePermissionsModel); + fixture.detectChanges(); + + expect(getDeletePermissionButton()).toBeNull(); + expect(hasAllowableOperationsSpy).toHaveBeenCalledWith(fakeNodeWithoutPermissions, AllowableOperationsEnum.UPDATEPERMISSIONS); + }); + }); }); diff --git a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts index 57ed294c33..0a949c59a6 100644 --- a/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts +++ b/lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts @@ -17,7 +17,7 @@ import { ObjectDataRow } from '@alfresco/adf-core'; import { PermissionElement } from '@alfresco/js-api'; -import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; +import { Component, DestroyRef, EventEmitter, inject, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; import { PermissionDisplayModel } from '../../models/permission.model'; import { PermissionListService } from './permission-list.service'; import { CommonModule } from '@angular/common'; @@ -29,6 +29,8 @@ import { TranslateModule } from '@ngx-translate/core'; import { MatButtonModule } from '@angular/material/button'; import { PermissionContainerComponent } from '../permission-container/permission-container.component'; import { PopOverDirective } from '../pop-over.directive'; +import { AllowableOperationsEnum, ContentService } from '../../../common'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; @Component({ selector: 'adf-permission-list', @@ -63,13 +65,30 @@ export class PermissionListComponent implements OnInit { selectedPermissions: PermissionDisplayModel[] = []; - constructor(public readonly permissionList: PermissionListService) { + private _updatePermissionsAllowed = false; + + private readonly destroyRef = inject(DestroyRef); + + get updatePermissionsAllowed(): boolean { + return this._updatePermissionsAllowed; + } + + constructor(public readonly permissionList: PermissionListService, private readonly contentService: ContentService) { this.error = this.permissionList.errored; this.update = this.permissionList.updated; } ngOnInit(): void { this.permissionList.fetchPermission(this.nodeId); + this.permissionList.data$ + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe( + (model) => + (this._updatePermissionsAllowed = this.contentService.hasAllowableOperations( + model.node, + AllowableOperationsEnum.UPDATEPERMISSIONS + )) + ); } openAddPermissionDialog() {