import GithubProvisioningServiceMock from '../../../api/mocks/GithubProvisioningServiceMock';
import GroupMembershipsServiceMock from '../../../api/mocks/GroupMembersipsServiceMock';
import GroupsServiceMock from '../../../api/mocks/GroupsServiceMock';
+import SettingsServiceMock from '../../../api/mocks/SettingsServiceMock';
import SystemServiceMock from '../../../api/mocks/SystemServiceMock';
import UsersServiceMock from '../../../api/mocks/UsersServiceMock';
import { mockGitHubConfiguration } from '../../../helpers/mocks/dop-translation';
const userHandler = new UsersServiceMock(groupMembershipsHandler);
const dopTranslationHandler = new DopTranslationServiceMock();
const githubHandler = new GithubProvisioningServiceMock(dopTranslationHandler);
+const settingsHandler = new SettingsServiceMock();
const ui = {
createGroupButton: byRole('button', { name: 'groups.create_group' }),
name: 'local-group local 3',
}),
+ samlWarning: byText('users.update_groups.saml_enabled'),
+
githubProvisioningPending: byText(/synchronization_pending/),
githubProvisioningInProgress: byText(/synchronization_in_progress/),
githubProvisioningSuccess: byText(/synchronization_successful/),
};
beforeEach(() => {
+ settingsHandler.reset();
handler.reset();
systemHandler.reset();
dopTranslationHandler.reset();
expect(await screen.findAllByRole('row')).toHaveLength(16);
});
+
+ it('should display a warning if SAML is enabled', async () => {
+ [
+ {
+ key: 'sonar.auth.saml.signature.enabled',
+ value: 'false',
+ },
+ {
+ key: 'sonar.auth.saml.enabled',
+ value: 'true',
+ },
+ {
+ key: 'sonar.auth.saml.applicationId',
+ value: 'sonarqube',
+ },
+ {
+ key: 'sonar.auth.saml.providerName',
+ value: 'SAML',
+ },
+ ].forEach((setting: any) => settingsHandler.set(setting.key, setting.value));
+
+ const user = userEvent.setup();
+ renderGroupsApp();
+
+ expect(await ui.localGroupRow.find()).toBeInTheDocument();
+
+ await user.click(ui.localGroupEditMembersButton.get());
+
+ expect(await ui.membersDialog.find()).toBeInTheDocument();
+
+ expect(await ui.getMembers()).toHaveLength(3);
+ expect(ui.samlWarning.get()).toBeInTheDocument();
+
+ await user.click(ui.doneButton.get());
+ expect(ui.membersDialog.query()).not.toBeInTheDocument();
+ });
});
describe('in manage mode', () => {
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { Modal, TextMuted } from 'design-system';
+import { FlagMessage, Modal, TextMuted } from 'design-system';
import { find } from 'lodash';
import * as React from 'react';
import SelectList, {
SelectListSearchParams,
} from '../../../components/controls/SelectList';
import { translate } from '../../../helpers/l10n';
+import { definitions } from '../../../helpers/mocks/definitions-list';
import {
useAddGroupMembershipMutation,
useGroupMembersQuery,
} from '../../../queries/group-memberships';
import { Group } from '../../../types/types';
import { RestUserBase } from '../../../types/users';
+import useSamlConfiguration from '../../settings/components/authentication/hook/useSamlConfiguration';
+import { SAML } from '../../settings/components/authentication/SamlAuthenticationTab';
+
+const samlDefinitions = definitions.filter((def) => def.subCategory === SAML);
interface Props {
group: Group;
});
const emptyQueryCache = useRemoveGroupMembersQueryFromCache();
+ const { samlEnabled } = useSamlConfiguration(samlDefinitions);
+
const users: (RestUserBase & { selected?: boolean })[] =
data?.pages.flatMap((page) => page.users) ?? [];
<Modal
headerTitle={modalHeader}
body={
- <SelectList
- elements={users.map((user) => user.id)}
- elementsTotalCount={data?.pages[0].page.total}
- needToReload={changedUsers.size > 0 && filter !== SelectListFilter.All}
- onSearch={onSearch}
- onSelect={handleSelect}
- onUnselect={handleUnselect}
- renderElement={renderElement}
- selectedElements={users
- .filter((u) => (changedUsers.has(u.id) ? changedUsers.get(u.id) : u.selected))
- .map((u) => u.id)}
- withPaging
- loading={isLoading}
- />
+ <>
+ {samlEnabled && (
+ <FlagMessage className="sw-mb-2" variant="warning">
+ {translate('users.update_groups.saml_enabled')}
+ </FlagMessage>
+ )}
+ <SelectList
+ elements={users.map((user) => user.id)}
+ elementsTotalCount={data?.pages[0].page.total}
+ needToReload={changedUsers.size > 0 && filter !== SelectListFilter.All}
+ onSearch={onSearch}
+ onSelect={handleSelect}
+ onUnselect={handleUnselect}
+ renderElement={renderElement}
+ selectedElements={users
+ .filter((u) => (changedUsers.has(u.id) ? changedUsers.get(u.id) : u.selected))
+ .map((u) => u.id)}
+ withPaging
+ loading={isLoading}
+ />
+ </>
}
secondaryButtonLabel={translate('done')}
onClose={props.onClose}
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { LightPrimary, Modal, Note } from 'design-system';
+import { FlagMessage, LightPrimary, Modal, Note } from 'design-system';
import { find } from 'lodash';
import * as React from 'react';
import SelectList, {
SelectListSearchParams,
} from '../../../components/controls/SelectList';
import { translate } from '../../../helpers/l10n';
+import { definitions } from '../../../helpers/mocks/definitions-list';
import {
useAddGroupMembershipMutation,
useRemoveGroupMembershipMutation,
useUserGroupsQuery,
} from '../../../queries/group-memberships';
import { RestUserDetailed } from '../../../types/users';
+import useSamlConfiguration from '../../settings/components/authentication/hook/useSamlConfiguration';
+import { SAML } from '../../settings/components/authentication/SamlAuthenticationTab';
+
+const samlDefinitions = definitions.filter((def) => def.subCategory === SAML);
interface Props {
onClose: () => void;
const { mutateAsync: addUserToGroup } = useAddGroupMembershipMutation();
const { mutateAsync: removeUserFromGroup } = useRemoveGroupMembershipMutation();
+ const { samlEnabled } = useSamlConfiguration(samlDefinitions);
+
const onSearch = (searchParams: SelectListSearchParams) => {
if (query === searchParams.query && filter === searchParams.filter) {
refetch();
headerTitle={header}
body={
<div className="sw-pt-1">
+ {samlEnabled && (
+ <FlagMessage className="sw-mb-2" variant="warning">
+ {translate('users.update_groups.saml_enabled')}
+ </FlagMessage>
+ )}
<SelectList
elements={groups?.map((group) => group.id.toString()) ?? []}
elementsTotalCount={groups?.length}
users.update_users_groups=Update {0}'s group membership
users.view_users_groups=View {0}'s group membership
users.update_groups=Update Groups
+users.update_groups.saml_enabled=Updating a group's membership when SAML is enabled will be temporary. The group membership will be updated the next time the user logs in.
users.view_groups=View Groups
users.manage_user=Update {0}
users.update_tokens=Update tokens