2021-04-22 05:19:41 -05:00
|
|
|
import { AccessControlAction, ThunkResult } from '../../../types';
|
2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { OrgUser } from 'app/types';
|
|
|
|
import { inviteesLoaded, usersLoaded } from './reducers';
|
2021-04-22 05:19:41 -05:00
|
|
|
import { contextSrv } from 'app/core/core';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
export function loadUsers(): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2018-10-03 02:43:10 -05:00
|
|
|
const users = await getBackendSrv().get('/api/org/users');
|
|
|
|
dispatch(usersLoaded(users));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadInvitees(): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2021-04-22 05:19:41 -05:00
|
|
|
if (!contextSrv.hasPermission(AccessControlAction.OrgUsersAdd)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-03 02:43:10 -05:00
|
|
|
const invitees = await getBackendSrv().get('/api/org/invites');
|
|
|
|
dispatch(inviteesLoaded(invitees));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function revokeInvite(code: string): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2018-10-03 02:43:10 -05:00
|
|
|
await getBackendSrv().patch(`/api/org/invites/${code}/revoke`, {});
|
|
|
|
dispatch(loadInvitees());
|
|
|
|
};
|
|
|
|
}
|