From: Stas Vilchik Date: Fri, 3 Feb 2017 09:55:49 +0000 (+0100) Subject: refactor and add type annonations around permissions domain X-Git-Tag: 6.3-RC1~230 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b7b89cce83baa7bdd3254ee09befb775522452c3;p=sonarqube.git refactor and add type annonations around permissions domain --- diff --git a/server/sonar-web/src/main/js/api/permissions.js b/server/sonar-web/src/main/js/api/permissions.js index 0496d8fa719..6cc97fe0a83 100644 --- a/server/sonar-web/src/main/js/api/permissions.js +++ b/server/sonar-web/src/main/js/api/permissions.js @@ -17,37 +17,53 @@ * 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; } @@ -57,9 +73,14 @@ export function grantPermissionToGroup (projectKey, groupName, permission, organ 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; } @@ -73,20 +94,20 @@ export function revokePermissionFromGroup (projectKey, groupName, permission, or * 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) ); @@ -96,59 +117,64 @@ export const deletePermissionTemplate = 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; } @@ -161,9 +187,14 @@ export function getPermissionsUsersForComponent (projectKey, query = '', permiss 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; } @@ -176,9 +207,13 @@ export function getPermissionsGroupsForComponent (projectKey, query = '', permis 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; } @@ -191,9 +226,13 @@ export function getGlobalPermissionsUsers (query = '', permission = null, organi 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; } @@ -206,9 +245,14 @@ export function getGlobalPermissionsGroups (query = '', permission = null, organ 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; } @@ -221,9 +265,14 @@ export function getPermissionTemplateUsers (templateId, query = '', permission = 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; } 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 fef65522ef8..18b927b8bb9 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 @@ -60,7 +60,7 @@ export default class OrganizationNavigation extends React.Component {
  • - {translate('permissions')} + {translate('permissions.page')}
  • 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 b61026ce1dd..192a70d796a 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 @@ -57,7 +57,7 @@ exports[`test admin 1`] = ` onlyActiveOnIndex={false} style={Object {}} to="/organizations/foo/permissions"> - permissions + permissions.page
  • diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.js b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.js index 1b1c6c2da78..97f5f83436c 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.js +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.js @@ -17,6 +17,7 @@ * 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'; @@ -121,20 +122,27 @@ const mapStateToProps = state => ({ 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, diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/App.js b/server/sonar-web/src/main/js/apps/permissions/global/components/App.js index b0cdc95a4ad..a8207451905 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/App.js +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/App.js @@ -34,7 +34,7 @@ export default class App extends React.Component { render () { return (
    - +
    diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/PageHeader.js b/server/sonar-web/src/main/js/apps/permissions/global/components/PageHeader.js index 47d78c927ed..da8aba19c44 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/PageHeader.js +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/PageHeader.js @@ -23,8 +23,9 @@ import { translate } from '../../../../helpers/l10n'; import { isPermissionsAppLoading } from '../../../../store/rootReducer'; class PageHeader extends React.Component { - static propTypes = { - loading: React.PropTypes.bool + props: { + loading?: boolean, + organization?: {} }; static defaultProps = { @@ -32,19 +33,23 @@ class PageHeader extends React.Component { }; 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 (
    -

    - {translate('global_permissions.page')} -

    +

    {title}

    {this.props.loading && ( )} -
    - {translate('global_permissions.page.description')} -
    +
    {description}
    ); } diff --git a/server/sonar-web/src/main/js/apps/permissions/global/store/actions.js b/server/sonar-web/src/main/js/apps/permissions/global/store/actions.js index 2a163720e38..c944b31c741 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/store/actions.js +++ b/server/sonar-web/src/main/js/apps/permissions/global/store/actions.js @@ -17,6 +17,7 @@ * 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 { @@ -37,7 +38,10 @@ 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()); @@ -70,64 +74,69 @@ export const loadHolders = organization => (dispatch, 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))); + }); + }; diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.js b/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.js index 6eff70419e1..f0d95730703 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.js +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.js @@ -17,6 +17,7 @@ * 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'; @@ -135,7 +136,13 @@ const mapStateToProps = state => ({ 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)), diff --git a/server/sonar-web/src/main/js/apps/permissions/project/store/actions.js b/server/sonar-web/src/main/js/apps/permissions/project/store/actions.js index 26d69c45e4c..29296b6be49 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/store/actions.js +++ b/server/sonar-web/src/main/js/apps/permissions/project/store/actions.js @@ -17,6 +17,7 @@ * 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 { @@ -37,79 +38,93 @@ 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, @@ -120,8 +135,13 @@ export const grantToGroup = (projectKey, groupName, permission, organization) => }); }; -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, diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 96affb7e3c5..a16c62820c0 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -493,6 +493,7 @@ manual_measures.page=Manual Measures 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