From 2879fc6789ada0ebfe449f47572a89ba7a83e9ed Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Fri, 10 Mar 2023 10:41:59 +0100 Subject: [PATCH] SONAR-18654 Disable group creation when user auto provisioning is enable --- .../main/js/apps/groups/components/App.tsx | 19 +++- .../main/js/apps/groups/components/Header.tsx | 97 +++++++++---------- .../groups/components/__tests__/App-test.tsx | 4 + .../__snapshots__/Header-test.tsx.snap | 20 ++-- .../resources/org/sonar/l10n/core.properties | 1 + 5 files changed, 79 insertions(+), 62 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/groups/components/App.tsx b/server/sonar-web/src/main/js/apps/groups/components/App.tsx index e282044653b..31cd060f6c9 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/App.tsx @@ -20,13 +20,14 @@ import { omit } from 'lodash'; import * as React from 'react'; import { Helmet } from 'react-helmet-async'; +import { getSystemInfo } from '../../../api/system'; import { createGroup, deleteGroup, searchUsersGroups, updateGroup } from '../../../api/user_groups'; import ListFooter from '../../../components/controls/ListFooter'; import SearchBox from '../../../components/controls/SearchBox'; import Suggestions from '../../../components/embed-docs-modal/Suggestions'; import { translate } from '../../../helpers/l10n'; import { omitNil } from '../../../helpers/request'; -import { Group, Paging } from '../../../types/types'; +import { Group, Paging, SysInfoCluster } from '../../../types/types'; import DeleteForm from './DeleteForm'; import Form from './Form'; import Header from './Header'; @@ -39,6 +40,7 @@ interface State { loading: boolean; paging?: Paging; query: string; + manageProvider?: string; } export default class App extends React.PureComponent<{}, State> { @@ -48,6 +50,7 @@ export default class App extends React.PureComponent<{}, State> { componentDidMount() { this.mounted = true; this.fetchGroups(); + this.fetchManageInstance(); } componentWillUnmount() { @@ -62,6 +65,15 @@ export default class App extends React.PureComponent<{}, State> { }); }; + async fetchManageInstance() { + const info = (await getSystemInfo()) as SysInfoCluster; + if (this.mounted) { + this.setState({ + manageProvider: info.System['External Users and Groups Provisioning'], + }); + } + } + stopLoading = () => { if (this.mounted) { this.setState({ loading: false }); @@ -188,7 +200,8 @@ export default class App extends React.PureComponent<{}, State> { }; render() { - const { editedGroup, groupToBeDeleted, groups, loading, paging, query } = this.state; + const { editedGroup, groupToBeDeleted, groups, loading, paging, query, manageProvider } = + this.state; const showAnyone = 'anyone'.includes(query.toLowerCase()); @@ -197,7 +210,7 @@ export default class App extends React.PureComponent<{}, State> {
-
+
Promise; + manageProvider?: string; } -interface State { - createModal: boolean; -} - -export default class Header extends React.PureComponent { - mounted = false; - state: State = { createModal: false }; - - componentDidMount() { - this.mounted = true; - } - - componentWillUnmount() { - this.mounted = false; - } - - handleCreateClick = () => { - this.setState({ createModal: true }); - }; - - handleClose = () => { - if (this.mounted) { - this.setState({ createModal: false }); - } - }; - - handleSubmit = (data: { name: string; description: string }) => { - return this.props.onCreate(data); - }; +export default function Header(props: Props) { + const { manageProvider } = props; + const [createModal, setCreateModal] = React.useState(false); - render() { - return ( - <> -
-

{translate('user_groups.page')}

+ return ( + <> +
+

{translate('user_groups.page')}

-
- -
+
+ +
+ {manageProvider === undefined ? (

{translate('user_groups.page.description')}

-
- {this.state.createModal && ( -
+ ) : ( + + + {translate('documentation')} + + ), + }} + /> + )} - - ); - } + + {createModal && ( + setCreateModal(false)} + onSubmit={props.onCreate} + /> + )} + + ); } diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx index 3c64bcf3a03..8858be2fd5e 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx @@ -57,6 +57,10 @@ jest.mock('../../../../api/user_groups', () => ({ updateGroup: jest.fn().mockResolvedValue({}), })); +jest.mock('../../../../api/system', () => ({ + getSystemInfo: jest.fn().mockResolvedValue({ System: {} }), +})); + beforeEach(() => { jest.clearAllMocks(); }); diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/Header-test.tsx.snap b/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/Header-test.tsx.snap index 3a12724c7c9..ba792ca89fc 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/Header-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/Header-test.tsx.snap @@ -2,19 +2,20 @@ exports[`should create new group 1`] = ` -
-

user_groups.page -

+
+
`; exports[`should create new group 2`] = ` -
-

user_groups.page -

+
+
`; 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 f0c58f35917..5ea15bc32c3 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -4392,6 +4392,7 @@ users.change_admin_password.form.continue_to_app=Continue to SonarQube #------------------------------------------------------------------------------ user_groups.page=Groups user_groups.page.description=Create and administer groups of users. +user_groups.page.managed_description=Your instance is managed by {provider}. No modification is allowed. You can still delete local groups. All other operations should be done on your identity provider. See {link} for help managing groups. user_groups.anyone.description=Anybody who browses the application belongs to this group. If authentication is not enforced, assigned permissions also apply to non-authenticated users. groups.delete_group=Delete Group groups.delete_group.confirmation=Are you sure you want to delete "{0}"? -- 2.39.5