* 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 { getJSON, post, postJSON } from '../helpers/request';
const PAGE_SIZE = 100;
-export function grantPermissionToUser (projectKey, login, permission, organization) {
+export function grantPermissionToUser (
+ projectKey: string | null,
+ login: string,
+ permission: string,
+ organization?: string
+) {
const url = '/api/permissions/add_user';
- const data = { login, permission };
+ const data: Object = { login, permission };
if (projectKey) {
data.projectKey = projectKey;
}
- if (organization) {
+ if (organization && !projectKey) {
data.organization = organization;
}
return post(url, data);
}
-export function revokePermissionFromUser (projectKey, login, permission, organization) {
+export function revokePermissionFromUser (
+ projectKey: string | null,
+ login: string,
+ permission: string,
+ organization?: string
+) {
const url = '/api/permissions/remove_user';
- const data = { login, permission };
+ const data: Object = { login, permission };
if (projectKey) {
data.projectKey = projectKey;
}
- if (organization) {
+ if (organization && !projectKey) {
data.organization = organization;
}
return post(url, data);
}
-export function grantPermissionToGroup (projectKey, groupName, permission, organization) {
+export function grantPermissionToGroup (
+ projectKey: string | null,
+ groupName: string,
+ permission: string,
+ organization?: string
+) {
const url = '/api/permissions/add_group';
- const data = { groupName, permission };
+ const data: Object = { groupName, permission };
if (projectKey) {
data.projectKey = projectKey;
}
return post(url, data);
}
-export function revokePermissionFromGroup (projectKey, groupName, permission, organization) {
+export function revokePermissionFromGroup (
+ projectKey: string | null,
+ groupName: string,
+ permission: string,
+ organization?: string
+) {
const url = '/api/permissions/remove_group';
- const data = { groupName, permission };
+ const data: Object = { groupName, permission };
if (projectKey) {
data.projectKey = projectKey;
}
* Get list of permission templates
* @returns {Promise}
*/
-export function getPermissionTemplates (organization) {
+export function getPermissionTemplates (organization?: string) {
const url = '/api/permissions/search_templates';
return organization ? getJSON(url, { organization }) : getJSON(url);
}
-export const createPermissionTemplate = data => (
+export const createPermissionTemplate = (data: Object) => (
postJSON('/api/permissions/create_template', data)
);
-export const updatePermissionTemplate = data => (
+export const updatePermissionTemplate = (data: Object) => (
post('/api/permissions/update_template', data)
);
-export const deletePermissionTemplate = data => (
+export const deletePermissionTemplate = (data: Object) => (
post('/api/permissions/delete_template', data)
);
* @param {string} qualifier
* @returns {Promise}
*/
-export function setDefaultPermissionTemplate (templateId, qualifier) {
+export function setDefaultPermissionTemplate (templateId: string, qualifier: string) {
const url = '/api/permissions/set_default_template';
const data = { templateId, qualifier };
return post(url, data);
}
-export function applyTemplateToProject (data) {
+export function applyTemplateToProject (data: Object) {
const url = '/api/permissions/apply_template';
return post(url, data);
}
-export function bulkApplyTemplate (data) {
+export function bulkApplyTemplate (data: Object) {
const url = '/api/permissions/bulk_apply_template';
return post(url, data);
}
-export function grantTemplatePermissionToUser (templateId, login, permission) {
+export function grantTemplatePermissionToUser (templateId: string, login: string, permission: string) {
const url = '/api/permissions/add_user_to_template';
const data = { templateId, login, permission };
return post(url, data);
}
-export function revokeTemplatePermissionFromUser (templateId, login, permission) {
+export function revokeTemplatePermissionFromUser (templateId: string, login: string, permission: string) {
const url = '/api/permissions/remove_user_from_template';
const data = { templateId, login, permission };
return post(url, data);
}
-export function grantTemplatePermissionToGroup (data) {
+export function grantTemplatePermissionToGroup (data: Object) {
const url = '/api/permissions/add_group_to_template';
return post(url, data);
}
-export function revokeTemplatePermissionFromGroup (data) {
+export function revokeTemplatePermissionFromGroup (data: Object) {
const url = '/api/permissions/remove_group_from_template';
return post(url, data);
}
-export function addProjectCreatorToTemplate (templateId, permission) {
+export function addProjectCreatorToTemplate (templateId: string, permission: string) {
const url = '/api/permissions/add_project_creator_to_template';
const data = { templateId, permission };
return post(url, data);
}
-export function removeProjectCreatorFromTemplate (templateId, permission) {
+export function removeProjectCreatorFromTemplate (templateId: string, permission: string) {
const url = '/api/permissions/remove_project_creator_from_template';
const data = { templateId, permission };
return post(url, data);
}
-export function getPermissionsUsersForComponent (projectKey, query = '', permission = null, organization = null) {
+export function getPermissionsUsersForComponent (
+ projectKey: string,
+ query?: string,
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/users';
- const data = { projectKey, ps: PAGE_SIZE };
+ const data: Object = { projectKey, ps: PAGE_SIZE };
if (query) {
data.q = query;
}
return getJSON(url, data).then(r => r.users);
}
-export function getPermissionsGroupsForComponent (projectKey, query = '', permission = null, organization = null) {
+export function getPermissionsGroupsForComponent (
+ projectKey: string,
+ query: string = '',
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/groups';
- const data = { projectKey, ps: PAGE_SIZE };
+ const data: Object = { projectKey, ps: PAGE_SIZE };
if (query) {
data.q = query;
}
return getJSON(url, data).then(r => r.groups);
}
-export function getGlobalPermissionsUsers (query = '', permission = null, organization = null) {
+export function getGlobalPermissionsUsers (
+ query?: string,
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/users';
- const data = { ps: PAGE_SIZE };
+ const data: Object = { ps: PAGE_SIZE };
if (query) {
data.q = query;
}
return getJSON(url, data).then(r => r.users);
}
-export function getGlobalPermissionsGroups (query = '', permission = null, organization = null) {
+export function getGlobalPermissionsGroups (
+ query?: string,
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/groups';
- const data = { ps: PAGE_SIZE };
+ const data: Object = { ps: PAGE_SIZE };
if (query) {
data.q = query;
}
return getJSON(url, data).then(r => r.groups);
}
-export function getPermissionTemplateUsers (templateId, query = '', permission = null, organization = null) {
+export function getPermissionTemplateUsers (
+ templateId: string,
+ query?: string,
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/template_users';
- const data = { templateId, ps: PAGE_SIZE };
+ const data: Object = { templateId, ps: PAGE_SIZE };
if (query) {
data.q = query;
}
return getJSON(url, data).then(r => r.users);
}
-export function getPermissionTemplateGroups (templateId, query = '', permission = null, organization = null) {
+export function getPermissionTemplateGroups (
+ templateId: string,
+ query?: string,
+ permission?: string,
+ organization?: string
+) {
const url = '/api/permissions/template_groups';
- const data = { templateId, ps: PAGE_SIZE };
+ const data: Object = { templateId, ps: PAGE_SIZE };
if (query) {
data.q = query;
}
</li>
<li>
<Link to={`/organizations/${organization.key}/permissions`} activeClassName="active">
- {translate('permissions')}
+ {translate('permissions.page')}
</Link>
</li>
<li>
onlyActiveOnIndex={false}
style={Object {}}
to="/organizations/foo/permissions">
- permissions
+ permissions.page
</Link>
</li>
<li>
* 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 SearchForm from '../../shared/components/SearchForm';
selectedPermission: getPermissionsAppSelectedPermission(state)
});
-const mapDispatchToProps = (dispatch, ownProps) => ({
- loadHolders: () => dispatch(loadHolders(ownProps.organization)),
- onSearch: query => dispatch(updateQuery(query, ownProps.organization)),
- onFilter: filter => dispatch(updateFilter(filter, ownProps.organization)),
- onSelectPermission: permission => dispatch(selectPermission(permission, ownProps.organization)),
- grantPermissionToUser: (login, permission) =>
- dispatch(grantToUser(login, permission, ownProps.organization)),
- revokePermissionFromUser: (login, permission) =>
- dispatch(revokeFromUser(login, permission, ownProps.organization)),
- grantPermissionToGroup: (groupName, permission) =>
- dispatch(grantToGroup(groupName, permission, ownProps.organization)),
- revokePermissionFromGroup: (groupName, permission) =>
- dispatch(revokeFromGroup(groupName, permission, ownProps.organization))
-});
+type OwnProps = {
+ organization?: { key: string }
+};
+
+const mapDispatchToProps = (dispatch, ownProps: OwnProps) => {
+ const organizationKey = ownProps.organization ? ownProps.organization.key : undefined;
+ return {
+ loadHolders: () => dispatch(loadHolders(organizationKey)),
+ onSearch: query => dispatch(updateQuery(query, organizationKey)),
+ onFilter: filter => dispatch(updateFilter(filter, organizationKey)),
+ onSelectPermission: permission => dispatch(selectPermission(permission, organizationKey)),
+ grantPermissionToUser: (login, permission) =>
+ dispatch(grantToUser(login, permission, organizationKey)),
+ revokePermissionFromUser: (login, permission) =>
+ dispatch(revokeFromUser(login, permission, organizationKey)),
+ grantPermissionToGroup: (groupName, permission) =>
+ dispatch(grantToGroup(groupName, permission, organizationKey)),
+ revokePermissionFromGroup: (groupName, permission) =>
+ dispatch(revokeFromGroup(groupName, permission, organizationKey))
+ };
+};
export default connect(
mapStateToProps,
render () {
return (
<div className="page page-limited">
- <PageHeader/>
+ <PageHeader organization={this.props.organization}/>
<PageError/>
<AllHoldersList organization={this.props.organization}/>
</div>
import { isPermissionsAppLoading } from '../../../../store/rootReducer';
class PageHeader extends React.Component {
- static propTypes = {
- loading: React.PropTypes.bool
+ props: {
+ loading?: boolean,
+ organization?: {}
};
static defaultProps = {
};
render () {
+ const title = this.props.organization ?
+ translate('permissions.page') :
+ translate('global_permissions.page');
+
+ const description = this.props.organization ?
+ translate('organization_permissions.page.description') :
+ translate('global_permissions.page.description');
+
return (
<header className="page-header">
- <h1 className="page-title">
- {translate('global_permissions.page')}
- </h1>
+ <h1 className="page-title">{title}</h1>
{this.props.loading && (
<i className="spinner"/>
)}
- <div className="page-description">
- {translate('global_permissions.page.description')}
- </div>
+ <div className="page-description">{description}</div>
</header>
);
}
* 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 * as api from '../../../../api/permissions';
import { parseError } from '../../../code/utils';
import {
getPermissionsAppSelectedPermission
} from '../../../../store/rootReducer';
-export const loadHolders = organization => (dispatch, getState) => {
+type Dispatch = (Object) => void;
+type GetState = () => Object;
+
+export const loadHolders = (organization?: string) => (dispatch: Dispatch, getState: GetState) => {
const query = getPermissionsAppQuery(getState());
const filter = getPermissionsAppFilter(getState());
const selectedPermission = getPermissionsAppSelectedPermission(getState());
});
};
-export const updateQuery = (query = '', organization) => dispatch => {
+export const updateQuery = (query: string = '', organization?: string) => (dispatch: Dispatch) => {
dispatch({ type: UPDATE_QUERY, query });
if (query.length === 0 || query.length > 2) {
dispatch(loadHolders(organization));
}
};
-export const updateFilter = (filter, organization) => dispatch => {
+export const updateFilter = (filter: string, organization?: string) => (dispatch: Dispatch) => {
dispatch({ type: UPDATE_FILTER, filter });
dispatch(loadHolders(organization));
};
-export const selectPermission = (permission, organization) => (dispatch, getState) => {
- const selectedPermission = getPermissionsAppSelectedPermission(getState());
- if (selectedPermission !== permission) {
- dispatch({ type: SELECT_PERMISSION, permission });
- } else {
- dispatch({ type: SELECT_PERMISSION, permission: null });
- }
- dispatch(loadHolders(organization));
-};
+export const selectPermission = (permission: string, organization?: string) =>
+ (dispatch: Dispatch, getState: GetState) => {
+ const selectedPermission = getPermissionsAppSelectedPermission(getState());
+ if (selectedPermission !== permission) {
+ dispatch({ type: SELECT_PERMISSION, permission });
+ } else {
+ dispatch({ type: SELECT_PERMISSION, permission: null });
+ }
+ dispatch(loadHolders(organization));
+ };
-export const grantToUser = (login, permission, organization) => dispatch => {
- api.grantPermissionToUser(null, login, permission, organization).then(() => {
- dispatch({ type: GRANT_PERMISSION_TO_USER, login, permission });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const grantToUser = (login: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.grantPermissionToUser(null, login, permission, organization).then(() => {
+ dispatch({ type: GRANT_PERMISSION_TO_USER, login, permission });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
-export const revokeFromUser = (login, permission, organization) => dispatch => {
- api.revokePermissionFromUser(null, login, permission, organization).then(() => {
- dispatch({ type: REVOKE_PERMISSION_TO_USER, login, permission });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const revokeFromUser = (login: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.revokePermissionFromUser(null, login, permission, organization).then(() => {
+ dispatch({ type: REVOKE_PERMISSION_TO_USER, login, permission });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
-export const grantToGroup = (groupName, permission, organization) => dispatch => {
- api.grantPermissionToGroup(null, groupName, permission, organization).then(() => {
- dispatch({
- type: GRANT_PERMISSION_TO_GROUP,
- groupName,
- permission
- });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const grantToGroup = (groupName: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.grantPermissionToGroup(null, groupName, permission, organization).then(() => {
+ dispatch({
+ type: GRANT_PERMISSION_TO_GROUP,
+ groupName,
+ permission
+ });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
-export const revokeFromGroup = (groupName, permission, organization) => dispatch => {
- api.revokePermissionFromGroup(null, groupName, permission, organization).then(() => {
- dispatch({
- type: REVOKE_PERMISSION_FROM_GROUP,
- groupName,
- permission
- });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const revokeFromGroup = (groupName: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.revokePermissionFromGroup(null, groupName, permission, organization).then(() => {
+ dispatch({
+ type: REVOKE_PERMISSION_FROM_GROUP,
+ groupName,
+ permission
+ });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
* 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 SearchForm from '../../shared/components/SearchForm';
selectedPermission: getPermissionsAppSelectedPermission(state)
});
-const mapDispatchToProps = (dispatch, ownProps) => ({
+type OwnProps = {
+ project: {
+ organization?: string
+ }
+};
+
+const mapDispatchToProps = (dispatch, ownProps: OwnProps) => ({
loadHolders: projectKey => dispatch(loadHolders(projectKey, ownProps.project.organization)),
onSearch: (projectKey, query) => dispatch(updateQuery(projectKey, query, ownProps.project.organization)),
onFilter: (projectKey, filter) => dispatch(updateFilter(projectKey, filter, ownProps.project.organization)),
* 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 * as api from '../../../../api/permissions';
import { parseError } from '../../../code/utils';
import {
getPermissionsAppSelectedPermission
} from '../../../../store/rootReducer';
-export const loadHolders = (projectKey, organization) => (dispatch, getState) => {
- const query = getPermissionsAppQuery(getState());
- const filter = getPermissionsAppFilter(getState());
- const selectedPermission = getPermissionsAppSelectedPermission(getState());
+type Dispatch = (Object) => void;
+type GetState = () => Object;
- dispatch({ type: REQUEST_HOLDERS, query });
+export const loadHolders = (project: string, organization?: string) =>
+ (dispatch: Dispatch, getState: GetState) => {
+ const query = getPermissionsAppQuery(getState());
+ const filter = getPermissionsAppFilter(getState());
+ const selectedPermission = getPermissionsAppSelectedPermission(getState());
- const requests = [];
+ dispatch({ type: REQUEST_HOLDERS, query });
- if (filter !== 'groups') {
- requests.push(api.getPermissionsUsersForComponent(projectKey, query, selectedPermission, organization));
- } else {
- requests.push(Promise.resolve([]));
- }
+ const requests = [];
- if (filter !== 'users') {
- requests.push(api.getPermissionsGroupsForComponent(projectKey, query, selectedPermission, organization));
- } else {
- requests.push(Promise.resolve([]));
- }
+ if (filter !== 'groups') {
+ requests.push(api.getPermissionsUsersForComponent(project, query, selectedPermission, organization));
+ } else {
+ requests.push(Promise.resolve([]));
+ }
- return Promise.all(requests).then(responses => (
- dispatch({
- type: RECEIVE_HOLDERS_SUCCESS,
- users: responses[0],
- groups: responses[1],
- query
- })
- )).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+ if (filter !== 'users') {
+ requests.push(api.getPermissionsGroupsForComponent(project, query, selectedPermission, organization));
+ } else {
+ requests.push(Promise.resolve([]));
+ }
-export const updateQuery = (projectKey, query = '', organization = null) => dispatch => {
- dispatch({ type: UPDATE_QUERY, query });
- if (query.length === 0 || query.length > 2) {
- dispatch(loadHolders(projectKey, organization));
- }
-};
+ return Promise.all(requests).then(responses => (
+ dispatch({
+ type: RECEIVE_HOLDERS_SUCCESS,
+ users: responses[0],
+ groups: responses[1],
+ query
+ })
+ )).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
-export const updateFilter = (projectKey, filter, organization) => dispatch => {
- dispatch({ type: UPDATE_FILTER, filter });
- dispatch(loadHolders(projectKey, organization));
-};
+export const updateQuery = (project: string, query: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ dispatch({ type: UPDATE_QUERY, query });
+ if (query.length === 0 || query.length > 2) {
+ dispatch(loadHolders(project, organization));
+ }
+ };
-export const selectPermission = (projectKey, permission, organization) => (dispatch, getState) => {
- const selectedPermission = getPermissionsAppSelectedPermission(getState());
- if (selectedPermission !== permission) {
- dispatch({ type: SELECT_PERMISSION, permission });
- } else {
- dispatch({ type: SELECT_PERMISSION, permission: null });
- }
- dispatch(loadHolders(projectKey, organization));
-};
+export const updateFilter = (project: string, filter: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ dispatch({ type: UPDATE_FILTER, filter });
+ dispatch(loadHolders(project, organization));
+ };
-export const grantToUser = (projectKey, login, permission, organization) => dispatch => {
- api.grantPermissionToUser(projectKey, login, permission, organization).then(() => {
- dispatch({ type: GRANT_PERMISSION_TO_USER, login, permission });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const selectPermission = (project: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch, getState: GetState) => {
+ const selectedPermission = getPermissionsAppSelectedPermission(getState());
+ if (selectedPermission !== permission) {
+ dispatch({ type: SELECT_PERMISSION, permission });
+ } else {
+ dispatch({ type: SELECT_PERMISSION, permission: null });
+ }
+ dispatch(loadHolders(project, organization));
+ };
-export const revokeFromUser = (projectKey, login, permission, organization) => dispatch => {
- api.revokePermissionFromUser(projectKey, login, permission, organization).then(() => {
- dispatch({ type: REVOKE_PERMISSION_TO_USER, login, permission });
- }).catch(e => {
- return parseError(e).then(message => dispatch(raiseError(message)));
- });
-};
+export const grantToUser = (project: string, login: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.grantPermissionToUser(project, login, permission, organization).then(() => {
+ dispatch({ type: GRANT_PERMISSION_TO_USER, login, permission });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
+
+export const revokeFromUser = (project: string, login: string, permission: string, organization?: string) =>
+ (dispatch: Dispatch) => {
+ api.revokePermissionFromUser(project, login, permission, organization).then(() => {
+ dispatch({ type: REVOKE_PERMISSION_TO_USER, login, permission });
+ }).catch(e => {
+ return parseError(e).then(message => dispatch(raiseError(message)));
+ });
+ };
-export const grantToGroup = (projectKey, groupName, permission, organization) => dispatch => {
- api.grantPermissionToGroup(projectKey, groupName, permission, organization).then(() => {
+export const grantToGroup = (
+ project: string,
+ groupName: string,
+ permission: string,
+ organization?: string
+) => (dispatch: Dispatch) => {
+ api.grantPermissionToGroup(project, groupName, permission, organization).then(() => {
dispatch({
type: GRANT_PERMISSION_TO_GROUP,
groupName,
});
};
-export const revokeFromGroup = (projectKey, groupName, permission, organization) => dispatch => {
- api.revokePermissionFromGroup(projectKey, groupName, permission, organization).then(() => {
+export const revokeFromGroup = (
+ project: string,
+ groupName: string,
+ permission: string,
+ organization?: string
+) => (dispatch: Dispatch) => {
+ api.revokePermissionFromGroup(project, groupName, permission, organization).then(() => {
dispatch({
type: REVOKE_PERMISSION_FROM_GROUP,
groupName,
manual_measures.page.description=Update the values of manual metrics for this project. Changes will take effect at the project's next analysis. Manual Metrics must be created at the global level.
custom_measures.page=Custom Measures
custom_measures.page.description=Update the values of custom metrics for this project. Changes will take effect at the project's next analysis. Custom metrics must be created at the global level.
+organization_permissions.page.description=Grant and revoke organization permissions. Permissions can be granted to groups or individual users.
roles.page=Project Permissions
roles.page.description2=Grant and revoke project-level permissions. Permissions can be granted to groups or individual users.
project_settings.page=General Settings