Skip to content

Commit

Permalink
Auth: Hide forgot password if grafana auth is disabled (#79895)
Browse files Browse the repository at this point in the history
* hide forgot password if grafana auth is disabled

* fix test
  • Loading branch information
Jguer committed Jan 4, 2024
1 parent e924627 commit 5ae3249
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions packages/grafana-data/src/types/config.ts
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions pkg/api/dtos/frontend_settings.go
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/frontendsettings.go
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/setting/setting.go
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions public/app/core/components/Login/LoginPage.test.tsx
Expand Up @@ -14,6 +14,9 @@ jest.mock('@grafana/runtime', () => ({
post: postMock,
}),
config: {
auth: {
disableLogin: false,
},
loginError: false,
buildInfo: {
version: 'v1.0',
Expand Down
18 changes: 10 additions & 8 deletions public/app/core/components/Login/LoginPage.tsx
Expand Up @@ -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';
Expand Down Expand Up @@ -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>
)}
Expand Down

0 comments on commit 5ae3249

Please sign in to comment.