From d4818eaa39ec76bf2ed14a14204741928bf1a9d6 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 5 May 2017 14:11:22 +0200 Subject: [PATCH] SONAR-9166 allow to change default project visibility on-premise (#2022) --- .../project/views/ApplyTemplateView.js | 9 +-- .../js/apps/projects-admin/AppContainer.js | 67 ++++++++++++------- .../src/main/js/apps/projects-admin/header.js | 28 ++++---- .../src/main/js/apps/projects-admin/main.js | 18 ++--- .../main/js/apps/projects-admin/projects.js | 2 +- 5 files changed, 69 insertions(+), 55 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/permissions/project/views/ApplyTemplateView.js b/server/sonar-web/src/main/js/apps/permissions/project/views/ApplyTemplateView.js index 07e5da1482d..a7c8c972d0b 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/views/ApplyTemplateView.js +++ b/server/sonar-web/src/main/js/apps/permissions/project/views/ApplyTemplateView.js @@ -30,10 +30,7 @@ export default ModalForm.extend({ }, loadPermissionTemplates() { - const request = this.options.organization - ? getPermissionTemplates(this.options.organization.key) - : getPermissionTemplates(); - return request.then(r => { + return getPermissionTemplates(this.options.organization.key).then(r => { this.permissionTemplates = r.permissionTemplates; this.render(); }); @@ -53,12 +50,10 @@ export default ModalForm.extend({ this.disableForm(); const data = { + organization: this.options.organization.key, projectKey: this.options.project.key, templateId: permissionTemplate }; - if (this.options.organization) { - data.organization = this.options.organization.key; - } applyTemplateToProject(data) .then(() => { this.trigger('done'); diff --git a/server/sonar-web/src/main/js/apps/projects-admin/AppContainer.js b/server/sonar-web/src/main/js/apps/projects-admin/AppContainer.js index 98bbe16a4f8..69f890b5caa 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/AppContainer.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/AppContainer.js @@ -21,34 +21,53 @@ import React from 'react'; import { connect } from 'react-redux'; import Main from './main'; import { onFail } from '../../store/rootActions'; -import { getCurrentUser, getAppState } from '../../store/rootReducer'; -import { getRootQualifiers } from '../../store/appState/duck'; +import { getAppState, getOrganizationByKey } from '../../store/rootReducer'; import { receiveOrganizations } from '../../store/organizations/duck'; import { changeProjectVisibility } from '../../api/organizations'; +import { fetchOrganization } from '../../apps/organizations/actions'; -function AppContainer(props) { - const hasProvisionPermission = props.organization - ? props.organization.canProvisionProjects - : props.user.permissions.global.indexOf('provisioning') !== -1; +class AppContainer extends React.PureComponent { + componentDidMount() { + // if there is no organization, that means we are in the global scope + // let's fetch defails for the default organization in this case + if (!this.props.organization || !this.props.organization.projectVisibility) { + this.props.fetchOrganization(this.props.appState.defaultOrganization); + } + } - const topLevelQualifiers = props.organization && !props.organization.isDefault - ? ['TRK'] - : props.rootQualifiers; + componentWillUnmount() { + this.mounted = false; + } - return ( -
- ); + handleVisibilityChange = visibility => { + this.props.onVisibilityChange(this.props.organization, visibility); + }; + + render() { + const { organization } = this.props; + + if (!organization) { + return null; + } + + const topLevelQualifiers = organization.isDefault ? this.props.appState.qualifiers : ['TRK']; + + return ( +
+ ); + } } -const mapStateToProps = state => ({ - rootQualifiers: getRootQualifiers(getAppState(state)), - user: getCurrentUser(state) +const mapStateToProps = (state, ownProps) => ({ + appState: getAppState(state), + organization: ownProps.organization || + getOrganizationByKey(state, getAppState(state).defaultOrganization) }); const onVisibilityChange = (organization, visibility) => dispatch => { @@ -60,8 +79,10 @@ const onVisibilityChange = (organization, visibility) => dispatch => { }); }; -const mapDispatchToProps = (dispatch, ownProps) => ({ - onVisibilityChange: visibility => dispatch(onVisibilityChange(ownProps.organization, visibility)), +const mapDispatchToProps = dispatch => ({ + fetchOrganization: key => dispatch(fetchOrganization(key)), + onVisibilityChange: (organization, visibility) => + dispatch(onVisibilityChange(organization, visibility)), onRequestFail: error => onFail(dispatch)(error) }); diff --git a/server/sonar-web/src/main/js/apps/projects-admin/header.js b/server/sonar-web/src/main/js/apps/projects-admin/header.js index a6171607dc8..f0b23d0ef61 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/header.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/header.js @@ -27,7 +27,7 @@ type Props = {| hasProvisionPermission: boolean, onProjectCreate: () => void, onVisibilityChange: string => void, - organization?: Organization + organization: Organization |}; type State = { @@ -59,19 +59,18 @@ export default class Header extends React.PureComponent {

{translate('projects_management')}

- {organization != null && - - {translate('organization.default_visibility_of_new_projects')} - {' '} - - {translate('visibility', organization.projectVisibility)} - - - } + + {translate('organization.default_visibility_of_new_projects')} + {' '} + + {translate('visibility', organization.projectVisibility)} + + + {this.props.hasProvisionPermission &&