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; GoogleSkipOrgRoleSync?: boolean;
// @deprecated -- this is no longer used and will be removed in Grafana 11 // @deprecated -- this is no longer used and will be removed in Grafana 11
GenericOAuthSkipOrgRoleSync?: boolean; GenericOAuthSkipOrgRoleSync?: boolean;
disableLogin?: boolean;
} }

View File

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

View File

@ -329,6 +329,7 @@ func (hs *HTTPServer) getFrontendSettings(c *contextmodel.ReqContext) (*dtos.Fro
GithubSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitHubProviderName]), GithubSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitHubProviderName]),
GitLabSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitlabProviderName]), GitLabSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.GitlabProviderName]),
OktaSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.OktaProviderName]), OktaSkipOrgRoleSync: parseSkipOrgRoleSyncEnabled(oauthProviders[social.OktaProviderName]),
DisableLogin: hs.Cfg.DisableLogin,
} }
if hs.pluginsCDNService != nil && hs.pluginsCDNService.IsEnabled() { 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 // AddChangePasswordLink returns if login form is disabled or not since
// the same intention can be used to hide both features. // the same intention can be used to hide both features.
func (cfg *Cfg) AddChangePasswordLink() bool { func (cfg *Cfg) AddChangePasswordLink() bool {
return !cfg.DisableLoginForm return !(cfg.DisableLoginForm || cfg.DisableLogin)
} }
type CommandLineArgs struct { type CommandLineArgs struct {

View File

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

View File

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