2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
19 import {actionTypes} from './PermissionsConstants.js';
20 import {permissionTypes} from './PermissionsConstants.js';
21 import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
22 import {askForRightsMsg} from './PermissionsManager.jsx';
23 import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js';
25 const PermissionsActionHelper = {
26 openPermissonsManager(dispatch, {itemId, askForRights}) {
29 type: modalActionTypes.GLOBAL_MODAL_SHOW,
31 title: i18n('Ask For Contributers Rights'),
32 msg: askForRightsMsg(),
33 confirmationButtonText: i18n('SEND'),
34 onConfirmed: () => this.askForContributorRights()
39 type: modalActionTypes.GLOBAL_MODAL_SHOW,
41 modalComponentName: modalContentMapper.MANAGE_PERMISSIONS,
42 title: i18n('Manage Permissions'),
43 modalComponentProps: {
51 closePermissionManager(dispatch) {
53 type: modalActionTypes.GLOBAL_MODAL_CLOSE
57 saveItemUsers(dispatch, {itemId, removedUsersIds, addedUsersIds, allUsers}) {
58 return ItemsHelper.updateContributors({itemId, removedUsersIds, addedUsersIds}).then(() =>
59 PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers})
63 changeOwner(dispatch, {itemId, newOwnerId, allUsers}) {
64 return ItemsHelper.changeOwner({itemId, ownerId: newOwnerId}).then(() =>
65 PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers})
69 fetchItemUsers(dispatch, {itemId, allUsers}) {
70 return ItemsHelper.fetchUsers({itemId}).then(response => {
72 let allContributors = response.results;
75 let contributors = [];
76 allContributors.map(user => {
77 let userObject = allUsers.find(userObject => userObject.userId === user.userId);
79 user = {...user, fullName: userObject.fullName, role: userObject.role};
81 switch(user.permission) {
82 case permissionTypes.OWNER:
85 case permissionTypes.CONTRIBUTOR:
86 contributors.push(user);
93 type: actionTypes.ITEM_USERS_LOADED,
100 askForContributorRights() {
101 console.log('asked for contributor rights');
108 export default PermissionsActionHelper;