mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* API: authorize admin/users views * Render admin/users components based on user's permissions * Add LDAP permissions (required by admin/user page) * Extend default admin role by LDAP permissions * Show/hide LDAP debug views * Render LDAP debug page if user has access * Authorize LDAP debug view * fix permissions definitions * Add LDAP page permissions * remove ambiguous permissions check * Hide logout buttons in sessions table * Add org/users permissions * Use org permissions for managing user roles in orgs * Apply permissions to org/users * Apply suggestions from review * Fix tests * remove scopes from the frontend * Tweaks according to review * Handle /invites endpoints
108 lines
3.2 KiB
TypeScript
108 lines
3.2 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { ConfirmButton, RadioButtonGroup, Icon } from '@grafana/ui';
|
|
import { cx } from '@emotion/css';
|
|
import { AccessControlAction } from 'app/types';
|
|
import { contextSrv } from 'app/core/core';
|
|
|
|
interface Props {
|
|
isGrafanaAdmin: boolean;
|
|
|
|
onGrafanaAdminChange: (isGrafanaAdmin: boolean) => void;
|
|
}
|
|
|
|
interface State {
|
|
isEditing: boolean;
|
|
currentAdminOption: string;
|
|
}
|
|
|
|
const adminOptions = [
|
|
{ label: 'Yes', value: 'YES' },
|
|
{ label: 'No', value: 'NO' },
|
|
];
|
|
|
|
export class UserPermissions extends PureComponent<Props, State> {
|
|
state = {
|
|
isEditing: false,
|
|
currentAdminOption: this.props.isGrafanaAdmin ? 'YES' : 'NO',
|
|
};
|
|
|
|
onChangeClick = () => {
|
|
this.setState({ isEditing: true });
|
|
};
|
|
|
|
onCancelClick = () => {
|
|
this.setState({
|
|
isEditing: false,
|
|
currentAdminOption: this.props.isGrafanaAdmin ? 'YES' : 'NO',
|
|
});
|
|
};
|
|
|
|
onGrafanaAdminChange = () => {
|
|
const { currentAdminOption } = this.state;
|
|
const newIsGrafanaAdmin = currentAdminOption === 'YES' ? true : false;
|
|
this.props.onGrafanaAdminChange(newIsGrafanaAdmin);
|
|
};
|
|
|
|
onAdminOptionSelect = (value: string) => {
|
|
this.setState({ currentAdminOption: value });
|
|
};
|
|
|
|
render() {
|
|
const { isGrafanaAdmin } = this.props;
|
|
const { isEditing, currentAdminOption } = this.state;
|
|
const changeButtonContainerClass = cx('pull-right');
|
|
const canChangePermissions = contextSrv.hasPermission(AccessControlAction.UsersPermissionsUpdate);
|
|
|
|
return (
|
|
<>
|
|
<h3 className="page-heading">Permissions</h3>
|
|
<div className="gf-form-group">
|
|
<div className="gf-form">
|
|
<table className="filter-table form-inline">
|
|
<tbody>
|
|
<tr>
|
|
<td className="width-16">Grafana Admin</td>
|
|
{isEditing ? (
|
|
<td colSpan={2}>
|
|
<RadioButtonGroup
|
|
options={adminOptions}
|
|
value={currentAdminOption}
|
|
onChange={this.onAdminOptionSelect}
|
|
/>
|
|
</td>
|
|
) : (
|
|
<td colSpan={2}>
|
|
{isGrafanaAdmin ? (
|
|
<>
|
|
<Icon name="shield" /> Yes
|
|
</>
|
|
) : (
|
|
<>No</>
|
|
)}
|
|
</td>
|
|
)}
|
|
<td>
|
|
<div className={changeButtonContainerClass}>
|
|
{canChangePermissions && (
|
|
<ConfirmButton
|
|
className="pull-right"
|
|
onClick={this.onChangeClick}
|
|
onConfirm={this.onGrafanaAdminChange}
|
|
onCancel={this.onCancelClick}
|
|
confirmText="Change"
|
|
>
|
|
Change
|
|
</ConfirmButton>
|
|
)}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
}
|