mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-24689] the add user or group icon is displayed within the folder permissions for a user with the collaborator role (#10373)
* [MNT-24689] Hide disallowed options for permissions * [MNT-24689] Used ng-container to wrap hidden buttons * MNT-24689 Unit tests * MNT-24689 Fixed sonar duplicated lines * [MNT-24689] Fixed sonar duplicated lines * [MNT-24689] Addressed comment
This commit is contained in:
@@ -15,15 +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',
|
||||
import { Node } from '@alfresco/js-api';
|
||||
|
||||
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,
|
||||
@@ -52,7 +48,11 @@ export const fakeNodeWithPermissions: 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: [
|
||||
{
|
||||
@@ -73,13 +73,7 @@ export const fakeNodeWithPermissions: any = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: true
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -92,9 +86,7 @@ export const fakeNodeWithPermissions: 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'
|
||||
}
|
||||
@@ -102,14 +94,7 @@ export const fakeNodeWithPermissions: any = {
|
||||
|
||||
export const fakeNodeInheritedOnly = {
|
||||
allowableOperations: ['updatePermissions'],
|
||||
aspectNames: [
|
||||
'cm:auditable',
|
||||
'cm:taggable',
|
||||
'cm:author',
|
||||
'cm:titled',
|
||||
'app:uifacets'
|
||||
],
|
||||
createdAt: '2017-11-16T16:29:38.638+0000',
|
||||
...fakeBaseNode,
|
||||
path: {
|
||||
name: '/Company Home/Sites/testsite/documentLibrary',
|
||||
isComplete: true,
|
||||
@@ -133,13 +118,6 @@ export const fakeNodeInheritedOnly = {
|
||||
}
|
||||
]
|
||||
},
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: {
|
||||
id: 'System',
|
||||
displayName: 'System'
|
||||
},
|
||||
modifiedAt: '2018-03-21T03:17:58.783+0000',
|
||||
permissions: {
|
||||
inherited: [
|
||||
{
|
||||
@@ -153,13 +131,7 @@ export const fakeNodeInheritedOnly = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: true
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -172,52 +144,14 @@ export const fakeNodeInheritedOnly = {
|
||||
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'
|
||||
}
|
||||
};
|
||||
|
||||
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',
|
||||
...fakeBaseNode,
|
||||
permissions: {
|
||||
inherited: [
|
||||
{
|
||||
@@ -231,13 +165,7 @@ export const fakeReadOnlyNodeInherited = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: true
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -250,56 +178,14 @@ export const fakeReadOnlyNodeInherited = {
|
||||
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'
|
||||
}
|
||||
};
|
||||
|
||||
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',
|
||||
...fakeBaseNode,
|
||||
permissions: {
|
||||
locallySet: [
|
||||
{
|
||||
@@ -308,13 +194,7 @@ export const fakeNodeWithoutSite: any = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: false
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -327,23 +207,15 @@ export const fakeNodeWithoutSite: 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'
|
||||
}
|
||||
};
|
||||
|
||||
export const fakeNodeWithOnlyLocally: any = {
|
||||
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,
|
||||
@@ -370,13 +242,6 @@ export const fakeNodeWithOnlyLocally: any = {
|
||||
}
|
||||
]
|
||||
},
|
||||
isFolder: true,
|
||||
isFile: false,
|
||||
createdByUser: {
|
||||
id: 'System',
|
||||
displayName: 'System'
|
||||
},
|
||||
modifiedAt: '2018-03-21T03:17:58.783+0000',
|
||||
permissions: {
|
||||
locallySet: [
|
||||
{
|
||||
@@ -385,13 +250,7 @@ export const fakeNodeWithOnlyLocally: any = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: false
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -404,52 +263,14 @@ export const fakeNodeWithOnlyLocally: 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'
|
||||
}
|
||||
};
|
||||
|
||||
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',
|
||||
...fakeBaseNode,
|
||||
permissions: {
|
||||
locallySet: [
|
||||
{
|
||||
@@ -468,13 +289,7 @@ export const fakeNodeToRemovePermission: any = {
|
||||
accessStatus: 'ALLOWED'
|
||||
}
|
||||
],
|
||||
settable: [
|
||||
'Contributor',
|
||||
'Collaborator',
|
||||
'Coordinator',
|
||||
'Editor',
|
||||
'Consumer'
|
||||
],
|
||||
settable: ['Contributor', 'Collaborator', 'Coordinator', 'Editor', 'Consumer'],
|
||||
isInheritanceEnabled: true
|
||||
},
|
||||
modifiedByUser: {
|
||||
@@ -487,52 +302,14 @@ export const fakeNodeToRemovePermission: 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'
|
||||
}
|
||||
};
|
||||
|
||||
export const fakeNodeWithoutPermissions: 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',
|
||||
...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: {
|
||||
@@ -664,14 +435,7 @@ 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',
|
||||
...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'
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@
|
||||
</h3>
|
||||
|
||||
<mat-slide-toggle
|
||||
*ngIf="updatePermissionsAllowed"
|
||||
class="adf-inherit-toggle"
|
||||
title="{{'PERMISSION_MANAGER.LABELS.INHERITED_PERMISSION_TOGGLE' | translate }}"
|
||||
color="primary"
|
||||
@@ -69,6 +70,7 @@
|
||||
|
||||
<div class="adf-toolbar--spacer"></div>
|
||||
|
||||
<ng-container *ngIf="updatePermissionsAllowed">
|
||||
<button
|
||||
mat-icon-button
|
||||
title="{{'PERMISSION_MANAGER.ACTION.ADD-PERMISSION' | translate}}"
|
||||
@@ -84,8 +86,9 @@
|
||||
[disabled]="!selectedPermissions?.length"
|
||||
(click)="deleteSelection()"
|
||||
data-automation-id="adf-delete-selected-permission">
|
||||
<mat-icon class="adf-delete-selected-permission-icon">delete_outline</mat-icon>
|
||||
<mat-icon>delete_outline</mat-icon>
|
||||
</button>
|
||||
</ng-container>
|
||||
</section>
|
||||
|
||||
<adf-permission-container
|
||||
@@ -98,7 +101,8 @@
|
||||
(updateAll)="updateAllPermission($event)"
|
||||
(row-select)="onSelect($any($event).detail.selection)"
|
||||
(row-unselect)="onSelect($any($event).detail.selection)"
|
||||
[roles]="model.roles" />
|
||||
[roles]="model.roles"
|
||||
[isReadOnly]="!updatePermissionsAllowed"/>
|
||||
|
||||
</mat-card-content>
|
||||
</ng-container>
|
||||
|
@@ -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,
|
||||
|
@@ -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<NodePermissionsModel>;
|
||||
let hasAllowableOperationsSpy: jasmine.Spy<(node: Node, allowableOperation: AllowableOperationsEnum | string) => boolean>;
|
||||
|
||||
const getPermissionContainerComponent = (): PermissionContainerComponent =>
|
||||
fixture.debugElement.query(By.directive(PermissionContainerComponent)).componentInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
data$ = new Subject<NodePermissionsModel>();
|
||||
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<NodePermissionsModel>;
|
||||
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<NodePermissionsModel>();
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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() {
|
||||
|
Reference in New Issue
Block a user