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 React from 'react';
17 import Form from 'nfvo-components/input/validation/Form.jsx';
18 import Select from 'nfvo-components/input/SelectInput.jsx';
19 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
20 import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
21 import Tooltip from 'react-bootstrap/lib/Tooltip.js';
22 import i18n from 'nfvo-utils/i18n/i18n.js';
24 import { permissionTypes, changeOwnerMessage } from './PermissionsConstants.js';
26 export const askForRightsMsg = () => {
29 <p>{i18n('Send a Contributor rights reguest to Owner')}</p>
34 class Permissions extends React.Component {
38 itemUsers: props.itemUsers,
40 showChangeOwner: false
45 let { users, owner } = this.props;
46 return users.filter(user => user.userId !== owner.userId).map(item => {
47 return { label: item.fullName, value: item.userId };
52 let { onCancel, owner } = this.props;
53 let { newOwnerId } = this.state;
55 <div className="manage-permissions-page">
58 onSubmit={() => this.onsaveItemUsers()}
59 onReset={() => onCancel()}
61 btnClassName="sdc-modal__footer">
62 <div className="manage-permissions-title">
65 <div className="owner-details">
66 <span>{owner.fullName}</span>
68 className="change-owner"
71 showChangeOwner: !this.state.showChangeOwner
74 {i18n('Change Owner')}
77 {this.state.showChangeOwner && (
78 <div className="change-owner-wrapper">
79 <div className="change-owner-title">
81 className="manage-permissions-title"
82 data-test-id="change-owner">
83 {i18n('Change Owner')}
90 id="manage-permissions-owner-tooltip"
91 className="manage-permissions-owner-tooltip">
92 {i18n(changeOwnerMessage)}
95 <SVGIcon name="questionMark" />
99 data-test-id="selected-owner"
103 newOwnerId: item ? item.value : ''
106 options={this.buildUserOptions()}
110 <div className="manage-permissions-title">
111 {i18n('Contributors')}
114 data-test-id="selected-contributors"
115 value={this.state.itemUsers.map(item => item.userId)}
116 className="options-input contributors-select"
118 onMultiSelectChanged={value => {
119 this.onChangeItemUsers({ itemUsers: value });
121 options={this.buildUserOptions()}
129 onChangeItemUsers({ itemUsers }) {
131 itemUsers: itemUsers.map(contributor => {
132 let contributorFromProps = this.props.itemUsers.find(
133 user => user.userId === contributor.userId
136 userId: contributor.value,
137 fullName: contributor.label,
138 permission: contributorFromProps
139 ? contributorFromProps.permission
140 : permissionTypes.CONTRIBUTOR
147 let { itemUsers: newUsers, newOwnerId } = this.state;
148 let { itemUsers: oldUsers, onSubmit, itemId, users } = this.props;
149 let addedUsersIds = newUsers
153 .map(oldUser => oldUser.userId)
154 .includes(newUser.userId)
156 .map(user => user.userId);
157 let removedUsersIds = oldUsers
161 .map(newUser => newUser.userId)
162 .includes(oldUser.userId)
164 .map(user => user.userId);
175 export default Permissions;