[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

@@ -0,0 +1,72 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { AlfrescoApiService } from './alfresco-api.service';
import moment from 'moment-es6';
import { Moment } from 'moment';
@Injectable({
providedIn: 'root'
})
export class LockService {
constructor(private alfrescoApiService: AlfrescoApiService) {
}
isLocked(node: Node): boolean {
let isLocked = false;
if (this.hasLockConfigured(node)) {
if (this.isReadOnlyLock(node)) {
isLocked = true;
if (this.isLockExpired(node)) {
isLocked = false;
}
} else if (this.isLockOwnerAllowed(node)) {
isLocked = this.alfrescoApiService.getInstance().getEcmUsername() !== node.properties['cm:lockOwner'].id;
if (this.isLockExpired(node)) {
isLocked = false;
}
}
}
return isLocked;
}
private hasLockConfigured(node: Node): boolean {
return node.isFile && node.isLocked && node.properties['cm:lockType'];
}
private isReadOnlyLock(node: Node): boolean {
return node.properties['cm:lockType'] === 'READ_ONLY_LOCK' && node.properties['cm:lockLifetime'] === 'PERSISTENT';
}
private isLockOwnerAllowed(node: Node): boolean {
return node.properties['cm:lockType'] === 'WRITE_LOCK' && node.properties['cm:lockLifetime'] === 'PERSISTENT';
}
private getLockExpiryTime(node: Node): Moment {
if (node.properties['cm:expiryDate']) {
return moment(node.properties['cm:expiryDate'], 'yyyy-MM-ddThh:mm:ssZ');
}
}
private isLockExpired(node: Node): boolean {
let expiryLockTime = this.getLockExpiryTime(node);
return moment().isAfter(expiryLockTime);
}
}