},
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();
});
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');
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 => {
});
};
-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)
});
hasProvisionPermission: boolean,
onProjectCreate: () => void,
onVisibilityChange: string => void,
- organization?: Organization
+ organization: Organization
|};
type State = {
<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')}
</p>
{this.state.visibilityForm &&
- organization != null &&
<ChangeVisibilityForm
onClose={this.closeVisiblityForm}
onConfirm={this.props.onVisibilityChange}
hasProvisionPermission: boolean,
onVisibilityChange: string => void,
onRequestFail: Object => void,
- organization?: Organization
+ organization: Organization
|};
type State = {
}
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;
};
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);
});
static propTypes = {
projects: React.PropTypes.array.isRequired,
selection: React.PropTypes.array.isRequired,
- organization: React.PropTypes.object
+ organization: React.PropTypes.object.isRequired
};
componentWillMount() {