aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2017-01-31 13:46:14 +0100
committerStas Vilchik <stas-vilchik@users.noreply.github.com>2017-02-01 09:43:03 +0100
commita14a5717cd31d3358d5ba09b36696caf08518546 (patch)
tree5d444c08b851dddd280496175f332e7d3e9049d1 /server/sonar-web/src/main/js
parent2bb7dc7da6a7fe958d24c233844f5944edbdaf8d (diff)
downloadsonarqube-a14a5717cd31d3358d5ba09b36696caf08518546.tar.gz
sonarqube-a14a5717cd31d3358d5ba09b36696caf08518546.zip
SONAR-8658 Create organization's permission templates page
Diffstat (limited to 'server/sonar-web/src/main/js')
-rw-r--r--server/sonar-web/src/main/js/api/permissions.js42
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js18
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js46
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js8
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap9
-rw-r--r--server/sonar-web/src/main/js/apps/organizations/routes.js2
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.js26
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/App.js8
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/Header.js9
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/Home.js3
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/List.js5
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/ListItem.js3
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/NameCell.js9
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/Template.js26
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/components/TemplateHeader.js10
-rw-r--r--server/sonar-web/src/main/js/apps/permission-templates/views/CreateView.js8
16 files changed, 175 insertions, 57 deletions
diff --git a/server/sonar-web/src/main/js/api/permissions.js b/server/sonar-web/src/main/js/api/permissions.js
index e4d7f9b9b09..f498c3612d9 100644
--- a/server/sonar-web/src/main/js/api/permissions.js
+++ b/server/sonar-web/src/main/js/api/permissions.js
@@ -71,9 +71,9 @@ export function revokePermissionFromGroup (projectKey, groupName, permission) {
* Get list of permission templates
* @returns {Promise}
*/
-export function getPermissionTemplates () {
+export function getPermissionTemplates (organization) {
const url = '/api/permissions/search_templates';
- return getJSON(url);
+ return organization ? getJSON(url, { organization }) : getJSON(url);
}
export const createPermissionTemplate = data => (
@@ -90,13 +90,13 @@ export const deletePermissionTemplate = data => (
/**
* Set default permission template for a given qualifier
- * @param {string} templateName
+ * @param {string} templateId
* @param {string} qualifier
* @returns {Promise}
*/
-export function setDefaultPermissionTemplate (templateName, qualifier) {
+export function setDefaultPermissionTemplate (templateId, qualifier) {
const url = '/api/permissions/set_default_template';
- const data = { templateName, qualifier };
+ const data = { templateId, qualifier };
return post(url, data);
}
@@ -110,39 +110,37 @@ export function bulkApplyTemplate (data) {
return post(url, data);
}
-export function grantTemplatePermissionToUser (templateName, login, permission) {
+export function grantTemplatePermissionToUser (templateId, login, permission) {
const url = '/api/permissions/add_user_to_template';
- const data = { templateName, login, permission };
+ const data = { templateId, login, permission };
return post(url, data);
}
-export function revokeTemplatePermissionFromUser (templateName, login, permission) {
+export function revokeTemplatePermissionFromUser (templateId, login, permission) {
const url = '/api/permissions/remove_user_from_template';
- const data = { templateName, login, permission };
+ const data = { templateId, login, permission };
return post(url, data);
}
-export function grantTemplatePermissionToGroup (templateName, groupName, permission) {
+export function grantTemplatePermissionToGroup (data) {
const url = '/api/permissions/add_group_to_template';
- const data = { templateName, groupName, permission };
return post(url, data);
}
-export function revokeTemplatePermissionFromGroup (templateName, groupName, permission) {
+export function revokeTemplatePermissionFromGroup (data) {
const url = '/api/permissions/remove_group_from_template';
- const data = { templateName, groupName, permission };
return post(url, data);
}
-export function addProjectCreatorToTemplate (templateName, permission) {
+export function addProjectCreatorToTemplate (templateId, permission) {
const url = '/api/permissions/add_project_creator_to_template';
- const data = { templateName, permission };
+ const data = { templateId, permission };
return post(url, data);
}
-export function removeProjectCreatorFromTemplate (templateName, permission) {
+export function removeProjectCreatorFromTemplate (templateId, permission) {
const url = '/api/permissions/remove_project_creator_from_template';
- const data = { templateName, permission };
+ const data = { templateId, permission };
return post(url, data);
}
@@ -194,7 +192,7 @@ export function getGlobalPermissionsGroups (query = '', permission = null) {
return getJSON(url, data).then(r => r.groups);
}
-export function getPermissionTemplateUsers (templateId, query = '', permission = null) {
+export function getPermissionTemplateUsers (templateId, query = '', permission = null, organization = null) {
const url = '/api/permissions/template_users';
const data = { templateId, ps: PAGE_SIZE };
if (query) {
@@ -203,10 +201,13 @@ export function getPermissionTemplateUsers (templateId, query = '', permission =
if (permission) {
data.permission = permission;
}
+ if (organization) {
+ Object.assign(data, { organization });
+ }
return getJSON(url, data).then(r => r.users);
}
-export function getPermissionTemplateGroups (templateId, query = '', permission = null) {
+export function getPermissionTemplateGroups (templateId, query = '', permission = null, organization = null) {
const url = '/api/permissions/template_groups';
const data = { templateId, ps: PAGE_SIZE };
if (query) {
@@ -215,5 +216,8 @@ export function getPermissionTemplateGroups (templateId, query = '', permission
if (permission) {
data.permission = permission;
}
+ if (organization) {
+ Object.assign(data, { organization });
+ }
return getJSON(url, data).then(r => r.groups);
}
diff --git a/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js b/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js
index 417f89a1553..9879cec41d5 100644
--- a/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js
+++ b/server/sonar-web/src/main/js/app/components/nav/settings/SettingsNav.js
@@ -75,9 +75,9 @@ class SettingsNav extends React.Component {
<div className="container">
<ul className="nav navbar-nav nav-crumbs">
<li>
- <IndexLink to="/settings">
- {translate('layout.settings')}
- </IndexLink>
+ <IndexLink to="/settings">
+ {translate('layout.settings')}
+ </IndexLink>
</li>
</ul>
@@ -138,11 +138,13 @@ class SettingsNav extends React.Component {
{translate('global_permissions.page')}
</IndexLink>
</li>
- <li>
- <IndexLink to="/permission_templates" activeClassName="active">
- {translate('permission_templates')}
- </IndexLink>
- </li>
+ {!this.props.customOrganizations && (
+ <li>
+ <IndexLink to="/permission_templates" activeClassName="active">
+ {translate('permission_templates')}
+ </IndexLink>
+ </li>
+ )}
</ul>
</li>
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js
new file mode 100644
index 00000000000..614e2ec376a
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+// @flow
+import React from 'react';
+import { connect } from 'react-redux';
+import AppContainer from '../../permission-templates/components/AppContainer';
+import { getOrganizationByKey } from '../../../store/rootReducer';
+import type { Organization } from '../../../store/organizations/duck';
+
+class OrganizationPermissionTemplates extends React.Component {
+ props: {
+ location: {},
+ organization: Organization
+ };
+
+ render () {
+ return (
+ <AppContainer
+ location={this.props.location}
+ organization={this.props.organization}/>
+ );
+ }
+}
+
+const mapStateToProps = (state, ownProps) => ({
+ organization: getOrganizationByKey(state, ownProps.params.organizationKey)
+});
+
+export default connect(mapStateToProps)(OrganizationPermissionTemplates);
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js
index d9cfafeb5eb..8590e0e192f 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/OrganizationNavigation.js
@@ -25,7 +25,8 @@ import { translate } from '../../../helpers/l10n';
const ADMIN_PATHS = [
'edit',
'groups',
- 'delete'
+ 'delete',
+ 'permission_templates'
];
export default class OrganizationNavigation extends React.Component {
@@ -57,6 +58,11 @@ export default class OrganizationNavigation extends React.Component {
</Link>
</li>
<li>
+ <Link to={`/organizations/${organization.key}/permission_templates`} activeClassName="active">
+ {translate('permission_templates')}
+ </Link>
+ </li>
+ <li>
<Link to={`/organizations/${organization.key}/edit`} activeClassName="active">
{translate('edit')}
</Link>
diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap
index cd5ffee80cf..af802f0809d 100644
--- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap
+++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.js.snap
@@ -54,6 +54,15 @@ exports[`test admin 1`] = `
activeClassName="active"
onlyActiveOnIndex={false}
style={Object {}}
+ to="/organizations/foo/permission_templates">
+ permission_templates
+ </Link>
+ </li>
+ <li>
+ <Link
+ activeClassName="active"
+ onlyActiveOnIndex={false}
+ style={Object {}}
to="/organizations/foo/edit">
edit
</Link>
diff --git a/server/sonar-web/src/main/js/apps/organizations/routes.js b/server/sonar-web/src/main/js/apps/organizations/routes.js
index 3cf6dc9b3b1..909ffa400e3 100644
--- a/server/sonar-web/src/main/js/apps/organizations/routes.js
+++ b/server/sonar-web/src/main/js/apps/organizations/routes.js
@@ -23,6 +23,7 @@ import OrganizationPage from './components/OrganizationPage';
import OrganizationAdmin from './components/OrganizationAdmin';
import OrganizationEdit from './components/OrganizationEdit';
import OrganizationGroups from './components/OrganizationGroups';
+import OrganizationPermissionTemplates from './components/OrganizationPermissionTemplates';
import OrganizationDelete from './components/OrganizationDelete';
export default (
@@ -31,6 +32,7 @@ export default (
<Route path="delete" component={OrganizationDelete}/>
<Route path="edit" component={OrganizationEdit}/>
<Route path="groups" component={OrganizationGroups}/>
+ <Route path="permission_templates" component={OrganizationPermissionTemplates}/>
</Route>
</Route>
);
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.js b/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.js
index 88c034de322..1a0a97e38cf 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.js
@@ -30,6 +30,7 @@ import { setDefaultPermissionTemplate } from '../../../api/permissions';
export default class ActionsCell extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
permissionTemplate: PermissionTemplateType.isRequired,
topQualifiers: React.PropTypes.array.isRequired,
refresh: CallbackType,
@@ -57,7 +58,10 @@ export default class ActionsCell extends React.Component {
new DeleteView({
model: new Backbone.Model(this.props.permissionTemplate)
}).on('done', () => {
- this.context.router.replace('/permission_templates');
+ const pathname = this.props.organization ?
+ `/organizations/${this.props.organization.key}/permission_templates` :
+ '/permission_templates';
+ this.context.router.replace(pathname);
this.props.refresh();
}).render();
}
@@ -65,7 +69,7 @@ export default class ActionsCell extends React.Component {
setDefault (qualifier, e) {
e.preventDefault();
setDefaultPermissionTemplate(
- this.props.permissionTemplate.name,
+ this.props.permissionTemplate.id,
qualifier
).then(this.props.refresh);
}
@@ -137,7 +141,11 @@ export default class ActionsCell extends React.Component {
}
render () {
- const { permissionTemplate: t } = this.props;
+ const { permissionTemplate: t, organization } = this.props;
+
+ const pathname = organization ?
+ `/organizations/${organization.key}/permission_templates` :
+ '/permission_templates';
return (
<div className="dropdown">
@@ -151,12 +159,12 @@ export default class ActionsCell extends React.Component {
{this.renderSetDefaultsControl()}
{!this.props.fromDetails && (
- <li>
- <Link to={{ pathname: '/permission_templates', query: { id: t.id } }}>
- {this.renderDropdownIcon(<i className="icon-edit"/>)}
- Edit Permissions
- </Link>
- </li>
+ <li>
+ <Link to={{ pathname, query: { id: t.id } }}>
+ {this.renderDropdownIcon(<i className="icon-edit"/>)}
+ Edit Permissions
+ </Link>
+ </li>
)}
<li>
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/App.js b/server/sonar-web/src/main/js/apps/permission-templates/components/App.js
index 2263339753b..b5e494aa2ed 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/App.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/App.js
@@ -30,6 +30,8 @@ import '../../permissions/styles.css';
export default class App extends React.Component {
static propTypes = {
+ location: React.PropTypes.object.isRequired,
+ organization: React.PropTypes.object,
topQualifiers: React.PropTypes.array.isRequired
};
@@ -53,7 +55,9 @@ export default class App extends React.Component {
}
requestPermissions () {
- return getPermissionTemplates().then(r => {
+ const { organization } = this.props;
+ const request = organization ? getPermissionTemplates(organization.key) : getPermissionTemplates();
+ return request.then(r => {
if (this.mounted) {
const permissions = sortPermissions(r.permissions);
const permissionTemplates = mergeDefaultsToTemplates(
@@ -77,6 +81,7 @@ export default class App extends React.Component {
const template = this.state.permissionTemplates.find(t => t.id === id);
return (
<Template
+ organization={this.props.organization}
template={template}
refresh={this.requestPermissions}
topQualifiers={this.props.topQualifiers}/>
@@ -92,6 +97,7 @@ export default class App extends React.Component {
return (
<Home
+ organization={this.props.organization}
topQualifiers={this.props.topQualifiers}
permissions={this.state.permissions}
permissionTemplates={this.state.permissionTemplates}
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/Header.js b/server/sonar-web/src/main/js/apps/permission-templates/components/Header.js
index b0f66504edd..e36a7e51570 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/Header.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/Header.js
@@ -24,6 +24,7 @@ import { CallbackType } from '../propTypes';
export default class Header extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
ready: React.PropTypes.bool.isRequired,
refresh: CallbackType
};
@@ -38,11 +39,15 @@ export default class Header extends React.Component {
handleCreateClick (e) {
e.preventDefault();
+ const { organization } = this.props;
- new CreateView().on('done', r => {
+ new CreateView({ organization }).on('done', r => {
this.props.refresh().then(() => {
+ const pathname = organization ?
+ `/organizations/${organization.key}/permission_templates` :
+ '/permission_templates';
this.context.router.push({
- pathname: '/permission_templates',
+ pathname,
query: { id: r.permissionTemplate.id }
});
});
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/Home.js b/server/sonar-web/src/main/js/apps/permission-templates/components/Home.js
index c8871e2c4e7..516e1f28f76 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/Home.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/Home.js
@@ -26,6 +26,7 @@ import { translate } from '../../../helpers/l10n';
export default class Home extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
topQualifiers: React.PropTypes.array.isRequired,
permissions: React.PropTypes.array.isRequired,
permissionTemplates: React.PropTypes.array.isRequired,
@@ -41,11 +42,13 @@ export default class Home extends React.Component {
titleTemplate="SonarQube - %s"/>
<Header
+ organization={this.props.organization}
ready={this.props.ready}
refresh={this.props.refresh}/>
<TooltipsContainer>
<List
+ organization={this.props.organization}
permissionTemplates={this.props.permissionTemplates}
permissions={this.props.permissions}
topQualifiers={this.props.topQualifiers}
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/List.js b/server/sonar-web/src/main/js/apps/permission-templates/components/List.js
index 11ad4cd42a9..8fda434904a 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/List.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/List.js
@@ -24,6 +24,7 @@ import { PermissionTemplateType, CallbackType } from '../propTypes';
export default class List extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
permissionTemplates: React.PropTypes.arrayOf(
PermissionTemplateType).isRequired,
permissions: React.PropTypes.array.isRequired,
@@ -35,14 +36,14 @@ export default class List extends React.Component {
const permissionTemplates = this.props.permissionTemplates.map(p => (
<ListItem
key={p.id}
+ organization={this.props.organization}
permissionTemplate={p}
topQualifiers={this.props.topQualifiers}
refresh={this.props.refresh}/>
));
return (
- <table id="permission-templates"
- className="data zebra permissions-table">
+ <table id="permission-templates" className="data zebra permissions-table">
<ListHeader permissions={this.props.permissions}/>
<tbody>{permissionTemplates}</tbody>
</table>
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/ListItem.js b/server/sonar-web/src/main/js/apps/permission-templates/components/ListItem.js
index 6c27462183b..3dd1986efed 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/ListItem.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/ListItem.js
@@ -27,6 +27,7 @@ import { PermissionTemplateType, CallbackType } from '../propTypes';
export default class ListItem extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
permissionTemplate: PermissionTemplateType.isRequired,
topQualifiers: React.PropTypes.array.isRequired,
refresh: CallbackType
@@ -63,6 +64,7 @@ export default class ListItem extends React.Component {
data-id={this.props.permissionTemplate.id}
data-name={this.props.permissionTemplate.name}>
<NameCell
+ organization={this.props.organization}
permissionTemplate={this.props.permissionTemplate}
topQualifiers={this.props.topQualifiers}/>
@@ -70,6 +72,7 @@ export default class ListItem extends React.Component {
<td className="nowrap thin text-right">
<ActionsCell
+ organization={this.props.organization}
permissionTemplate={this.props.permissionTemplate}
topQualifiers={this.props.topQualifiers}
refresh={this.props.refresh}/>
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/NameCell.js b/server/sonar-web/src/main/js/apps/permission-templates/components/NameCell.js
index 78d1ded45ab..41379178da2 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/NameCell.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/NameCell.js
@@ -24,15 +24,20 @@ import { PermissionTemplateType } from '../propTypes';
export default class NameCell extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
permissionTemplate: PermissionTemplateType.isRequired
};
render () {
- const { permissionTemplate: t } = this.props;
+ const { permissionTemplate: t, organization } = this.props;
+
+ const pathname = organization ?
+ `/organizations/${organization.key}/permission_templates` :
+ '/permission_templates';
return (
<td>
- <Link to={{ pathname: '/permission_templates', query: { id: t.id } }}>
+ <Link to={{ pathname, query: { id: t.id } }}>
<strong className="js-name">{t.name}</strong>
</Link>
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/Template.js b/server/sonar-web/src/main/js/apps/permission-templates/components/Template.js
index 1639f5cb6c3..c37066308dc 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/Template.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/Template.js
@@ -31,6 +31,7 @@ import withStore from '../../../store/utils/withStore';
class Template extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
template: React.PropTypes.object.isRequired,
refresh: React.PropTypes.func.isRequired,
topQualifiers: React.PropTypes.array.isRequired
@@ -95,9 +96,9 @@ class Template extends React.Component {
const hasPermission = user.permissions.includes(permission);
const request = hasPermission ?
api.revokeTemplatePermissionFromUser(
- template.name, user.login, permission) :
+ template.id, user.login, permission) :
api.grantTemplatePermissionToUser(
- template.name, user.login, permission);
+ template.id, user.login, permission);
request.then(() => this.requestHolders()).then(this.props.refresh);
}
@@ -105,19 +106,25 @@ class Template extends React.Component {
const { template } = this.props;
const hasPermission = user.permissions.includes(permission);
const request = hasPermission ?
- api.removeProjectCreatorFromTemplate(template.name, permission) :
- api.addProjectCreatorToTemplate(template.name, permission);
+ api.removeProjectCreatorFromTemplate(template.id, permission) :
+ api.addProjectCreatorToTemplate(template.id, permission);
request.then(() => this.requestHolders()).then(this.props.refresh);
}
handleToggleGroup (group, permission) {
- const { template } = this.props;
+ const { template, organization } = this.props;
const hasPermission = group.permissions.includes(permission);
+ const data = {
+ templateId: template.id,
+ groupName: group.name,
+ permission
+ };
+ if (organization) {
+ Object.assign(data, { organization: organization.key });
+ }
const request = hasPermission ?
- api.revokeTemplatePermissionFromGroup(
- template.name, group.name, permission) :
- api.grantTemplatePermissionToGroup(
- template.name, group.name, permission);
+ api.revokeTemplatePermissionFromGroup(data) :
+ api.grantTemplatePermissionToGroup(data);
request.then(() => this.requestHolders()).then(this.props.refresh);
}
@@ -194,6 +201,7 @@ class Template extends React.Component {
titleTemplate="SonarQube - %s"/>
<TemplateHeader
+ organization={this.props.organization}
template={this.props.template}
loading={store.loading}
refresh={this.props.refresh}
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/TemplateHeader.js b/server/sonar-web/src/main/js/apps/permission-templates/components/TemplateHeader.js
index 57dd6349760..3de1362b3a4 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/components/TemplateHeader.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/components/TemplateHeader.js
@@ -24,6 +24,7 @@ import { translate } from '../../../helpers/l10n';
export default class TemplateHeader extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
template: React.PropTypes.object.isRequired,
loading: React.PropTypes.bool.isRequired,
refresh: React.PropTypes.func.isRequired,
@@ -31,12 +32,16 @@ export default class TemplateHeader extends React.Component {
};
render () {
- const { template } = this.props;
+ const { template, organization } = this.props;
+
+ const pathname = organization ?
+ `/organizations/${organization.key}/permission_templates` :
+ '/permission_templates';
return (
<header id="project-permissions-header" className="page-header">
<div className="note spacer-bottom">
- <Link to="/permission_templates" className="text-muted">
+ <Link to={pathname} className="text-muted">
{translate('permission_templates.page')}
</Link>
</div>
@@ -51,6 +56,7 @@ export default class TemplateHeader extends React.Component {
<div className="pull-right">
<ActionsCell
+ organization={this.props.organization}
permissionTemplate={this.props.template}
topQualifiers={this.props.topQualifiers}
refresh={this.props.refresh}
diff --git a/server/sonar-web/src/main/js/apps/permission-templates/views/CreateView.js b/server/sonar-web/src/main/js/apps/permission-templates/views/CreateView.js
index c444d48705d..a0cfc34da3a 100644
--- a/server/sonar-web/src/main/js/apps/permission-templates/views/CreateView.js
+++ b/server/sonar-web/src/main/js/apps/permission-templates/views/CreateView.js
@@ -24,11 +24,15 @@ import { parseError } from '../../code/utils';
export default FormView.extend({
sendRequest () {
this.disableForm();
- createPermissionTemplate({
+ const data = {
name: this.$('#permission-template-name').val(),
description: this.$('#permission-template-description').val(),
projectKeyPattern: this.$('#permission-template-project-key-pattern').val()
- }).then(
+ };
+ if (this.options.organization) {
+ Object.assign(data, { organization: this.options.organization.key });
+ }
+ createPermissionTemplate(data).then(
r => {
this.trigger('done', r);
this.destroy();