From b31316753aa681eeac126d0363772319fdc23daf Mon Sep 17 00:00:00 2001 From: Selene Date: Tue, 21 Sep 2021 17:47:35 +0200 Subject: [PATCH] Disable external user's change role in admin (#39172) * Disable external user's change role in admin * Missing part of the tooltip text * Disable change button with the tooltip instead dropdown * Missing refactor * Apply suggestion --- public/app/features/admin/UserAdminPage.tsx | 1 + public/app/features/admin/UserOrgs.tsx | 109 +++++++++++++++++--- 2 files changed, 96 insertions(+), 14 deletions(-) diff --git a/public/app/features/admin/UserAdminPage.tsx b/public/app/features/admin/UserAdminPage.tsx index 7479386f76d..ec5fa2eb9ec 100644 --- a/public/app/features/admin/UserAdminPage.tsx +++ b/public/app/features/admin/UserAdminPage.tsx @@ -129,6 +129,7 @@ export class UserAdminPage extends PureComponent { {orgs && ( void; onOrgRoleChange: (orgId: number, newRole: OrgRole) => void; @@ -29,13 +42,12 @@ export class UserOrgs extends PureComponent { }; render() { - const { orgs, onOrgRoleChange, onOrgRemove, onOrgAdd } = this.props; + const { orgs, isExternalUser, onOrgRoleChange, onOrgRemove, onOrgAdd } = this.props; const { showAddOrgModal } = this.state; const addToOrgContainerClass = css` margin-top: 0.8rem; `; const canAddToOrg = contextSrv.hasPermission(AccessControlAction.OrgUsersAdd); - return ( <>

Organizations

@@ -46,6 +58,7 @@ export class UserOrgs extends PureComponent { {orgs.map((org, index) => ( { label: css` font-weight: 500; `, + disabledTooltip: css` + display: flex; + `, + tooltipItem: css` + margin-left: 5px; + `, + tooltipItemLink: css` + color: ${theme.palette.blue95}; + `, }; }); interface OrgRowProps extends Themeable { org: UserOrg; + isExternalUser?: boolean; onOrgRemove: (orgId: number) => void; onOrgRoleChange: (orgId: number, newRole: OrgRole) => void; } @@ -121,7 +144,7 @@ class UnThemedOrgRow extends PureComponent { }; render() { - const { org, theme } = this.props; + const { org, isExternalUser, theme } = this.props; const { currentRole, isChangingRole } = this.state; const styles = getOrgRowStyles(theme); const labelClass = cx('width-16', styles.label); @@ -141,14 +164,12 @@ class UnThemedOrgRow extends PureComponent {
{canChangeRole && ( - - Change role - + )}
@@ -255,3 +276,63 @@ export class AddToOrgModal extends PureComponent void; + onCancelClick: () => void; + onOrgRoleSave: () => void; +} + +const getChangeOrgButtonTheme = (theme: GrafanaTheme2) => ({ + disabledTooltip: css` + display: flex; + `, + tooltipItemLink: css` + color: ${theme.v1.palette.blue95}; + `, +}); + +export function ChangeOrgButton({ + onChangeRoleClick, + isExternalUser, + onOrgRoleSave, + onCancelClick, +}: ChangeOrgButtonProps): ReactElement { + const styles = useStyles2(getChangeOrgButtonTheme); + return ( +
+ + Change role + + {isExternalUser && ( + + This user's role is not editable because it is synchronized from your auth provider. Refer to + the  + + Grafana authentication docs + +  for details. +
+ } + > + + + )} + + ); +}