diff options
author | Pascal Mugnier <pascal.mugnier@sonarsource.com> | 2018-10-10 10:35:04 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-10-10 20:20:59 +0200 |
commit | cc361223daf0c462e588a614c9037222c117e679 (patch) | |
tree | faea2bf3833bd9c0c6a6e663df1fadc8bc8639c1 /server/sonar-web | |
parent | 80d89a69cc4417a9fcab76542ca2eec66e6e6890 (diff) | |
download | sonarqube-cc361223daf0c462e588a614c9037222c117e679.tar.gz sonarqube-cc361223daf0c462e588a614c9037222c117e679.zip |
Apply feedbacks
Diffstat (limited to 'server/sonar-web')
5 files changed, 44 insertions, 20 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx index 1f67682cdc8..47a424a0e54 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx @@ -23,10 +23,11 @@ import CreateFormShim from '../../../../apps/portfolio/components/CreateFormShim import Dropdown from '../../../../components/controls/Dropdown'; import PlusIcon from '../../../../components/icons-components/PlusIcon'; import { AppState, hasGlobalPermission, CurrentUser } from '../../../types'; -import { getPortfolioAdminUrl } from '../../../../helpers/urls'; +import { getPortfolioAdminUrl, getPortfolioUrl } from '../../../../helpers/urls'; import { getExtensionStart } from '../../extensions/utils'; import { isSonarCloud } from '../../../../helpers/system'; import { translate } from '../../../../helpers/l10n'; +import { getComponentNavigation } from '../../../../api/nav'; interface Props { appState: Pick<AppState, 'qualifiers'>; @@ -81,8 +82,20 @@ export class GlobalNavPlus extends React.PureComponent<Props & WithRouterProps, }; handleCreatePortfolio = ({ key, qualifier }: { key: string; qualifier: string }) => { - this.closeCreatePortfolioForm(); - this.props.router.push(getPortfolioAdminUrl(key, qualifier)); + return getComponentNavigation({ componentKey: key }).then(data => { + if ( + data.configuration && + data.configuration.extensions && + data.configuration.extensions.find( + (item: { key: string; name: string }) => item.key === 'governance/console' + ) + ) { + this.props.router.push(getPortfolioAdminUrl(key, qualifier)); + } else { + this.props.router.push(getPortfolioUrl(key)); + } + this.closeCreatePortfolioForm(); + }); }; renderCreateProject() { @@ -132,9 +145,14 @@ export class GlobalNavPlus extends React.PureComponent<Props & WithRouterProps, render() { const { currentUser } = this.props; + const canCreateProject = hasGlobalPermission(currentUser, 'provisioning'); const canCreateApplication = hasGlobalPermission(currentUser, 'applicationcreator'); const canCreatePortfolio = hasGlobalPermission(currentUser, 'portfoliocreator'); + if (!canCreateProject && !canCreateApplication && !canCreatePortfolio) { + return null; + } + let defaultQualifier: string | undefined; if (!canCreateApplication) { defaultQualifier = 'VW'; diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx index 9305f1ddcbb..b74fe72c299 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx @@ -44,11 +44,7 @@ it('opens onboarding', () => { }); it('should display create new project link when user has permission only', () => { - expect( - getOverlayWrapper(getWrapper({}, [])) - .find('.js-new-project') - .exists() - ).toBe(false); + expect(getWrapper({}, []).find('Dropdown').length).toEqual(0); }); it('should display create new organization on SonarCloud only', () => { diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx index 9adccff9343..0282227203b 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx @@ -104,11 +104,13 @@ export class AllHoldersList extends React.PureComponent<Props> { return ( <> <HoldersList + filter={this.props.filter} groups={this.props.groups} loading={this.props.loading} onToggleGroup={this.handleToggleGroup} onToggleUser={this.handleToggleUser} permissions={permissions} + query={this.props.query} users={this.props.users}> <SearchForm filter={this.props.filter} diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.tsx index f03354dad35..27cd441636e 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/AllHoldersList.tsx @@ -98,11 +98,13 @@ export default class AllHoldersList extends React.PureComponent<Props> { return ( <> <HoldersList + filter={this.props.filter} groups={this.props.groups} onSelectPermission={this.handleSelectPermission} onToggleGroup={this.handleToggleGroup} onToggleUser={this.handleToggleUser} permissions={permissions} + query={this.props.query} selectedPermission={this.props.selectedPermission} users={this.props.users}> <SearchForm diff --git a/server/sonar-web/src/main/js/apps/permissions/shared/components/HoldersList.tsx b/server/sonar-web/src/main/js/apps/permissions/shared/components/HoldersList.tsx index bc916310724..c90341d2510 100644 --- a/server/sonar-web/src/main/js/apps/permissions/shared/components/HoldersList.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/shared/components/HoldersList.tsx @@ -27,23 +27,29 @@ import { PermissionGroup, PermissionUser, PermissionDefinitions } from '../../.. import { isPermissionDefinitionGroup } from '../../utils'; interface Props { - loading?: boolean; + filter?: string; groups: PermissionGroup[]; + loading?: boolean; onSelectPermission?: (permission: string) => void; onToggleGroup: (group: PermissionGroup, permission: string) => Promise<void>; onToggleUser: (user: PermissionUser, permission: string) => Promise<void>; permissions: PermissionDefinitions; + query?: string; selectedPermission?: string; showPublicProjectsWarning?: boolean; users: PermissionUser[]; } interface State { - permissionsCount: { [key: string]: number }; + initialPermissionsCount: { [key: string]: number }; } - export default class HoldersList extends React.PureComponent<Props, State> { - state: State = { permissionsCount: {} }; + state: State = { initialPermissionsCount: {} }; + componentDidUpdate(prevProps: Props) { + if (this.props.filter !== prevProps.filter || this.props.query !== prevProps.query) { + this.setState({ initialPermissionsCount: {} }); + } + } isPermissionUser(item: PermissionGroup | PermissionUser): item is PermissionUser { return (item as PermissionUser).login !== undefined; @@ -51,10 +57,10 @@ export default class HoldersList extends React.PureComponent<Props, State> { handleGroupToggle = (group: PermissionGroup, permission: string) => { const key = group.id || group.name; - if (this.state.permissionsCount[key] === undefined) { + if (this.state.initialPermissionsCount[key] === undefined) { this.setState(state => ({ - permissionsCount: { - ...state.permissionsCount, + initialPermissionsCount: { + ...state.initialPermissionsCount, [key]: group.permissions.length } })); @@ -63,10 +69,10 @@ export default class HoldersList extends React.PureComponent<Props, State> { }; handleUserToggle = (user: PermissionUser, permission: string) => { - if (this.state.permissionsCount[user.login] === undefined) { + if (this.state.initialPermissionsCount[user.login] === undefined) { this.setState(state => ({ - permissionsCount: { - ...state.permissionsCount, + initialPermissionsCount: { + ...state.initialPermissionsCount, [user.login]: user.permissions.length } })); @@ -76,8 +82,8 @@ export default class HoldersList extends React.PureComponent<Props, State> { getItemInitialPermissionsCount = (item: PermissionGroup | PermissionUser) => { const key = this.isPermissionUser(item) ? item.login : item.id || item.name; - return this.state.permissionsCount[key] !== undefined - ? this.state.permissionsCount[key] + return this.state.initialPermissionsCount[key] !== undefined + ? this.state.initialPermissionsCount[key] : item.permissions.length; }; |