Library Panels: Fix library panel creation with RBAC enabled (#76553)

This commit is contained in:
kay delaney 2023-10-25 14:29:57 +01:00 committed by GitHub
parent 327ae398e6
commit b215d2f0fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -63,6 +63,8 @@ func (l *LibraryElementService) createHandler(c *contextmodel.ReqContext) respon
if cmd.FolderUID != nil {
if *cmd.FolderUID == "" {
cmd.FolderID = 0
generalFolderUID := ac.GeneralFolderUID
cmd.FolderUID = &generalFolderUID
} else {
folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), UID: cmd.FolderUID, SignedInUser: c.SignedInUser})
if err != nil || folder == nil {

View File

@ -1,13 +1,14 @@
import React, { useCallback, useEffect, useState } from 'react';
import { useAsync, useDebounce } from 'react-use';
import { isFetchError } from '@grafana/runtime';
import { FetchError, isFetchError } from '@grafana/runtime';
import { Button, Field, Input, Modal } from '@grafana/ui';
import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker';
import { t, Trans } from 'app/core/internationalization';
import { PanelModel } from '../../../dashboard/state';
import { getLibraryPanelByName } from '../../state/api';
import { LibraryElementDTO } from '../../types';
import { usePanelSave } from '../../utils/usePanelSave';
interface AddLibraryPanelContentsProps {
@ -28,9 +29,11 @@ export const AddLibraryPanelContents = ({ panel, initialFolderUid, onDismiss }:
const { saveLibraryPanel } = usePanelSave();
const onCreate = useCallback(() => {
panel.libraryPanel = { uid: '', name: panelName };
saveLibraryPanel(panel, folderUid!).then((res) => {
if (!(res instanceof Error)) {
saveLibraryPanel(panel, folderUid!).then((res: LibraryElementDTO | FetchError) => {
if (!isFetchError(res)) {
onDismiss();
} else {
panel.libraryPanel = undefined;
}
});
}, [panel, panelName, folderUid, onDismiss, saveLibraryPanel]);