actions.ts 869 B

12345678910111213141516171819202122232425262728
  1. import { getBackendSrv } from '@grafana/runtime';
  2. import { accessControlQueryParam } from 'app/core/utils/accessControl';
  3. import { OrgUser } from 'app/types';
  4. import { ThunkResult } from '../../../types';
  5. import { usersLoaded } from './reducers';
  6. export function loadUsers(): ThunkResult<void> {
  7. return async (dispatch) => {
  8. const users = await getBackendSrv().get('/api/org/users', accessControlQueryParam());
  9. dispatch(usersLoaded(users));
  10. };
  11. }
  12. export function updateUser(user: OrgUser): ThunkResult<void> {
  13. return async (dispatch) => {
  14. await getBackendSrv().patch(`/api/org/users/${user.userId}`, { role: user.role });
  15. dispatch(loadUsers());
  16. };
  17. }
  18. export function removeUser(userId: number): ThunkResult<void> {
  19. return async (dispatch) => {
  20. await getBackendSrv().delete(`/api/org/users/${userId}`);
  21. dispatch(loadUsers());
  22. };
  23. }