2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import { permissionTypes } from 'sdc-app/onboarding/permissions/PermissionsConstants.js';
19 import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
20 import { actionTypes as onboardingActionTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
21 import objectPropsToUrlString from 'nfvo-utils/objectPropsToUrlString.js';
23 export const archiveActions = {
29 const restPrefix = Configuration.get('restPrefix');
30 return `${restPrefix}/v1.0/items`;
34 performVCAction({ itemId, version, action, comment }) {
35 const { id: versionId } = version;
38 ...(action === VersionControllerActionsEnum.COMMIT && {
39 commitRequest: { message: comment }
42 return RestAPIUtil.put(
43 `${baseUrl()}/${itemId}/versions/${versionId}/actions`,
48 fetchVersions({ itemId }) {
49 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/versions`);
52 fetchVersion({ itemId, versionId }) {
53 return RestAPIUtil.fetch(
54 `${baseUrl()}/${itemId}/versions/${versionId}`
58 fetchActivityLog({ itemId, versionId }) {
59 return RestAPIUtil.fetch(
60 `${baseUrl()}/${itemId}/versions/${versionId}/activity-logs`
64 fetchUsers({ itemId }) {
65 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}/permissions`);
68 updateContributors({ itemId, removedUsersIds, addedUsersIds }) {
69 return RestAPIUtil.put(
70 `${baseUrl()}/${itemId}/permissions/${permissionTypes.CONTRIBUTOR}`,
71 { removedUsersIds, addedUsersIds }
75 changeOwner({ itemId, ownerId }) {
76 return RestAPIUtil.put(
77 `${baseUrl()}/${itemId}/permissions/${permissionTypes.OWNER}`,
78 { removedUsersIds: [], addedUsersIds: [ownerId] }
82 async checkItemStatus(dispatch, { itemId, versionId }) {
83 const response = await ItemsHelper.fetchVersion({ itemId, versionId });
84 let state = (response && response.state) || {};
85 const { baseId, description, id, name, status } = response;
86 const item = await ItemsHelper.fetchItem(itemId);
88 type: onboardingActionTypes.UPDATE_ITEM_STATUS,
90 itemStatus: response.status,
91 archivedStatus: item.status,
92 updatedVersion: { baseId, description, id, name, status }
95 return Promise.resolve({ ...response, archivedStatus: item.status });
99 return RestAPIUtil.fetch(`${baseUrl()}/${itemId}`);
102 archiveItem(itemId) {
103 return RestAPIUtil.put(`${baseUrl()}/${itemId}/actions`, {
104 action: archiveActions.ARCHIVE
107 restoreItem(itemId) {
108 return RestAPIUtil.put(`${baseUrl()}/${itemId}/actions`, {
109 action: archiveActions.RESTORE
113 fetchItems(filterData) {
114 const str = objectPropsToUrlString(filterData);
115 return RestAPIUtil.fetch(`${baseUrl()}?${str}`);
119 export default ItemsHelper;