[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:
Vito
2019-03-27 11:42:09 +00:00
committed by Eugenio Romano
parent e75335a06d
commit 070bf020a7
6 changed files with 356 additions and 56 deletions

View File

@@ -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,