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

pull/45398/head
Gabriel MABILLE 3 years ago committed by GitHub
parent ed5b2e5210
commit 91dd0563c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      public/app/features/teams/TeamList.tsx
  2. 11
      public/app/features/teams/state/actions.ts

@ -42,10 +42,7 @@ export class TeamList extends PureComponent<Props, State> {
} }
componentDidMount() { componentDidMount() {
// Don't fetch teams if the user cannot see any this.fetchTeams();
if (contextSrv.hasAccess(AccessControlAction.ActionTeamsRead, true)) {
this.fetchTeams();
}
if (contextSrv.licensedAccessControlEnabled() && contextSrv.hasPermission(AccessControlAction.ActionRolesList)) { if (contextSrv.licensedAccessControlEnabled() && contextSrv.hasPermission(AccessControlAction.ActionRolesList)) {
this.fetchRoleOptions(); this.fetchRoleOptions();
} }
@ -198,10 +195,8 @@ export class TeamList extends PureComponent<Props, State> {
renderList() { renderList() {
const { teamsCount, hasFetched } = this.props; const { teamsCount, hasFetched } = this.props;
// If the user cannot read any team, we didn't fetch them
let isLoading = !hasFetched && contextSrv.hasAccess(AccessControlAction.ActionTeamsRead, true);
if (isLoading) { if (!hasFetched) {
return null; return null;
} }
@ -214,12 +209,10 @@ export class TeamList extends PureComponent<Props, State> {
render() { render() {
const { hasFetched, navModel } = this.props; const { hasFetched, navModel } = this.props;
// If the user cannot read any team, we didn't fetch them
let isLoading = !hasFetched && contextSrv.hasAccess(AccessControlAction.ActionTeamsRead, true);
return ( return (
<Page navModel={navModel}> <Page navModel={navModel}>
<Page.Contents isLoading={isLoading}>{this.renderList()}</Page.Contents> <Page.Contents isLoading={!hasFetched}>{this.renderList()}</Page.Contents>
</Page> </Page>
); );
} }

@ -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());
}; };
} }

Loading…
Cancel
Save