aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-ui/src/sdc-app/onboarding/permissions
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-ui/src/sdc-app/onboarding/permissions')
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js108
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js27
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js43
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx117
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js28
5 files changed, 323 insertions, 0 deletions
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js
new file mode 100644
index 0000000000..c25d93f2fc
--- /dev/null
+++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsActionHelper.js
@@ -0,0 +1,108 @@
+/*!
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+import i18n from 'nfvo-utils/i18n/i18n.js';
+import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
+import {actionTypes} from './PermissionsConstants.js';
+import {permissionTypes} from './PermissionsConstants.js';
+import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
+import {askForRightsMsg} from './PermissionsManager.jsx';
+import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js';
+
+const PermissionsActionHelper = {
+ openPermissonsManager(dispatch, {itemId, askForRights}) {
+ if (askForRights) {
+ dispatch({
+ type: modalActionTypes.GLOBAL_MODAL_SHOW,
+ data: {
+ title: i18n('Ask For Contributers Rights'),
+ msg: askForRightsMsg(),
+ confirmationButtonText: i18n('SEND'),
+ onConfirmed: () => this.askForContributorRights()
+ }
+ });
+ } else {
+ dispatch({
+ type: modalActionTypes.GLOBAL_MODAL_SHOW,
+ data: {
+ modalComponentName: modalContentMapper.MANAGE_PERMISSIONS,
+ title: i18n('Manage Permissions'),
+ modalComponentProps: {
+ itemId
+ }
+ }
+ });
+ }
+ },
+
+ closePermissionManager(dispatch) {
+ dispatch({
+ type: modalActionTypes.GLOBAL_MODAL_CLOSE
+ });
+ },
+
+ saveItemUsers(dispatch, {itemId, removedUsersIds, addedUsersIds, allUsers}) {
+ return ItemsHelper.updateContributors({itemId, removedUsersIds, addedUsersIds}).then(() =>
+ PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers})
+ );
+ },
+
+ changeOwner(dispatch, {itemId, newOwnerId, allUsers}) {
+ return ItemsHelper.changeOwner({itemId, ownerId: newOwnerId}).then(() =>
+ PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers})
+ );
+ },
+
+ fetchItemUsers(dispatch, {itemId, allUsers}) {
+ return ItemsHelper.fetchUsers({itemId}).then(response => {
+
+ let allContributors = response.results;
+
+ let owner = {};
+ let contributors = [];
+ allContributors.map(user => {
+ let userObject = allUsers.find(userObject => userObject.userId === user.userId);
+ if (userObject) {
+ user = {...user, fullName: userObject.fullName, role: userObject.role};
+
+ switch(user.permission) {
+ case permissionTypes.OWNER:
+ owner = user;
+ break;
+ case permissionTypes.CONTRIBUTOR:
+ contributors.push(user);
+ break;
+ }
+ }
+ });
+
+ dispatch({
+ type: actionTypes.ITEM_USERS_LOADED,
+ contributors,
+ owner
+ });
+ });
+ },
+
+ askForContributorRights() {
+ console.log('asked for contributor rights');
+ }
+
+
+
+};
+
+export default PermissionsActionHelper;
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js
new file mode 100644
index 0000000000..48a3461799
--- /dev/null
+++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsConstants.js
@@ -0,0 +1,27 @@
+/*!
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+import keyMirror from 'nfvo-utils/KeyMirror.js';
+
+export const actionTypes = keyMirror({
+ ITEM_USERS_LOADED: null
+});
+
+export const permissionTypes = {
+ OWNER: 'Owner',
+ CONTRIBUTOR: 'Contributor'
+};
+
+export const changeOwnerMessage = 'You will no longer be able to manage the permissions of this item.\nYour permission level will be set to contributor.';
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js
new file mode 100644
index 0000000000..ba6562b28f
--- /dev/null
+++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.js
@@ -0,0 +1,43 @@
+/*!
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+import {connect} from 'react-redux';
+import PermissionsManager from './PermissionsManager.jsx';
+import PermissionsActionHelper from './PermissionsActionHelper.js';
+
+export const mapStateToProps = ({versionsPage, users: {usersList, userInfo}}) => {
+ let {permissions} = versionsPage;
+
+ return {
+ users: usersList,
+ userInfo,
+ owner: permissions.owner,
+ itemUsers: permissions.contributors
+ };
+};
+
+const mapActionsToProps = (dispatch) => {
+ return {
+ onCancel: () => PermissionsActionHelper.closePermissionManager(dispatch),
+ onSubmit: ({itemId, addedUsersIds, removedUsersIds, allUsers, newOwnerId}) => {
+ return PermissionsActionHelper.saveItemUsers(dispatch,{itemId, addedUsersIds, removedUsersIds, allUsers}).then(() => {
+ return newOwnerId ? PermissionsActionHelper.changeOwner(dispatch, {itemId, newOwnerId, allUsers}) : Promise.resolve();
+ }).then(() => PermissionsActionHelper.closePermissionManager(dispatch));
+ }
+ };
+};
+
+export default connect(mapStateToProps, mapActionsToProps)(PermissionsManager);
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx
new file mode 100644
index 0000000000..b7d5d57cca
--- /dev/null
+++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsManager.jsx
@@ -0,0 +1,117 @@
+/*!
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+import React from 'react';
+import Form from 'nfvo-components/input/validation/Form.jsx';
+import Select from 'nfvo-components/input/SelectInput.jsx';
+import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
+import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
+import Tooltip from 'react-bootstrap/lib/Tooltip.js';
+import i18n from 'nfvo-utils/i18n/i18n.js';
+
+import {permissionTypes, changeOwnerMessage} from './PermissionsConstants.js';
+
+export const askForRightsMsg = () => {
+ return (
+ <div>
+ <p>{i18n('Send a Contributor rights reguest to Owner')}</p>
+ </div>
+ );
+};
+
+
+class Permissions extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ itemUsers: props.itemUsers,
+ newOwnerId: '',
+ showChangeOwner: false
+ };
+ }
+
+ buildUserOptions() {
+ let {users, owner} = this.props;
+ return users.filter(user => user.userId !== owner.userId).map(item => {return {label: item.fullName, value: item.userId};});
+ }
+
+ render() {
+ let {onCancel, owner} = this.props;
+ let {newOwnerId} = this.state;
+ return (
+ <div className='manage-permissions-page'>
+ <Form
+ hasButtons={true}
+ onSubmit={() => this.onsaveItemUsers()}
+ onReset={() => onCancel() }
+ labledButtons={true}>
+ <div className='manage-permissions-title'>{i18n('Owner')}</div>
+ <div className='owner-details'>
+ <span>{owner.fullName}</span>
+ <span className='change-owner' onClick={() => this.setState({showChangeOwner: !this.state.showChangeOwner})}>{i18n('Change Owner')}</span>
+ </div>
+ {this.state.showChangeOwner && <div className='change-owner-wrapper'>
+ <div className='change-owner-title'>
+ <span className='manage-permissions-title' data-test-id='change-owner'>{i18n('Change Owner')}</span>
+ <OverlayTrigger placement='right' trigger='click' overlay={
+ <Tooltip id='manage-permissions-owner-tooltip' className='manage-permissions-owner-tooltip'>{i18n(changeOwnerMessage)}</Tooltip> }>
+ <SVGIcon name='questionMark' />
+ </OverlayTrigger>
+ </div>
+ <Select
+ data-test-id='selected-owner'
+ value={newOwnerId}
+ onChange={(item) => this.setState({newOwnerId: item ? item.value : ''})}
+ options={this.buildUserOptions()} />
+ </div>}
+ <div className='manage-permissions-title'>{i18n('Contributors')}</div>
+ <Select
+ data-test-id='selected-contributors'
+ value={this.state.itemUsers.map(item => item.userId)}
+ className='options-input contributors-select'
+ clearable={false}
+ onMultiSelectChanged={(value) => {this.onChangeItemUsers({itemUsers: value});}}
+ options={this.buildUserOptions()}
+ multi/>
+ </Form>
+ </div>
+ );
+ }
+
+ onChangeItemUsers({itemUsers}) {
+ this.setState({
+ itemUsers: itemUsers.map(contributor => {
+ let contributorFromProps = this.props.itemUsers.find(user => user.userId === contributor.userId);
+ return {
+ userId: contributor.value,
+ fullName: contributor.label,
+ permission: contributorFromProps ? contributorFromProps.permission : permissionTypes.CONTRIBUTOR
+ };
+ })
+ });
+ }
+
+ onsaveItemUsers() {
+ let {itemUsers: newUsers, newOwnerId} = this.state;
+ let {itemUsers: oldUsers, onSubmit, itemId, users} = this.props;
+ let addedUsersIds = newUsers.filter(newUser => !oldUsers.map(oldUser => oldUser.userId).includes(newUser.userId))
+ .map(user => user.userId);
+ let removedUsersIds = oldUsers.filter(oldUser => !newUsers.map(newUser => newUser.userId).includes(oldUser.userId))
+ .map(user => user.userId);
+ onSubmit({itemId, addedUsersIds, removedUsersIds, allUsers: users, newOwnerId});
+ }
+}
+
+export default Permissions;
diff --git a/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js
new file mode 100644
index 0000000000..b4ab78964d
--- /dev/null
+++ b/openecomp-ui/src/sdc-app/onboarding/permissions/PermissionsReducer.js
@@ -0,0 +1,28 @@
+/*!
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+import {actionTypes} from './PermissionsConstants.js';
+
+export default (state = {}, action) => {
+ switch (action.type) {
+ case actionTypes.ITEM_USERS_LOADED:
+ return {
+ owner: action.owner,
+ contributors: action.contributors
+ };
+ default:
+ return state;
+ }
+}; \ No newline at end of file