2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { OrgUser } from 'app/types';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { ThunkResult } from '../../../types';
|
|
|
|
|
2022-02-21 05:37:49 -06:00
|
|
|
import { usersLoaded } from './reducers';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
export function loadUsers(): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2022-01-19 04:27:45 -06:00
|
|
|
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> {
|
2021-01-20 00:59:48 -06:00
|
|
|
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> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2018-10-03 02:43:10 -05:00
|
|
|
await getBackendSrv().delete(`/api/org/users/${userId}`);
|
|
|
|
dispatch(loadUsers());
|
|
|
|
};
|
|
|
|
}
|