2019-06-03 17:55:59 +02:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
2020-01-13 08:03:22 +01:00
|
|
|
import { OrgUser } from 'app/types';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
|
|
|
|
import { ThunkResult } from '../../../types';
|
|
|
|
|
|
2022-02-21 11:37:49 +00:00
|
|
|
import { usersLoaded } from './reducers';
|
2018-10-03 09:43:10 +02:00
|
|
|
|
|
|
|
|
export function loadUsers(): ThunkResult<void> {
|
2021-01-20 07:59:48 +01:00
|
|
|
return async (dispatch) => {
|
2022-01-19 11:27:45 +01:00
|
|
|
const users = await getBackendSrv().get('/api/org/users', accessControlQueryParam());
|
2018-10-03 09:43:10 +02:00
|
|
|
dispatch(usersLoaded(users));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function updateUser(user: OrgUser): ThunkResult<void> {
|
2021-01-20 07:59:48 +01:00
|
|
|
return async (dispatch) => {
|
2018-10-03 10:54:15 +02:00
|
|
|
await getBackendSrv().patch(`/api/org/users/${user.userId}`, { role: user.role });
|
2018-10-03 09:43:10 +02:00
|
|
|
dispatch(loadUsers());
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function removeUser(userId: number): ThunkResult<void> {
|
2021-01-20 07:59:48 +01:00
|
|
|
return async (dispatch) => {
|
2018-10-03 09:43:10 +02:00
|
|
|
await getBackendSrv().delete(`/api/org/users/${userId}`);
|
|
|
|
|
dispatch(loadUsers());
|
|
|
|
|
};
|
|
|
|
|
}
|