Auth: Hide forgot password if grafana auth is disabled (#79895)

* hide forgot password if grafana auth is disabled

* fix test
This commit is contained in:
Jo 2024-01-04 10:46:55 +01:00 committed by GitHub
parent e924627659
commit 5ae3249c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 9 deletions

View File

@ -259,4 +259,6 @@ export interface AuthSettings {
GoogleSkipOrgRoleSync?: boolean;
// @deprecated -- this is no longer used and will be removed in Grafana 11
GenericOAuthSkipOrgRoleSync?: boolean;
disableLogin?: boolean;
}

View File

@ -29,6 +29,8 @@ type FrontendSettingsAuthDTO struct {
GitLabSkipOrgRoleSync bool `json:"GitLabSkipOrgRoleSync"`
// Deprecated: this is no longer used and will be removed in Grafana 11
OktaSkipOrgRoleSync bool `json:"OktaSkipOrgRoleSync"`
DisableLogin bool `json:"disableLogin"`
}
type FrontendSettingsBuildInfoDTO struct {

View File

@ -329,6 +329,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
GithubSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitHubProviderName]),
GitLabSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitlabProviderName]),
OktaSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.OktaProviderName]),
DisableLogin: hs.Cfg.DisableLogin,
}
if hs.pluginsCDNService != nil && hs.pluginsCDNService.IsEnabled() {

View File

@ -551,7 +551,7 @@ type Cfg struct {
// AddChangePasswordLink returns if login form is disabled or not since
// the same intention can be used to hide both features.
func (cfg *Cfg) AddChangePasswordLink() bool {
return !cfg.DisableLoginForm
return !(cfg.DisableLoginForm || cfg.DisableLogin)
}
type CommandLineArgs struct {

View File

@ -14,6 +14,9 @@ jest.mock('@grafana/runtime', () => ({
post: postMock,
}),
config: {
auth: {
disableLogin: false,
},
loginError: false,
buildInfo: {
version: 'v1.0',

View File

@ -4,9 +4,9 @@ import React from 'react';
// Components
import { GrafanaTheme2 } from '@grafana/data';
import { config } from '@grafana/runtime';
import { Alert, HorizontalGroup, LinkButton, useStyles2 } from '@grafana/ui';
import { Branding } from 'app/core/components/Branding/Branding';
import config from 'app/core/config';
import { t } from 'app/core/internationalization';
import { ChangePassword } from '../ForgottenPassword/ChangePassword';
@ -48,13 +48,15 @@ export const LoginPage = () => {
{!disableLoginForm && (
<LoginForm onSubmit={login} loginHint={loginHint} passwordHint={passwordHint} isLoggingIn={isLoggingIn}>
<HorizontalGroup justify="flex-end">
<LinkButton
className={styles.forgottenPassword}
fill="text"
href={`${config.appSubUrl}/user/password/send-reset-email`}
>
Forgot your password?
</LinkButton>
{!config.auth.disableLogin && (
<LinkButton
className={styles.forgottenPassword}
fill="text"
href={`${config.appSubUrl}/user/password/send-reset-email`}
>
Forgot your password?
</LinkButton>
)}
</HorizontalGroup>
</LoginForm>
)}