mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix: Hide invite when disabled login form is set (#67031)
* FIX: Hide Invite Button with external user management * Hide also when login form is disabled * add tests and readability --------- Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com>
This commit is contained in:
parent
0eca9950a0
commit
b7f047c8dd
@ -2,6 +2,8 @@ import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
import { mockToolkitActionCreator } from 'test/core/redux/mocks';
|
||||
|
||||
import { config } from 'app/core/config';
|
||||
|
||||
import { Props, UsersActionBarUnconnected } from './UsersActionBar';
|
||||
import { searchQueryChanged } from './state/reducers';
|
||||
|
||||
@ -62,4 +64,17 @@ describe('Render', () => {
|
||||
|
||||
expect(screen.getByRole('link', { name: 'someUrl' })).toHaveAttribute('href', 'some/url');
|
||||
});
|
||||
|
||||
it('should not show invite button when disableLoginForm is set', () => {
|
||||
const originalDisableLoginForm = config.disableLoginForm;
|
||||
config.disableLoginForm = true;
|
||||
|
||||
setup({
|
||||
canInvite: true,
|
||||
});
|
||||
|
||||
expect(screen.queryByRole('link', { name: 'Invite' })).not.toBeInTheDocument();
|
||||
// Reset the disableLoginForm mock to its original value
|
||||
config.disableLoginForm = originalDisableLoginForm;
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { connect, ConnectedProps } from 'react-redux';
|
||||
|
||||
import { RadioButtonGroup, LinkButton, FilterInput } from '@grafana/ui';
|
||||
import config from 'app/core/config';
|
||||
import { contextSrv } from 'app/core/core';
|
||||
import { AccessControlAction, StoreState } from 'app/types';
|
||||
|
||||
@ -48,6 +49,8 @@ export const UsersActionBarUnconnected = ({
|
||||
{ label: `Pending Invites (${pendingInvitesCount})`, value: 'invites' },
|
||||
];
|
||||
const canAddToOrg: boolean = contextSrv.hasAccess(AccessControlAction.OrgUsersAdd, canInvite);
|
||||
// backend rejects invitations if the login form is disabled
|
||||
const showInviteButton: boolean = canAddToOrg && !config.disableLoginForm;
|
||||
|
||||
return (
|
||||
<div className="page-action-bar" data-testid="users-action-bar">
|
||||
@ -63,7 +66,7 @@ export const UsersActionBarUnconnected = ({
|
||||
<RadioButtonGroup value={showInvites ? 'invites' : 'users'} options={options} onChange={onShowInvites} />
|
||||
</div>
|
||||
)}
|
||||
{canAddToOrg && <LinkButton href="org/users/invite">Invite</LinkButton>}
|
||||
{showInviteButton && <LinkButton href="org/users/invite">Invite</LinkButton>}
|
||||
{externalUserMngLinkUrl && (
|
||||
<LinkButton href={externalUserMngLinkUrl} target="_blank" rel="noopener">
|
||||
{externalUserMngLinkName}
|
||||
|
Loading…
Reference in New Issue
Block a user