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