mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Check for Grafana admin instead of Org admin (#35000)
* check for grafana admin where necessary * fix
This commit is contained in:
parent
51afde34bd
commit
aba1801193
@ -4,15 +4,15 @@ import { gt, satisfies } from 'semver';
|
|||||||
|
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { Button, HorizontalGroup, Icon, LinkButton, useStyles2 } from '@grafana/ui';
|
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 { Metadata, Plugin } from '../types';
|
||||||
import { hasRole } from '../helpers';
|
|
||||||
import { api } from '../api';
|
import { api } from '../api';
|
||||||
|
|
||||||
// This isn't exported in the sdk yet
|
// This isn't exported in the sdk yet
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import appEvents from 'grafana/app/core/app_events';
|
import appEvents from 'grafana/app/core/app_events';
|
||||||
|
import { isGrafanaAdmin } from '../helpers';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
localPlugin?: Metadata;
|
localPlugin?: Metadata;
|
||||||
@ -76,7 +76,7 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => {
|
|||||||
|
|
||||||
const isDevelopmentBuild = Boolean(localPlugin?.dev);
|
const isDevelopmentBuild = Boolean(localPlugin?.dev);
|
||||||
const isEnterprise = remotePlugin?.status === 'enterprise';
|
const isEnterprise = remotePlugin?.status === 'enterprise';
|
||||||
const hasPermission = hasRole(OrgRole.Admin);
|
const hasPermission = isGrafanaAdmin();
|
||||||
|
|
||||||
if (isEnterprise) {
|
if (isEnterprise) {
|
||||||
return (
|
return (
|
||||||
@ -97,7 +97,7 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => {
|
|||||||
<HorizontalGroup height="auto">
|
<HorizontalGroup height="auto">
|
||||||
{shouldUpdate &&
|
{shouldUpdate &&
|
||||||
(isExternallyManaged ? (
|
(isExternallyManaged ? (
|
||||||
<LinkButton disabled={!hasPermission} href={externalManageLink} target="_blank" rel="noopener noreferrer">
|
<LinkButton href={externalManageLink} target="_blank" rel="noopener noreferrer">
|
||||||
{'Update via grafana.com'}
|
{'Update via grafana.com'}
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
) : (
|
) : (
|
||||||
@ -107,21 +107,17 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => {
|
|||||||
))}
|
))}
|
||||||
|
|
||||||
{isExternallyManaged ? (
|
{isExternallyManaged ? (
|
||||||
<LinkButton
|
<LinkButton variant="destructive" href={externalManageLink} target="_blank" rel="noopener noreferrer">
|
||||||
variant="destructive"
|
|
||||||
disabled={!hasPermission}
|
|
||||||
href={externalManageLink}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
{'Uninstall via grafana.com'}
|
{'Uninstall via grafana.com'}
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
) : (
|
) : (
|
||||||
<Button variant="destructive" disabled={loading || !hasPermission} onClick={onUninstall}>
|
<>
|
||||||
{loading && !shouldUpdate ? 'Uninstalling' : 'Uninstall'}
|
<Button variant="destructive" disabled={loading || !hasPermission} onClick={onUninstall}>
|
||||||
</Button>
|
{loading && !shouldUpdate ? 'Uninstalling' : 'Uninstall'}
|
||||||
|
</Button>
|
||||||
|
{!hasPermission && <div className={styles.message}>You need admin privileges to manage this plugin.</div>}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{!hasPermission && <div className={styles.message}>You need admin privileges to manage this plugin.</div>}
|
|
||||||
</HorizontalGroup>
|
</HorizontalGroup>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -138,15 +134,17 @@ export const InstallControls = ({ localPlugin, remotePlugin }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<HorizontalGroup height="auto">
|
<HorizontalGroup height="auto">
|
||||||
{isExternallyManaged ? (
|
{isExternallyManaged ? (
|
||||||
<LinkButton disabled={!hasPermission} href={externalManageLink} target="_blank" rel="noopener noreferrer">
|
<LinkButton href={externalManageLink} target="_blank" rel="noopener noreferrer">
|
||||||
{'Install via grafana.com'}
|
{'Install via grafana.com'}
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
) : (
|
) : (
|
||||||
<Button disabled={loading || !hasPermission} onClick={onInstall}>
|
<>
|
||||||
{loading ? 'Installing' : 'Install'}
|
<Button disabled={loading || !hasPermission} onClick={onInstall}>
|
||||||
</Button>
|
{loading ? 'Installing' : 'Install'}
|
||||||
|
</Button>
|
||||||
|
{!hasPermission && <div className={styles.message}>You need admin privileges to install this plugin.</div>}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{!hasPermission && <div className={styles.message}>You need admin privileges to install this plugin.</div>}
|
|
||||||
</HorizontalGroup>
|
</HorizontalGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,20 +1,5 @@
|
|||||||
import { OrgRole } from '@grafana/data';
|
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
|
|
||||||
export function hasRole(requiredRole: OrgRole): boolean {
|
export function isGrafanaAdmin(): boolean {
|
||||||
const user = config.bootData.user;
|
return config.bootData.user.isGrafanaAdmin;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user