blob: b82bc92017117e96c698088262bd53d67074f8a5 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 */
16import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17import Configuration from 'sdc-app/config/Configuration.js';
18import {permissionTypes} from 'sdc-app/onboarding/permissions/PermissionsConstants.js';
19import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
20import {actionTypes as onboardingActionTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
21
22function baseUrl() {
23 const restPrefix = Configuration.get('restPrefix');
24 return `${restPrefix}/v1.0/items`;
25}
26
27const ItemsHelper = {
28 performVCAction({itemId, version, action, comment}) {
29 const {id: versionId} = version;
30 const data = {
31 action,
32 ...action === VersionControllerActionsEnum.COMMIT && {commitRequest: {message: comment}}
33 };
34 return RestAPIUtil.put(`${baseUrl()}/${itemId}/versions/${versionId}/actions`, data);
35 },
36
37 fetchVersions({itemId}) {
38 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/versions`);
39 },
40
41 fetchVersion({itemId, versionId}) {
42 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/versions/${versionId}`);
43 },
44
45 fetchActivityLog({itemId, versionId}) {
46 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/versions/${versionId}/activity-logs`);
47 },
48
49 fetchUsers({itemId}) {
50 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/permissions`);
51 },
52
53 updateContributors({itemId, removedUsersIds, addedUsersIds}) {
54 return RestAPIUtil.put(`${baseUrl()}/${itemId}/permissions/${permissionTypes.CONTRIBUTOR}`, {removedUsersIds, addedUsersIds});
55 },
56
57 changeOwner({itemId, ownerId}) {
58 return RestAPIUtil.put(`${baseUrl()}/${itemId}/permissions/${permissionTypes.OWNER}`, {removedUsersIds: [], addedUsersIds: [ownerId]});
59 },
60
61 checkItemStatus(dispatch, {itemId, versionId}) {
62 return ItemsHelper.fetchVersion({itemId, versionId}).then(response => {
63 let state = response && response.state || {};
64 const {baseId, description, id, name, status} = response;
65
66 dispatch({
67 type: onboardingActionTypes.UPDATE_ITEM_STATUS,
68 itemState: state,
69 itemStatus: response.status,
70 updatedVersion: {baseId, description, id, name, status}
71 });
72 return Promise.resolve(response);
73 });
74
75 },
76};
77
78export default ItemsHelper;