Dashboards: Fix dashboard listing when user can't list any folders (#77983)

* return empty list of folder if the user doesn't have the permissions to view folders

* fix the empty folder list initialisation
This commit is contained in:
Ieva 2023-11-10 11:27:53 +00:00 committed by GitHub
parent 7d2d5fbe89
commit 6097ff255c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,9 @@ import { getGrafanaSearcher, NestedFolderDTO } from 'app/features/search/service
import { queryResultToViewItem } from 'app/features/search/service/utils'; import { queryResultToViewItem } from 'app/features/search/service/utils';
import { DashboardViewItem } from 'app/features/search/types'; import { DashboardViewItem } from 'app/features/search/types';
import { contextSrv } from '../../../core/core';
import { AccessControlAction } from '../../../types';
export const PAGE_SIZE = 50; export const PAGE_SIZE = 50;
export async function listFolders( export async function listFolders(
@ -18,11 +21,14 @@ export async function listFolders(
const backendSrv = getBackendSrv(); const backendSrv = getBackendSrv();
const folders = await backendSrv.get<NestedFolderDTO[]>('/api/folders', { let folders: NestedFolderDTO[] = [];
parentUid: parentUID, if (contextSrv.hasPermission(AccessControlAction.FoldersRead)) {
page, folders = await backendSrv.get<NestedFolderDTO[]>('/api/folders', {
limit: pageSize, parentUid: parentUID,
}); page,
limit: pageSize,
});
}
return folders.map((item) => ({ return folders.map((item) => ({
kind: 'folder', kind: 'folder',