mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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 != nil {
|
||||||
if *cmd.FolderUID == "" {
|
if *cmd.FolderUID == "" {
|
||||||
cmd.FolderID = 0
|
cmd.FolderID = 0
|
||||||
|
generalFolderUID := ac.GeneralFolderUID
|
||||||
|
cmd.FolderUID = &generalFolderUID
|
||||||
} else {
|
} else {
|
||||||
folder, err := l.folderService.Get(c.Req.Context(), &folder.GetFolderQuery{OrgID: c.SignedInUser.GetOrgID(), UID: cmd.FolderUID, SignedInUser: c.SignedInUser})
|
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 {
|
if err != nil || folder == nil {
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { useAsync, useDebounce } from 'react-use';
|
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 { Button, Field, Input, Modal } from '@grafana/ui';
|
||||||
import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker';
|
import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker';
|
||||||
import { t, Trans } from 'app/core/internationalization';
|
import { t, Trans } from 'app/core/internationalization';
|
||||||
|
|
||||||
import { PanelModel } from '../../../dashboard/state';
|
import { PanelModel } from '../../../dashboard/state';
|
||||||
import { getLibraryPanelByName } from '../../state/api';
|
import { getLibraryPanelByName } from '../../state/api';
|
||||||
|
import { LibraryElementDTO } from '../../types';
|
||||||
import { usePanelSave } from '../../utils/usePanelSave';
|
import { usePanelSave } from '../../utils/usePanelSave';
|
||||||
|
|
||||||
interface AddLibraryPanelContentsProps {
|
interface AddLibraryPanelContentsProps {
|
||||||
@ -28,9 +29,11 @@ export const AddLibraryPanelContents = ({ panel, initialFolderUid, onDismiss }:
|
|||||||
const { saveLibraryPanel } = usePanelSave();
|
const { saveLibraryPanel } = usePanelSave();
|
||||||
const onCreate = useCallback(() => {
|
const onCreate = useCallback(() => {
|
||||||
panel.libraryPanel = { uid: '', name: panelName };
|
panel.libraryPanel = { uid: '', name: panelName };
|
||||||
saveLibraryPanel(panel, folderUid!).then((res) => {
|
saveLibraryPanel(panel, folderUid!).then((res: LibraryElementDTO | FetchError) => {
|
||||||
if (!(res instanceof Error)) {
|
if (!isFetchError(res)) {
|
||||||
onDismiss();
|
onDismiss();
|
||||||
|
} else {
|
||||||
|
panel.libraryPanel = undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [panel, panelName, folderUid, onDismiss, saveLibraryPanel]);
|
}, [panel, panelName, folderUid, onDismiss, saveLibraryPanel]);
|
||||||
|
Loading…
Reference in New Issue
Block a user