From 884a99e375e48b9bbf6b07410ca66dce31391447 Mon Sep 17 00:00:00 2001 From: dupondje Date: Tue, 16 Feb 2021 10:20:41 +0100 Subject: [PATCH] Disable Change Password for OAuth users (#27886) --- public/app/core/utils/UserProvider.tsx | 6 +-- .../features/profile/ChangePasswordForm.tsx | 11 +++- .../features/profile/ChangePasswordPage.tsx | 50 +++++++++++-------- .../features/profile/UserOrganizations.tsx | 4 +- .../app/features/profile/UserProfileEdit.tsx | 11 +++- .../features/profile/UserProfileEditForm.tsx | 14 ++++-- public/app/features/profile/UserSessions.tsx | 4 +- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/public/app/core/utils/UserProvider.tsx b/public/app/core/utils/UserProvider.tsx index afd30082b73..59d5b58d338 100644 --- a/public/app/core/utils/UserProvider.tsx +++ b/public/app/core/utils/UserProvider.tsx @@ -1,6 +1,6 @@ import React, { PureComponent } from 'react'; import { getBackendSrv } from '@grafana/runtime'; -import { User, Team, UserOrg, UserSession } from 'app/types'; +import { UserDTO, Team, UserOrg, UserSession } from 'app/types'; import { config } from 'app/core/config'; import { dateTimeFormat, dateTimeFormatTimeAgo } from '@grafana/data'; @@ -45,12 +45,12 @@ export interface Props { teams: Team[], orgs: UserOrg[], sessions: UserSession[], - user?: User + user?: UserDTO ) => JSX.Element; } export interface State { - user?: User; + user?: UserDTO; teams: Team[]; orgs: UserOrg[]; sessions: UserSession[]; diff --git a/public/app/features/profile/ChangePasswordForm.tsx b/public/app/features/profile/ChangePasswordForm.tsx index 9937659a484..bf27dba2233 100644 --- a/public/app/features/profile/ChangePasswordForm.tsx +++ b/public/app/features/profile/ChangePasswordForm.tsx @@ -1,20 +1,27 @@ import React, { FC } from 'react'; import config from 'app/core/config'; +import { UserDTO } from 'app/types'; import { Button, LinkButton, Form, Field, Input, HorizontalGroup } from '@grafana/ui'; import { ChangePasswordFields } from 'app/core/utils/UserProvider'; import { css } from 'emotion'; export interface Props { + user: UserDTO; isSaving: boolean; onChangePassword: (payload: ChangePasswordFields) => void; } -export const ChangePasswordForm: FC = ({ onChangePassword, isSaving }) => { - const { ldapEnabled, authProxyEnabled } = config; +export const ChangePasswordForm: FC = ({ user, onChangePassword, isSaving }) => { + const { ldapEnabled, authProxyEnabled, disableLoginForm } = config; + const authSource = user.authLabels?.length && user.authLabels[0]; if (ldapEnabled || authProxyEnabled) { return

You cannot change password when ldap or auth proxy authentication is enabled.

; } + if (authSource && disableLoginForm) { + return

Password cannot be changed here!

; + } + return (
{ - render() { - const { navModel } = this.props; - return ( - - - {({ changePassword }, states) => ( - -

Change Your Password

- -
- )} -
-
- ); - } -} +export const ChangePasswordPage: FC = ({ navModel }) => ( + + + {( + api: UserAPI, + states: LoadingStates, + teams: Team[], + orgs: UserOrg[], + sessions: UserSession[], + user: UserDTO + ) => { + return ( + +

Change Your Password

+ {states.loadUser ? ( + + ) : ( + + )} +
+ ); + }} +
+
+); function mapStateToProps(state: StoreState) { return { diff --git a/public/app/features/profile/UserOrganizations.tsx b/public/app/features/profile/UserOrganizations.tsx index a0a178ea2c0..901ce469b62 100644 --- a/public/app/features/profile/UserOrganizations.tsx +++ b/public/app/features/profile/UserOrganizations.tsx @@ -1,9 +1,9 @@ import React, { PureComponent } from 'react'; -import { User, UserOrg } from 'app/types'; +import { UserDTO, UserOrg } from 'app/types'; import { LoadingPlaceholder, Button } from '@grafana/ui'; export interface Props { - user: User; + user: UserDTO; orgs: UserOrg[]; isLoading: boolean; loadOrgs: () => void; diff --git a/public/app/features/profile/UserProfileEdit.tsx b/public/app/features/profile/UserProfileEdit.tsx index ec6c59189f2..79a29d58980 100644 --- a/public/app/features/profile/UserProfileEdit.tsx +++ b/public/app/features/profile/UserProfileEdit.tsx @@ -6,7 +6,7 @@ import { config } from '@grafana/runtime'; import { NavModel } from '@grafana/data'; import { UserProvider, UserAPI, LoadingStates } from 'app/core/utils/UserProvider'; import { getNavModel } from 'app/core/selectors/navModel'; -import { User, Team, UserOrg, UserSession, StoreState } from 'app/types'; +import { UserDTO, Team, UserOrg, UserSession, StoreState } from 'app/types'; import { SharedPreferences } from 'app/core/components/SharedPreferences/SharedPreferences'; import Page from 'app/core/components/Page/Page'; import { UserTeams } from './UserTeams'; @@ -21,7 +21,14 @@ export interface Props { export const UserProfileEdit: FC = ({ navModel }) => ( - {(api: UserAPI, states: LoadingStates, teams: Team[], orgs: UserOrg[], sessions: UserSession[], user: User) => { + {( + api: UserAPI, + states: LoadingStates, + teams: Team[], + orgs: UserOrg[], + sessions: UserSession[], + user: UserDTO + ) => { return ( {states.loadUser ? ( diff --git a/public/app/features/profile/UserProfileEditForm.tsx b/public/app/features/profile/UserProfileEditForm.tsx index c116d03c59a..71a0b7f600a 100644 --- a/public/app/features/profile/UserProfileEditForm.tsx +++ b/public/app/features/profile/UserProfileEditForm.tsx @@ -1,11 +1,11 @@ import React, { FC } from 'react'; import { Button, Tooltip, Icon, Form, Input, Field, FieldSet } from '@grafana/ui'; -import { User } from 'app/types'; +import { UserDTO } from 'app/types'; import config from 'app/core/config'; import { ProfileUpdateFields } from 'app/core/utils/UserProvider'; export interface Props { - user: User; + user: UserDTO; isSavingUser: boolean; updateProfile: (payload: ProfileUpdateFields) => void; } @@ -22,8 +22,14 @@ export const UserProfileEditForm: FC = ({ user, isSavingUser, updateProfi {({ register, errors }) => { return (
- - + + } + /> void;