diff --git a/pkg/storage/unified/entitybridge/entitybridge.go b/pkg/storage/unified/entitybridge/entitybridge.go index 2fe36766add..16ccc24e216 100644 --- a/pkg/storage/unified/entitybridge/entitybridge.go +++ b/pkg/storage/unified/entitybridge/entitybridge.go @@ -34,7 +34,7 @@ func ProvideResourceServer(db db.DB, cfg *setting.Cfg, features featuremgmt.Feat // Create a local blob filesystem blob store if supportBlobs { dir := filepath.Join(cfg.DataPath, "unistore", "blobs") - if err := os.MkdirAll(dir, 0o755); err != nil { + if err := os.MkdirAll(dir, 0o750); err != nil { return nil, err } @@ -77,7 +77,7 @@ func ProvideResourceServer(db db.DB, cfg *setting.Cfg, features featuremgmt.Feat opts.Lifecycle = bridge } else { dir := filepath.Join(cfg.DataPath, "unistore", "resource") - if err := os.MkdirAll(dir, 0o755); err != nil { + if err := os.MkdirAll(dir, 0o750); err != nil { return nil, err } diff --git a/pkg/storage/unified/resource/go.sum b/pkg/storage/unified/resource/go.sum index 4a6e93256fd..fe8c86a681a 100644 --- a/pkg/storage/unified/resource/go.sum +++ b/pkg/storage/unified/resource/go.sum @@ -33,6 +33,7 @@ github.com/fullstorydev/grpchan v1.1.1 h1:heQqIJlAv5Cnks9a70GRL2EJke6QQoUB25VGR6 github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7G7k= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx index 91e50fba9e1..1f8a113de7e 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.test.tsx @@ -25,7 +25,7 @@ import { transformSaveModelToScene, } from '../serialization/transformSaveModelToScene'; import { DecoratedRevisionModel } from '../settings/VersionsEditView'; -import { historySrv } from '../settings/version-history/HistorySrv'; +import { getHistorySrv } from '../settings/version-history/HistorySrv'; import { dashboardSceneGraph } from '../utils/dashboardSceneGraph'; import { djb2Hash } from '../utils/djb2Hash'; import { findVizPanelByKey } from '../utils/utils'; @@ -1137,7 +1137,7 @@ describe('DashboardScene', () => { version: 4, }); - jest.mocked(historySrv.restoreDashboard).mockResolvedValue({ version: newVersion }); + jest.mocked(getHistorySrv().restoreDashboard).mockResolvedValue({ version: newVersion }); jest.mocked(transformSaveModelToScene).mockReturnValue(mockScene); return scene.onRestore(getVersionMock()).then((res) => { @@ -1150,7 +1150,7 @@ describe('DashboardScene', () => { it('should return early if historySrv does not return a valid version number', () => { jest - .mocked(historySrv.restoreDashboard) + .mocked(getHistorySrv().restoreDashboard) .mockResolvedValueOnce({ version: null }) .mockResolvedValueOnce({ version: undefined }) .mockResolvedValueOnce({ version: Infinity }) diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.tsx index 2b04bec57de..67be7d0fcde 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.tsx @@ -49,7 +49,7 @@ import { import { gridItemToPanel } from '../serialization/transformSceneToSaveModel'; import { DecoratedRevisionModel } from '../settings/VersionsEditView'; import { DashboardEditView } from '../settings/utils'; -import { historySrv } from '../settings/version-history'; +import { getHistorySrv } from '../settings/version-history'; import { DashboardModelCompatibilityWrapper } from '../utils/DashboardModelCompatibilityWrapper'; import { dashboardSceneGraph, getLibraryVizPanelFromVizPanel } from '../utils/dashboardSceneGraph'; import { djb2Hash } from '../utils/djb2Hash'; @@ -355,19 +355,20 @@ export class DashboardScene extends SceneObjectBase { } public onRestore = async (version: DecoratedRevisionModel): Promise => { - const versionRsp = await historySrv.restoreDashboard(version.uid, version.version); - - if (!Number.isInteger(versionRsp.version)) { + const versionRsp = await getHistorySrv().restoreDashboard(version.uid, version.version); + + const rev = (versionRsp as SaveDashboardResponseDTO).version; + if (!Number.isInteger(version)) { return false; } const dashboardDTO: DashboardDTO = { - dashboard: new DashboardModel(version.data), + dashboard: new DashboardModel(version.data!), meta: this.state.meta, }; const dashScene = transformSaveModelToScene(dashboardDTO); const newState = sceneUtils.cloneSceneObjectState(dashScene.state); - newState.version = versionRsp.version; + newState.version = rev; this.setState(newState); this.exitEditMode({ skipConfirm: true, restoreInitialState: false }); diff --git a/public/app/features/dashboard-scene/settings/VersionsEditView.test.tsx b/public/app/features/dashboard-scene/settings/VersionsEditView.test.tsx index f9024d2b8ed..b1256e997b5 100644 --- a/public/app/features/dashboard-scene/settings/VersionsEditView.test.tsx +++ b/public/app/features/dashboard-scene/settings/VersionsEditView.test.tsx @@ -4,7 +4,7 @@ import { DashboardScene } from '../scene/DashboardScene'; import { activateFullSceneTree } from '../utils/test-utils'; import { VERSIONS_FETCH_LIMIT, VersionsEditView } from './VersionsEditView'; -import { historySrv } from './version-history'; +import { getHistorySrv } from './version-history'; jest.mock('./version-history/HistorySrv'); @@ -20,7 +20,7 @@ describe('VersionsEditView', () => { } as unknown as React.FormEvent; beforeEach(async () => { - jest.mocked(historySrv.getHistoryList).mockResolvedValue(getVersions()); + jest.mocked(getHistorySrv().getHistoryList).mockResolvedValue(getVersions()); const result = await buildTestScene(); dashboard = result.dashboard; @@ -81,7 +81,7 @@ describe('VersionsEditView', () => { versionsView.onCheck(mockEvent, 4); jest - .mocked(historySrv.getDashboardVersion) + .mocked(getHistorySrv().getDashboardVersion) .mockResolvedValueOnce({ data: 'lhs' }) .mockResolvedValue({ data: 'rhs' }); @@ -100,7 +100,7 @@ describe('VersionsEditView', () => { versionsView.onCheck(mockEvent, 2); jest - .mocked(historySrv.getDashboardVersion) + .mocked(getHistorySrv().getDashboardVersion) .mockResolvedValueOnce({ data: 'lhs' }) .mockResolvedValue({ data: 'rhs' }); diff --git a/public/app/features/dashboard-scene/settings/VersionsEditView.tsx b/public/app/features/dashboard-scene/settings/VersionsEditView.tsx index e3f54207bfc..3ed616d8095 100644 --- a/public/app/features/dashboard-scene/settings/VersionsEditView.tsx +++ b/public/app/features/dashboard-scene/settings/VersionsEditView.tsx @@ -16,16 +16,10 @@ import { VersionHistoryTable, VersionsHistoryButtons, } from './version-history'; -import { VersionModel, getHistorySrv } from './version-history/HistorySrv'; +import { DecoratedRevisionModel, VersionModel, getHistorySrv } from './version-history/HistorySrv'; export const VERSIONS_FETCH_LIMIT = 10; -export type DecoratedRevisionModel = VersionModel & { - checked: boolean; - createdDateString: string; - ageString: string; -}; - export interface VersionsEditViewState extends DashboardEditViewState { versions?: DecoratedRevisionModel[]; isLoading?: boolean; diff --git a/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts b/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts index 7f64cfe29a0..9ccf740be39 100644 --- a/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts +++ b/public/app/features/dashboard-scene/settings/version-history/HistorySrv.ts @@ -7,19 +7,28 @@ export interface HistoryListOpts { start: number; } -// The raw version from +// The raw version returned from api export interface VersionModel { uid: string; - version: number | string; // resourceVersion in k8s + version: number; // resourceVersion in k8s must be numeric created: string; createdBy: string; message: string; } +// The version used in UI components +export type DecoratedRevisionModel = VersionModel & { + checked: boolean; + createdDateString: string; + ageString: string; + data?: Dashboard +}; + + export interface HistorySrv { getHistoryList(dashboardUID: string, options: HistoryListOpts): Promise; getDashboardVersion(dashboardUID: string, version: number | string): Promise; // Just the spec (for now) - restoreDashboard(dashboardUID: string, version: number | string): Promise; + restoreDashboard(dashboardUID: string, version: number | string): Promise; } class LegacyHistorySrv implements HistorySrv { @@ -40,9 +49,9 @@ class LegacyHistorySrv implements HistorySrv { return info.data; // the dashboard body } - restoreDashboard(dashboardUID: string, version: number): Promise { + restoreDashboard(dashboardUID: string, version: number): Promise { if (typeof dashboardUID !== 'string') { - return Promise.resolve({}); + return Promise.resolve({} as unknown as SaveDashboardResponseDTO); } const url = `api/dashboards/uid/${dashboardUID}/restore`; diff --git a/public/app/features/dashboard-scene/settings/version-history/RevertDashboardModal.tsx b/public/app/features/dashboard-scene/settings/version-history/RevertDashboardModal.tsx index c3e44c132d1..87d96754e27 100644 --- a/public/app/features/dashboard-scene/settings/version-history/RevertDashboardModal.tsx +++ b/public/app/features/dashboard-scene/settings/version-history/RevertDashboardModal.tsx @@ -1,7 +1,7 @@ import { ConfirmModal } from '@grafana/ui'; import { useAppNotification } from 'app/core/copy/appNotification'; -import { DecoratedRevisionModel } from '../VersionsEditView'; +import { DecoratedRevisionModel } from './HistorySrv'; export interface RevertDashboardModalProps { hideModal: () => void; diff --git a/public/app/features/dashboard-scene/settings/version-history/index.ts b/public/app/features/dashboard-scene/settings/version-history/index.ts index c87d2d0b9b7..b9c4201ba43 100644 --- a/public/app/features/dashboard-scene/settings/version-history/index.ts +++ b/public/app/features/dashboard-scene/settings/version-history/index.ts @@ -1,4 +1,4 @@ -export { HistorySrv, historySrv, RevisionsModel } from './HistorySrv'; +export { HistorySrv, getHistorySrv } from './HistorySrv'; export { VersionHistoryTable } from './VersionHistoryTable'; export { VersionHistoryHeader } from './VersionHistoryHeader'; export { VersionsHistoryButtons } from './VersionHistoryButtons'; diff --git a/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.tsx b/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.tsx index 30bd8138bd8..4a9b88d0708 100644 --- a/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.tsx +++ b/public/app/features/dashboard/components/DashboardSettings/VersionsSettings.tsx @@ -4,11 +4,10 @@ import * as React from 'react'; import { Spinner, HorizontalGroup } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { - RevisionsModel, VersionHistoryHeader, VersionsHistoryButtons, } from 'app/features/dashboard-scene/settings/version-history'; -import { getHistorySrv } from 'app/features/dashboard-scene/settings/version-history/HistorySrv'; +import { DecoratedRevisionModel, VersionModel, getHistorySrv } from 'app/features/dashboard-scene/settings/version-history/HistorySrv'; import { VersionHistoryComparison } from '../VersionHistory/VersionHistoryComparison'; import { VersionHistoryTable } from '../VersionHistory/VersionHistoryTable'; @@ -28,11 +27,6 @@ type State = { isNewLatest: boolean; }; -export type DecoratedRevisionModel = RevisionsModel & { - createdDateString: string; - ageString: string; -}; - export const VERSIONS_FETCH_LIMIT = 10; export class VersionsSettings extends PureComponent { @@ -100,7 +94,7 @@ export class VersionsSettings extends PureComponent { }); }; - decorateVersions = (versions: RevisionsModel[]) => + decorateVersions = (versions: VersionModel[]) => versions.map((version) => ({ ...version, createdDateString: this.props.dashboard.formatDate(version.created), @@ -115,7 +109,7 @@ export class VersionsSettings extends PureComponent { onCheck = (ev: React.FormEvent, versionId: number) => { this.setState({ versions: this.state.versions.map((version) => - version.id === versionId ? { ...version, checked: ev.currentTarget.checked } : version + version.version === versionId ? { ...version, checked: ev.currentTarget.checked } : version ), }); }; diff --git a/public/app/features/dashboard/components/VersionHistory/VersionHistoryComparison.tsx b/public/app/features/dashboard/components/VersionHistory/VersionHistoryComparison.tsx index 2f23cd32e17..f44443a53f4 100644 --- a/public/app/features/dashboard/components/VersionHistory/VersionHistoryComparison.tsx +++ b/public/app/features/dashboard/components/VersionHistory/VersionHistoryComparison.tsx @@ -4,10 +4,9 @@ import { GrafanaTheme2 } from '@grafana/data'; import { Button, ModalsController, CollapsableSection, useStyles2, Stack, Icon, Box } from '@grafana/ui'; import { DiffGroup } from 'app/features/dashboard-scene/settings/version-history/DiffGroup'; import { DiffViewer } from 'app/features/dashboard-scene/settings/version-history/DiffViewer'; +import { DecoratedRevisionModel } from 'app/features/dashboard-scene/settings/version-history/HistorySrv'; import { jsonDiff } from 'app/features/dashboard-scene/settings/version-history/utils'; -import { DecoratedRevisionModel } from '../DashboardSettings/VersionsSettings'; - import { RevertDashboardModal } from './RevertDashboardModal'; type DiffViewProps = { diff --git a/public/app/features/dashboard/components/VersionHistory/VersionHistoryTable.tsx b/public/app/features/dashboard/components/VersionHistory/VersionHistoryTable.tsx index 2cd8514992a..504db7cbb35 100644 --- a/public/app/features/dashboard/components/VersionHistory/VersionHistoryTable.tsx +++ b/public/app/features/dashboard/components/VersionHistory/VersionHistoryTable.tsx @@ -3,8 +3,7 @@ import * as React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Checkbox, Button, Tag, ModalsController, useStyles2 } from '@grafana/ui'; - -import { DecoratedRevisionModel } from '../DashboardSettings/VersionsSettings'; +import { DecoratedRevisionModel } from 'app/features/dashboard-scene/settings/version-history/HistorySrv'; import { RevertDashboardModal } from './RevertDashboardModal'; @@ -32,7 +31,7 @@ export const VersionHistoryTable = ({ versions, canCompare, onCheck }: VersionsT {versions.map((version, idx) => ( - + onCheck(ev, version.id)} + onChange={(ev) => onCheck(ev, version.version)} disabled={!version.checked && canCompare} />