Auth: Show invite button if disable login form is set to false (#69946)

* show invite button if disable login form is set to false

* fix test

* Update public/app/features/users/UsersActionBar.tsx

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>

---------

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
This commit is contained in:
Ieva 2023-06-15 13:17:45 +01:00 committed by GitHub
parent 14c4c26215
commit 21f8dd9599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -65,9 +65,10 @@ describe('Render', () => {
expect(screen.getByRole('link', { name: 'someUrl' })).toHaveAttribute('href', 'some/url');
});
it('should not show invite button when externalUserMngInfo is set', () => {
it('should not show invite button when externalUserMngInfo is set and disableLoginForm is true', () => {
const originalExternalUserMngInfo = config.externalUserMngInfo;
config.externalUserMngInfo = 'truthy';
config.disableLoginForm = true;
setup({
canInvite: true,
@ -77,4 +78,30 @@ describe('Render', () => {
// Reset the disableLoginForm mock to its original value
config.externalUserMngInfo = originalExternalUserMngInfo;
});
it('should show invite button when externalUserMngInfo is not set and disableLoginForm is true', () => {
config.externalUserMngInfo = '';
config.disableLoginForm = true;
setup({
canInvite: true,
});
expect(screen.getByRole('link', { name: 'Invite' })).toHaveAttribute('href', 'org/users/invite');
// Reset the disableLoginForm mock to its original value
config.disableLoginForm = false;
});
it('should show invite button when externalUserMngInfo is set and disableLoginForm is false', () => {
const originalExternalUserMngInfo = config.externalUserMngInfo;
config.externalUserMngInfo = 'truthy';
setup({
canInvite: true,
});
expect(screen.getByRole('link', { name: 'Invite' })).toHaveAttribute('href', 'org/users/invite');
// Reset the disableLoginForm mock to its original value
config.externalUserMngInfo = originalExternalUserMngInfo;
});
});

View File

@ -49,8 +49,10 @@ export const UsersActionBarUnconnected = ({
{ label: `Pending Invites (${pendingInvitesCount})`, value: 'invites' },
];
const canAddToOrg: boolean = contextSrv.hasAccess(AccessControlAction.OrgUsersAdd, canInvite);
// Hide Invite button in case users are managed externally
const showInviteButton: boolean = canAddToOrg && !config.externalUserMngInfo;
// Show invite button in the following cases:
// 1) the instance is not a hosted Grafana instance (!config.externalUserMngInfo)
// 2) new basic auth users can be created for this instance (!config.disableLoginForm).
const showInviteButton: boolean = canAddToOrg && !(config.disableLoginForm && config.externalUserMngInfo);
return (
<div className="page-action-bar" data-testid="users-action-bar">