mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
Library Panels: Fix library panel creation with RBAC enabled (#76553)
This commit is contained in:
parent
327ae398e6
commit
b215d2f0fb
@ -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 {
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user