From 16df95a4fa061755d0129927e29a3e7dc4794e8d Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Wed, 7 Oct 2020 10:24:33 +0200 Subject: SONAR-13936 Remove org on user and group API front-end. --- server/sonar-web/src/main/js/api/permissions.ts | 28 +---- server/sonar-web/src/main/js/api/user_groups.ts | 24 +--- server/sonar-web/src/main/js/api/users.ts | 5 - .../src/main/js/app/components/StartupModal.tsx | 11 +- .../app/components/__tests__/StartupModal-test.tsx | 1 - .../js/app/components/nav/global/GlobalNavMenu.tsx | 29 +---- .../components/ActionsCell.tsx | 21 +--- .../apps/permission-templates/components/App.tsx | 40 +++---- .../permission-templates/components/Defaults.tsx | 6 +- .../permission-templates/components/Header.tsx | 13 +-- .../apps/permission-templates/components/Home.tsx | 4 +- .../apps/permission-templates/components/List.tsx | 11 +- .../permission-templates/components/ListHeader.tsx | 1 - .../permission-templates/components/ListItem.tsx | 4 +- .../permission-templates/components/NameCell.tsx | 10 +- .../permission-templates/components/Template.tsx | 25 ++-- .../components/TemplateDetails.tsx | 5 +- .../components/TemplateHeader.tsx | 12 +- .../components/__tests__/ActionsCell-test.tsx | 15 --- .../components/__tests__/App-test.tsx | 11 +- .../components/__tests__/Defaults-test.tsx | 18 +-- .../components/__tests__/ListItem-test.tsx | 1 - .../components/__tests__/NameCell-test.tsx | 41 +++++++ .../components/__tests__/Template-test.tsx | 127 +++++++++++++++++++++ .../__tests__/__snapshots__/App-test.tsx.snap | 32 +----- .../__tests__/__snapshots__/Defaults-test.tsx.snap | 20 ---- .../__tests__/__snapshots__/NameCell-test.tsx.snap | 43 +++++++ .../__tests__/__snapshots__/Template-test.tsx.snap | 95 +++++++++++++++ .../src/main/js/apps/permission-templates/utils.ts | 2 + .../js/apps/permissions/global/components/App.tsx | 25 ++-- .../permissions/global/components/PageHeader.tsx | 13 +-- .../global/components/__tests__/App-test.tsx | 7 +- .../__tests__/__snapshots__/App-test.tsx.snap | 12 -- .../project/components/ApplyTemplate.tsx | 2 +- .../projectsManagement/BulkApplyTemplateModal.tsx | 2 +- .../apps/projectsManagement/RestoreAccessModal.tsx | 3 +- .../__tests__/BulkApplyTemplateModal-test.tsx | 2 +- .../js/apps/quality-profiles/components/App.tsx | 7 +- .../components/__tests__/App-test.tsx | 35 ++++++ .../__tests__/__snapshots__/App-test.tsx.snap | 19 +++ .../js/components/common/OrganizationHelmet.tsx | 33 ------ .../src/main/js/store/__tests__/users-test.tsx | 11 -- server/sonar-web/src/main/js/store/users.ts | 19 +-- server/sonar-web/src/main/js/types/types.d.ts | 1 - 44 files changed, 457 insertions(+), 389 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/NameCell-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/Template-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/__snapshots__/NameCell-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/permission-templates/components/__tests__/__snapshots__/Template-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/App-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/__snapshots__/App-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/common/OrganizationHelmet.tsx (limited to 'server/sonar-web/src/main') diff --git a/server/sonar-web/src/main/js/api/permissions.ts b/server/sonar-web/src/main/js/api/permissions.ts index 53222bd2212..d87932fe7cd 100644 --- a/server/sonar-web/src/main/js/api/permissions.ts +++ b/server/sonar-web/src/main/js/api/permissions.ts @@ -27,7 +27,6 @@ export function grantPermissionToUser(data: { projectKey?: string; login: string; permission: string; - organization?: string; }) { return post('/api/permissions/add_user', data).catch(throwGlobalError); } @@ -36,7 +35,6 @@ export function revokePermissionFromUser(data: { projectKey?: string; login: string; permission: string; - organization?: string; }) { return post('/api/permissions/remove_user', data).catch(throwGlobalError); } @@ -45,7 +43,6 @@ export function grantPermissionToGroup(data: { projectKey?: string; groupName: string; permission: string; - organization?: string; }) { return post('/api/permissions/add_group', data).catch(throwGlobalError); } @@ -54,7 +51,6 @@ export function revokePermissionFromGroup(data: { projectKey?: string; groupName: string; permission: string; - organization?: string; }) { return post('/api/permissions/remove_group', data).catch(throwGlobalError); } @@ -65,11 +61,9 @@ interface GetPermissionTemplatesResponse { permissions: Array<{ key: string; name: string; description: string }>; } -export function getPermissionTemplates( - organization?: string -): Promise { +export function getPermissionTemplates(): Promise { const url = '/api/permissions/search_templates'; - return organization ? getJSON(url, { organization }) : getJSON(url); + return getJSON(url); } export function createPermissionTemplate(data: RequestData) { @@ -103,7 +97,6 @@ export function grantTemplatePermissionToUser(data: { templateId: string; login: string; permission: string; - organization?: string; }): Promise { return post('/api/permissions/add_user_to_template', data); } @@ -112,7 +105,6 @@ export function revokeTemplatePermissionFromUser(data: { templateId: string; login: string; permission: string; - organization?: string; }): Promise { return post('/api/permissions/remove_user_from_template', data); } @@ -140,7 +132,6 @@ export function getPermissionsUsersForComponent(data: { projectKey: string; q?: string; permission?: string; - organization?: string; p?: number; ps?: number; }): Promise<{ paging: T.Paging; users: T.PermissionUser[] }> { @@ -154,7 +145,6 @@ export function getPermissionsGroupsForComponent(data: { projectKey: string; q?: string; permission?: string; - organization?: string; p?: number; ps?: number; }): Promise<{ paging: T.Paging; groups: T.PermissionGroup[] }> { @@ -167,7 +157,6 @@ export function getPermissionsGroupsForComponent(data: { export function getGlobalPermissionsUsers(data: { q?: string; permission?: string; - organization?: string; p?: number; ps?: number; }): Promise<{ paging: T.Paging; users: T.PermissionUser[] }> { @@ -180,7 +169,6 @@ export function getGlobalPermissionsUsers(data: { export function getGlobalPermissionsGroups(data: { q?: string; permission?: string; - organization?: string; p?: number; ps?: number; }): Promise<{ paging: T.Paging; groups: T.PermissionGroup[] }> { @@ -193,8 +181,7 @@ export function getGlobalPermissionsGroups(data: { export function getPermissionTemplateUsers( templateId: string, query?: string, - permission?: string, - organization?: string + permission?: string ): Promise { const data: RequestData = { templateId, ps: PAGE_SIZE }; if (query) { @@ -203,17 +190,13 @@ export function getPermissionTemplateUsers( if (permission) { data.permission = permission; } - if (organization) { - Object.assign(data, { organization }); - } return getJSON('/api/permissions/template_users', data).then(r => r.users); } export function getPermissionTemplateGroups( templateId: string, query?: string, - permission?: string, - organization?: string + permission?: string ): Promise { const data: RequestData = { templateId, ps: PAGE_SIZE }; if (query) { @@ -222,9 +205,6 @@ export function getPermissionTemplateGroups( if (permission) { data.permission = permission; } - if (organization) { - Object.assign(data, { organization }); - } return getJSON('/api/permissions/template_groups', data).then(r => r.groups); } diff --git a/server/sonar-web/src/main/js/api/user_groups.ts b/server/sonar-web/src/main/js/api/user_groups.ts index fca0be2e46d..6d7aa683c93 100644 --- a/server/sonar-web/src/main/js/api/user_groups.ts +++ b/server/sonar-web/src/main/js/api/user_groups.ts @@ -22,7 +22,6 @@ import throwGlobalError from '../app/utils/throwGlobalError'; export function searchUsersGroups(data: { f?: string; - organization?: string; p?: number; ps?: number; q?: string; @@ -33,7 +32,6 @@ export function searchUsersGroups(data: { export function getUsersInGroup(data: { id?: number; name?: string; - organization?: string; p?: number; ps?: number; q?: string; @@ -42,29 +40,15 @@ export function getUsersInGroup(data: { return getJSON('/api/user_groups/users', data).catch(throwGlobalError); } -export function addUserToGroup(data: { - id?: string; - name?: string; - login?: string; - organization?: string; -}) { +export function addUserToGroup(data: { id?: string; name?: string; login?: string }) { return post('/api/user_groups/add_user', data).catch(throwGlobalError); } -export function removeUserFromGroup(data: { - id?: string; - name?: string; - login?: string; - organization?: string; -}) { +export function removeUserFromGroup(data: { id?: string; name?: string; login?: string }) { return post('/api/user_groups/remove_user', data).catch(throwGlobalError); } -export function createGroup(data: { - description?: string; - organization?: string; - name: string; -}): Promise { +export function createGroup(data: { description?: string; name: string }): Promise { return postJSON('/api/user_groups/create', data).then(r => r.group, throwGlobalError); } @@ -72,6 +56,6 @@ export function updateGroup(data: { description?: string; id: number; name?: str return post('/api/user_groups/update', data).catch(throwGlobalError); } -export function deleteGroup(data: { name: string; organization?: string }) { +export function deleteGroup(data: { name: string }) { return post('/api/user_groups/delete', data).catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/api/users.ts b/server/sonar-web/src/main/js/api/users.ts index 44bba9b96fc..0fd0364dc00 100644 --- a/server/sonar-web/src/main/js/api/users.ts +++ b/server/sonar-web/src/main/js/api/users.ts @@ -42,7 +42,6 @@ export interface UserGroup { export function getUserGroups(data: { login: string; - organization?: string; p?: number; ps?: number; q?: string; @@ -91,10 +90,6 @@ export function deactivateUser(data: { login: string }): Promise { return postJSON('/api/users/deactivate', data).catch(throwGlobalError); } -export function skipOnboarding(): Promise { - return post('/api/users/skip_onboarding_tutorial').catch(throwGlobalError); -} - export function setHomePage(homepage: T.HomePage): Promise { return post('/api/users/set_homepage', homepage).catch(throwGlobalError); } diff --git a/server/sonar-web/src/main/js/app/components/StartupModal.tsx b/server/sonar-web/src/main/js/app/components/StartupModal.tsx index 9d4d41c994f..a873cd4a3ae 100644 --- a/server/sonar-web/src/main/js/app/components/StartupModal.tsx +++ b/server/sonar-web/src/main/js/app/components/StartupModal.tsx @@ -28,7 +28,6 @@ import { showLicense } from '../../api/marketplace'; import { Location, Router, withRouter } from '../../components/hoc/withRouter'; import { isLoggedIn } from '../../helpers/users'; import { getAppState, getCurrentUser, Store } from '../../store/rootReducer'; -import { skipOnboarding } from '../../store/users'; import { EditionKey } from '../../types/editions'; const LicensePromptModal = lazyLoadComponent( @@ -42,10 +41,6 @@ interface StateProps { currentUser: T.CurrentUser; } -interface DispatchProps { - skipOnboarding: () => void; -} - interface OwnProps { children?: React.ReactNode; } @@ -55,7 +50,7 @@ interface WithRouterProps { router: Pick; } -type Props = StateProps & DispatchProps & OwnProps & WithRouterProps; +type Props = StateProps & OwnProps & WithRouterProps; interface State { open?: boolean; @@ -112,6 +107,4 @@ const mapStateToProps = (state: Store): StateProps => ({ currentUser: getCurrentUser(state) }); -const mapDispatchToProps: DispatchProps = { skipOnboarding }; - -export default connect(mapStateToProps, mapDispatchToProps)(withRouter(StartupModal)); +export default connect(mapStateToProps)(withRouter(StartupModal)); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx index b97e7e10728..c1aa981c501 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx @@ -130,7 +130,6 @@ function getWrapper(props: Partial = {}) { currentUser={LOGGED_IN_USER} location={{ pathname: 'foo/bar' }} router={{ push: jest.fn() }} - skipOnboarding={jest.fn()} {...props}>
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.tsx b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.tsx index 6da08f37d7b..f384811b69e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.tsx @@ -24,9 +24,8 @@ import Dropdown from 'sonar-ui-common/components/controls/Dropdown'; import DropdownIcon from 'sonar-ui-common/components/icons/DropdownIcon'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { isMySet } from '../../../../apps/issues/utils'; -import { isSonarCloud } from '../../../../helpers/system'; import { getQualityGatesUrl } from '../../../../helpers/urls'; -import { isLoggedIn } from '../../../../helpers/users'; +import { ComponentQualifier } from '../../../../types/component'; interface Props { appState: Pick; @@ -36,10 +35,6 @@ interface Props { export default class GlobalNavMenu extends React.PureComponent { renderProjects() { - if (isSonarCloud() && !isLoggedIn(this.props.currentUser)) { - return null; - } - const active = this.props.location.pathname.startsWith('/projects') && this.props.location.pathname !== '/projects/create'; @@ -47,7 +42,7 @@ export default class GlobalNavMenu extends React.PureComponent { return (
  • - {isSonarCloud() ? translate('my_projects') : translate('projects.page')} + {translate('projects.page')}
  • ); @@ -64,24 +59,8 @@ export default class GlobalNavMenu extends React.PureComponent { } renderIssuesLink() { - if (isSonarCloud() && !isLoggedIn(this.props.currentUser)) { - return null; - } - const active = this.props.location.pathname.startsWith('/issues'); - if (isSonarCloud()) { - return ( -
  • - - {translate('my_issues')} - -
  • - ); - } - const query = this.props.currentUser.isLoggedIn && isMySet() ? { resolved: 'false', myIssues: 'true' } @@ -174,7 +153,9 @@ export default class GlobalNavMenu extends React.PureComponent { } render() { - const governanceInstalled = this.props.appState.qualifiers.includes('VW'); + const governanceInstalled = this.props.appState.qualifiers.includes( + ComponentQualifier.Portfolio + ); const { organizationsEnabled } = this.props.appState; return ( diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.tsx b/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.tsx index d02c73189b8..bdaf8c4249f 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.tsx +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/ActionsCell.tsx @@ -30,12 +30,12 @@ import { updatePermissionTemplate } from '../../../api/permissions'; import { Router, withRouter } from '../../../components/hoc/withRouter'; +import { PERMISSION_TEMPLATES_PATH } from '../utils'; import DeleteForm from './DeleteForm'; import Form from './Form'; interface Props { fromDetails?: boolean; - organization?: { isDefault?: boolean; key: string }; permissionTemplate: T.PermissionTemplate; refresh: () => void; router: Pick; @@ -91,10 +91,7 @@ export class ActionsCell extends React.PureComponent { handleDeleteSubmit = () => { return deletePermissionTemplate({ templateId: this.props.permissionTemplate.id }).then(() => { - const pathname = this.props.organization - ? `/organizations/${this.props.organization.key}/permission_templates` - : '/permission_templates'; - this.props.router.replace(pathname); + this.props.router.replace(PERMISSION_TEMPLATES_PATH); this.props.refresh(); }); }; @@ -107,11 +104,7 @@ export class ActionsCell extends React.PureComponent { }; getAvailableQualifiers() { - const topQualifiers = - this.props.organization && !this.props.organization.isDefault - ? ['TRK'] - : this.props.topQualifiers; - return difference(topQualifiers, this.props.permissionTemplate.defaultFor); + return difference(this.props.topQualifiers, this.props.permissionTemplate.defaultFor); } renderSetDefaultsControl() { @@ -160,11 +153,7 @@ export class ActionsCell extends React.PureComponent { } render() { - const { permissionTemplate: t, organization } = this.props; - - const pathname = organization - ? `/organizations/${organization.key}/permission_templates` - : '/permission_templates'; + const { permissionTemplate: t } = this.props; return ( <> @@ -172,7 +161,7 @@ export class ActionsCell extends React.PureComponent { {this.renderSetDefaultsControl()} {!this.props.fromDetails && ( - + {translate('edit_permissions')} )} diff --git a/server/sonar-web/src/main/js/apps/permission-templates/components/App.tsx b/server/sonar-web/src/main/js/apps/permission-templates/components/App.tsx index e05c6178687..3a47ab64959 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/permission-templates/components/App.tsx @@ -19,11 +19,11 @@ */ import { Location } from 'history'; import * as React from 'react'; +import { Helmet } from 'react-helmet-async'; import { connect } from 'react-redux'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { getPermissionTemplates } from '../../../api/permissions'; import Suggestions from '../../../app/components/embed-docs-modal/Suggestions'; -import OrganizationHelmet from '../../../components/common/OrganizationHelmet'; import { getAppState, Store } from '../../../store/rootReducer'; import '../../permissions/styles.css'; import { mergeDefaultsToTemplates, mergePermissionsToTemplates, sortPermissions } from '../utils'; @@ -32,7 +32,6 @@ import Template from './Template'; interface Props { location: Location; - organization: T.Organization | undefined; topQualifiers: string[]; } @@ -59,21 +58,21 @@ export class App extends React.PureComponent { this.mounted = false; } - requestPermissions = () => { - 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( - mergePermissionsToTemplates(r.permissionTemplates, permissions), - r.defaultTemplates - ); - this.setState({ ready: true, permissionTemplates, permissions }); - } - }); + requestPermissions = async () => { + const { permissions, defaultTemplates, permissionTemplates } = await getPermissionTemplates(); + + if (this.mounted) { + const sortedPerm = sortPermissions(permissions); + const permissionTemplatesMerged = mergeDefaultsToTemplates( + mergePermissionsToTemplates(permissionTemplates, sortedPerm), + defaultTemplates + ); + this.setState({ + ready: true, + permissionTemplates: permissionTemplatesMerged, + permissions: sortedPerm + }); + } }; renderTemplate(id: string) { @@ -88,7 +87,6 @@ export class App extends React.PureComponent { return (