diff options
author | Stas Vilchik <stas-vilchik@users.noreply.github.com> | 2017-05-05 14:11:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-05 14:11:22 +0200 |
commit | d4818eaa39ec76bf2ed14a14204741928bf1a9d6 (patch) | |
tree | 70886bb2c1124f2ead6c35f6693ce4f362dcd27b | |
parent | c02711383a37622cb43f637312167e1ba3d61ab4 (diff) | |
download | sonarqube-d4818eaa39ec76bf2ed14a14204741928bf1a9d6.tar.gz sonarqube-d4818eaa39ec76bf2ed14a14204741928bf1a9d6.zip |
SONAR-9166 allow to change default project visibility on-premise (#2022)
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 ( - <Main - hasProvisionPermission={hasProvisionPermission} - topLevelQualifiers={topLevelQualifiers} - onVisibilityChange={props.onVisibilityChange} - onRequestFail={props.onRequestFail} - organization={props.organization} - /> - ); + 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 ( + <Main + hasProvisionPermission={organization.canProvisionProjects} + topLevelQualifiers={topLevelQualifiers} + onVisibilityChange={this.handleVisibilityChange} + onRequestFail={this.props.onRequestFail} + organization={organization} + /> + ); + } } -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 { <header className="page-header"> <h1 className="page-title">{translate('projects_management')}</h1> <div className="page-actions"> - {organization != null && - <span className="big-spacer-right"> - {translate('organization.default_visibility_of_new_projects')} - {' '} - <strong> - {translate('visibility', organization.projectVisibility)} - </strong> - <a - className="spacer-left icon-edit" - href="#" - onClick={this.handleChangeVisibilityClick} - /> - </span>} + <span className="big-spacer-right"> + {translate('organization.default_visibility_of_new_projects')} + {' '} + <strong> + {translate('visibility', organization.projectVisibility)} + </strong> + <a + className="spacer-left icon-edit" + href="#" + onClick={this.handleChangeVisibilityClick} + /> + </span> {this.props.hasProvisionPermission && <button id="create-project" onClick={this.handleCreateProjectClick}> {translate('qualifiers.create.TRK')} @@ -82,7 +81,6 @@ export default class Header extends React.PureComponent { </p> {this.state.visibilityForm && - organization != null && <ChangeVisibilityForm onClose={this.closeVisiblityForm} onConfirm={this.props.onVisibilityChange} diff --git a/server/sonar-web/src/main/js/apps/projects-admin/main.js b/server/sonar-web/src/main/js/apps/projects-admin/main.js index 3d6a154acf8..cb1c99b30f3 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/main.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/main.js @@ -33,7 +33,7 @@ type Props = {| hasProvisionPermission: boolean, onVisibilityChange: string => void, onRequestFail: Object => void, - organization?: Organization + organization: Organization |}; type State = { @@ -73,16 +73,16 @@ export default class Main extends React.PureComponent { } getFilters = () => { - const filters: { [string]: string | number } = { ps: PAGE_SIZE }; + const filters: { [string]: string | number } = { + organization: this.props.organization.key, + ps: PAGE_SIZE + }; if (this.state.page !== 1) { filters.p = this.state.page; } if (this.state.query) { filters.q = this.state.query; } - if (this.props.organization) { - filters.organization = this.props.organization.key; - } return filters; }; @@ -211,10 +211,10 @@ export default class Main extends React.PureComponent { deleteProjects = () => { this.setState({ ready: false }); const projects = this.state.selection.join(','); - const data = { projects }; - if (this.props.organization) { - Object.assign(data, { organization: this.props.organization.key }); - } + const data = { + organization: this.props.organization.key, + projects + }; deleteComponents(data).then(() => { this.setState({ page: 1, selection: [] }, this.requestProjects); }); diff --git a/server/sonar-web/src/main/js/apps/projects-admin/projects.js b/server/sonar-web/src/main/js/apps/projects-admin/projects.js index bc1f94eda63..cbf2aab4a72 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/projects.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/projects.js @@ -31,7 +31,7 @@ export default class Projects extends React.PureComponent { static propTypes = { projects: React.PropTypes.array.isRequired, selection: React.PropTypes.array.isRequired, - organization: React.PropTypes.object + organization: React.PropTypes.object.isRequired }; componentWillMount() { |