grafana/public/app/features/users/state/actions.ts

29 lines
869 B
TypeScript
Raw Normal View History

import { getBackendSrv } from '@grafana/runtime';
import { accessControlQueryParam } from 'app/core/utils/accessControl';
import { OrgUser } from 'app/types';
import { ThunkResult } from '../../../types';
import { usersLoaded } from './reducers';
2018-10-03 02:43:10 -05:00
export function loadUsers(): ThunkResult<void> {
return async (dispatch) => {
const users = await getBackendSrv().get('/api/org/users', accessControlQueryParam());
2018-10-03 02:43:10 -05:00
dispatch(usersLoaded(users));
};
}
export function updateUser(user: OrgUser): ThunkResult<void> {
return async (dispatch) => {
2018-10-03 03:54:15 -05:00
await getBackendSrv().patch(`/api/org/users/${user.userId}`, { role: user.role });
2018-10-03 02:43:10 -05:00
dispatch(loadUsers());
};
}
export function removeUser(userId: number): ThunkResult<void> {
return async (dispatch) => {
2018-10-03 02:43:10 -05:00
await getBackendSrv().delete(`/api/org/users/${userId}`);
dispatch(loadUsers());
};
}