mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AccessControl: Disable user remove and user update roles when they do not have the permissions (#43429)
* AccessControl: Disable user remove and update roles when they do not have the appropriate permissions * AccessControl: Ensure frontend tests pass in CI
This commit is contained in:
@@ -8,6 +8,7 @@ import { ConfirmModal } from '@grafana/ui';
|
|||||||
jest.mock('app/core/core', () => ({
|
jest.mock('app/core/core', () => ({
|
||||||
contextSrv: {
|
contextSrv: {
|
||||||
hasPermission: () => true,
|
hasPermission: () => true,
|
||||||
|
hasPermissionInMetadata: () => true,
|
||||||
accessControlEnabled: () => false,
|
accessControlEnabled: () => false,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ export interface Props {
|
|||||||
|
|
||||||
const UsersTable: FC<Props> = (props) => {
|
const UsersTable: FC<Props> = (props) => {
|
||||||
const { users, orgId, onRoleChange, onRemoveUser } = props;
|
const { users, orgId, onRoleChange, onRemoveUser } = props;
|
||||||
const canUpdateRole = contextSrv.hasPermission(AccessControlAction.OrgUsersRoleUpdate);
|
|
||||||
const canRemoveFromOrg = contextSrv.hasPermission(AccessControlAction.OrgUsersRemove);
|
|
||||||
const rolePickerDisabled = !canUpdateRole;
|
|
||||||
|
|
||||||
const [showRemoveModal, setShowRemoveModal] = useState<string | boolean>(false);
|
const [showRemoveModal, setShowRemoveModal] = useState<string | boolean>(false);
|
||||||
const [roleOptions, setRoleOptions] = useState<Role[]>([]);
|
const [roleOptions, setRoleOptions] = useState<Role[]>([]);
|
||||||
@@ -89,19 +86,19 @@ const UsersTable: FC<Props> = (props) => {
|
|||||||
onBuiltinRoleChange={(newRole) => onRoleChange(newRole, user)}
|
onBuiltinRoleChange={(newRole) => onRoleChange(newRole, user)}
|
||||||
getRoleOptions={getRoleOptions}
|
getRoleOptions={getRoleOptions}
|
||||||
getBuiltinRoles={getBuiltinRoles}
|
getBuiltinRoles={getBuiltinRoles}
|
||||||
disabled={rolePickerDisabled}
|
disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRoleUpdate, user)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<OrgRolePicker
|
<OrgRolePicker
|
||||||
aria-label="Role"
|
aria-label="Role"
|
||||||
value={user.role}
|
value={user.role}
|
||||||
disabled={!canUpdateRole}
|
disabled={!contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRoleUpdate, user)}
|
||||||
onChange={(newRole) => onRoleChange(newRole, user)}
|
onChange={(newRole) => onRoleChange(newRole, user)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{canRemoveFromOrg && (
|
{contextSrv.hasPermissionInMetadata(AccessControlAction.OrgUsersRemove, user) && (
|
||||||
<td>
|
<td>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import { getBackendSrv } from '@grafana/runtime';
|
|||||||
import { OrgUser } from 'app/types';
|
import { OrgUser } from 'app/types';
|
||||||
import { inviteesLoaded, usersLoaded } from './reducers';
|
import { inviteesLoaded, usersLoaded } from './reducers';
|
||||||
import { contextSrv } from 'app/core/core';
|
import { contextSrv } from 'app/core/core';
|
||||||
|
import { addAccessControlQueryParam } from 'app/core/utils/accessControl';
|
||||||
|
|
||||||
export function loadUsers(): ThunkResult<void> {
|
export function loadUsers(): ThunkResult<void> {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
const users = await getBackendSrv().get('/api/org/users');
|
const users = await getBackendSrv().get(addAccessControlQueryParam('/api/org/users'));
|
||||||
dispatch(usersLoaded(users));
|
dispatch(usersLoaded(users));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { OrgRole } from '.';
|
import { OrgRole } from '.';
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue, WithAccessControlMetadata } from '@grafana/data';
|
||||||
|
export interface OrgUser extends WithAccessControlMetadata {
|
||||||
export interface OrgUser {
|
|
||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
email: string;
|
email: string;
|
||||||
lastSeenAt: string;
|
lastSeenAt: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user