[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / nfvo-components / panel / versionController / VersionControllerUtils.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import Configuration from 'sdc-app/config/Configuration.js';
17 import {statusEnum} from './VersionControllerConstants.js';
18
19
20 const VersionControllerUtils = {
21
22         getCheckOutStatusKindByUserID(status, lockingUser) {
23                 let returnStatus;
24                 let isCheckedOut;
25                 let currentLoginUserID = Configuration.get('UserID');
26                 if (lockingUser) {
27                         isCheckedOut = currentLoginUserID === lockingUser;
28                         returnStatus = isCheckedOut ? status : statusEnum.LOCK_STATUS;
29                 } else {
30                         isCheckedOut = false;
31                         returnStatus = status;
32                 }
33
34                 return {
35                         status: returnStatus,
36                         isCheckedOut
37                 };
38         },
39
40         isCheckedOutByCurrentUser(resource) {
41                 let currentLoginUserID = Configuration.get('UserID');
42                 return resource.lockingUser !== undefined && resource.lockingUser === currentLoginUserID;
43         },
44
45         isReadOnly(resource) {
46                 const {version, viewableVersions = []} = resource;
47                 const latestVersion = viewableVersions[viewableVersions.length - 1];
48                 return version.id !== latestVersion.id || !VersionControllerUtils.isCheckedOutByCurrentUser(resource);
49         }
50 };
51
52 export default VersionControllerUtils;