AccessControl: Trigger permission reload with team removal (#45383)

This commit is contained in:
Gabriel MABILLE
2022-02-15 14:23:40 +01:00
committed by GitHub
parent ed5b2e5210
commit 91dd0563c9
2 changed files with 13 additions and 11 deletions

View File

@@ -1,13 +1,20 @@
import { getBackendSrv } from '@grafana/runtime';
import { TeamMember, ThunkResult } from 'app/types';
import { AccessControlAction, TeamMember, ThunkResult } from 'app/types';
import { updateNavIndex } from 'app/core/actions';
import { buildNavModel } from './navModel';
import { teamGroupsLoaded, teamLoaded, teamMembersLoaded, teamsLoaded } from './reducers';
import { accessControlQueryParam } from 'app/core/utils/accessControl';
import { contextSrv } from 'app/core/core';
export function loadTeams(): ThunkResult<void> {
return async (dispatch) => {
// Early return if the user cannot list teams
if (!contextSrv.hasPermission(AccessControlAction.ActionTeamsRead)) {
dispatch(teamsLoaded([]));
return;
}
const response = await getBackendSrv().get(
'/api/teams/search',
accessControlQueryParam({ perpage: 1000, page: 1 })
@@ -83,6 +90,8 @@ export function removeTeamGroup(groupId: string): ThunkResult<void> {
export function deleteTeam(id: number): ThunkResult<void> {
return async (dispatch) => {
await getBackendSrv().delete(`/api/teams/${id}`);
// Update users permissions in case they lost teams.read with the deletion
await contextSrv.fetchUserPermissions();
dispatch(loadTeams());
};
}