mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3228] Added lock check for context actions (#4163)
* [ADF-3228] Added lock check in content service * [ADF-3228] added unit test for lock check * [ADF-3228] fixed wrong line on rebase * [ADF-3228] fixed e2e related to new lock behaviour * [ADF-3228] externalised lock service and added more unit tests * [ADF-3228] added lock service to disable context actions * [ADF-3228] fixed e2e rebased to the latest
This commit is contained in:
@@ -443,6 +443,99 @@ describe('DocumentList', () => {
|
||||
expect(actions[0].disabled).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should disable the action if a readonly lock is applied to the file', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {
|
||||
entry: {
|
||||
isFile: true,
|
||||
name: 'xyz',
|
||||
isLocked: true,
|
||||
allowableOperations: ['create', 'update', 'delete'],
|
||||
properties: { 'cm:lockType': 'READ_ONLY_LOCK', 'cm:lockLifetime': 'PERSISTENT' }
|
||||
}
|
||||
};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not disable the action for the lock owner if write lock is applied', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('lockOwner');
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {
|
||||
entry: {
|
||||
isFile: true,
|
||||
name: 'xyz',
|
||||
isLocked: true,
|
||||
allowableOperations: ['create', 'update', 'delete'],
|
||||
properties: {
|
||||
'cm:lockType': 'WRITE_LOCK',
|
||||
'cm:lockLifetime': 'PERSISTENT',
|
||||
'cm:lockOwner': { id: 'lockOwner', displayName: 'lockOwner' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should disable the action if write lock is applied and user is not the lock owner', () => {
|
||||
let documentMenu = new ContentActionModel({
|
||||
permission: 'delete',
|
||||
target: 'document',
|
||||
title: 'FileAction'
|
||||
});
|
||||
|
||||
spyOn(apiService.getInstance(), 'getEcmUsername').and.returnValue('jerryTheKillerCow');
|
||||
|
||||
documentList.actions = [
|
||||
documentMenu
|
||||
];
|
||||
|
||||
let nodeFile = {
|
||||
entry: {
|
||||
isFile: true,
|
||||
name: 'xyz',
|
||||
isLocked: true,
|
||||
allowableOperations: ['create', 'update', 'delete'],
|
||||
properties: {
|
||||
'cm:lockType': 'WRITE_LOCK',
|
||||
'cm:lockLifetime': 'PERSISTENT',
|
||||
'cm:lockOwner': { id: 'lockOwner', displayName: 'lockOwner' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let actions = documentList.getNodeActions(nodeFile);
|
||||
expect(actions.length).toBe(1);
|
||||
expect(actions[0].title).toEqual('FileAction');
|
||||
expect(actions[0].disabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not disable the action if there is the right permission for the folder', () => {
|
||||
const documentMenu = new ContentActionModel({
|
||||
disableWithNoPermission: true,
|
||||
|
@@ -42,7 +42,8 @@ import {
|
||||
CustomEmptyContentTemplateDirective,
|
||||
RequestPaginationModel,
|
||||
AlfrescoApiService,
|
||||
UserPreferenceValues
|
||||
UserPreferenceValues,
|
||||
LockService
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { Node, NodeEntry, NodePaging, Pagination } from '@alfresco/js-api';
|
||||
@@ -325,7 +326,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
private customResourcesService: CustomResourcesService,
|
||||
private contentService: ContentService,
|
||||
private thumbnailService: ThumbnailService,
|
||||
private alfrescoApiService: AlfrescoApiService) {
|
||||
private alfrescoApiService: AlfrescoApiService,
|
||||
private lockService: LockService) {
|
||||
|
||||
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pagSize) => {
|
||||
this.maxItems = this._pagination.maxItems = pagSize;
|
||||
@@ -532,11 +534,14 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
return action.disabled(node);
|
||||
}
|
||||
|
||||
if (action.permission && action.disableWithNoPermission && !this.contentService.hasAllowableOperations(node.entry, action.permission)) {
|
||||
if ((action.permission &&
|
||||
action.disableWithNoPermission &&
|
||||
!this.contentService.hasAllowableOperations(node.entry, action.permission)) ||
|
||||
this.lockService.isLocked(node.entry)) {
|
||||
return true;
|
||||
} else {
|
||||
return action.disabled;
|
||||
}
|
||||
|
||||
return action.disabled;
|
||||
}
|
||||
|
||||
@HostListener('contextmenu', ['$event'])
|
||||
|
Reference in New Issue
Block a user