diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2017-02-03 10:55:49 +0100 |
---|---|---|
committer | Stas Vilchik <stas-vilchik@users.noreply.github.com> | 2017-02-03 11:54:45 +0100 |
commit | b7b89cce83baa7bdd3254ee09befb775522452c3 (patch) | |
tree | 200262ebedd1b1c0e460a26db9d390ee63fcf7a7 /server/sonar-web/src/main/js/apps | |
parent | 63d06f0b44b99b0ca814d590b1487265db998bc3 (diff) | |
download | sonarqube-b7b89cce83baa7bdd3254ee09befb775522452c3.tar.gz sonarqube-b7b89cce83baa7bdd3254ee09befb775522452c3.zip |
refactor and add type annonations around permissions domain
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
8 files changed, 187 insertions, 138 deletions
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 { </li> <li> <Link to={`/organizations/${organization.key}/permissions`} activeClassName="active"> - {translate('permissions')} + {translate('permissions.page')} </Link> </li> <li> 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 </Link> </li> <li> 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 ( <div className="page page-limited"> - <PageHeader/> + <PageHeader organization={this.props.organization}/> <PageError/> <AllHoldersList organization={this.props.organization}/> </div> 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 ( <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> ); } 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, |