diff --git a/plugins-bundled/internal/plugin-admin-app/src/components/InstallControls.tsx b/plugins-bundled/internal/plugin-admin-app/src/components/InstallControls.tsx index 54676297dc8..7bbf150e41d 100644 --- a/plugins-bundled/internal/plugin-admin-app/src/components/InstallControls.tsx +++ b/plugins-bundled/internal/plugin-admin-app/src/components/InstallControls.tsx @@ -4,15 +4,15 @@ import { gt, satisfies } from 'semver'; import { config } from '@grafana/runtime'; import { Button, HorizontalGroup, Icon, LinkButton, useStyles2 } from '@grafana/ui'; -import { AppEvents, GrafanaTheme2, OrgRole } from '@grafana/data'; +import { AppEvents, GrafanaTheme2 } from '@grafana/data'; import { Metadata, Plugin } from '../types'; -import { hasRole } from '../helpers'; import { api } from '../api'; // This isn't exported in the sdk yet // @ts-ignore import appEvents from 'grafana/app/core/app_events'; +import { isGrafanaAdmin } from '../helpers'; interface Props { localPlugin?: Metadata; @@ -76,7 +76,7 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => { const isDevelopmentBuild = Boolean(localPlugin?.dev); const isEnterprise = remotePlugin?.status === 'enterprise'; - const hasPermission = hasRole(OrgRole.Admin); + const hasPermission = isGrafanaAdmin(); if (isEnterprise) { return ( @@ -97,7 +97,7 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => { {shouldUpdate && (isExternallyManaged ? ( - + {'Update via grafana.com'} ) : ( @@ -107,21 +107,17 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => { ))} {isExternallyManaged ? ( - + {'Uninstall via grafana.com'} ) : ( - - {loading && !shouldUpdate ? 'Uninstalling' : 'Uninstall'} - + <> + + {loading && !shouldUpdate ? 'Uninstalling' : 'Uninstall'} + + {!hasPermission && You need admin privileges to manage this plugin.} + > )} - {!hasPermission && You need admin privileges to manage this plugin.} ); } @@ -138,15 +134,17 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => { return ( {isExternallyManaged ? ( - + {'Install via grafana.com'} ) : ( - - {loading ? 'Installing' : 'Install'} - + <> + + {loading ? 'Installing' : 'Install'} + + {!hasPermission && You need admin privileges to install this plugin.} + > )} - {!hasPermission && You need admin privileges to install this plugin.} ); }; diff --git a/plugins-bundled/internal/plugin-admin-app/src/helpers.ts b/plugins-bundled/internal/plugin-admin-app/src/helpers.ts index 7a8c0631c0a..f353ab03050 100644 --- a/plugins-bundled/internal/plugin-admin-app/src/helpers.ts +++ b/plugins-bundled/internal/plugin-admin-app/src/helpers.ts @@ -1,20 +1,5 @@ -import { OrgRole } from '@grafana/data'; import { config } from '@grafana/runtime'; -export function hasRole(requiredRole: OrgRole): boolean { - const user = config.bootData.user; - switch (requiredRole) { - case OrgRole.Admin: { - return user.orgRole === OrgRole.Admin; - } - case OrgRole.Editor: { - return user.orgRole === OrgRole.Admin || user.orgRole === OrgRole.Editor; - } - case OrgRole.Viewer: { - return user.orgRole === OrgRole.Admin || user.orgRole === OrgRole.Editor || user.orgRole === OrgRole.Viewer; - } - default: { - return false; - } - } +export function isGrafanaAdmin(): boolean { + return config.bootData.user.isGrafanaAdmin; }