Snapshots: Add snapshot enable config (#61587)
* Add config to remove Snapshot functionality (frontend is hidden and validation in the backend) * Add test cases * Remove unused mock on the test * Moving Snapshot config from globar variables to settings.Cfg * Removing warnings on code
This commit is contained in:
@@ -15,13 +15,14 @@ import (
|
||||
type DashboardSnapshotStore struct {
|
||||
store db.DB
|
||||
log log.Logger
|
||||
cfg *setting.Cfg
|
||||
}
|
||||
|
||||
// DashboardStore implements the Store interface
|
||||
var _ dashboardsnapshots.Store = (*DashboardSnapshotStore)(nil)
|
||||
|
||||
func ProvideStore(db db.DB) *DashboardSnapshotStore {
|
||||
return &DashboardSnapshotStore{store: db, log: log.New("dashboardsnapshot.store")}
|
||||
func ProvideStore(db db.DB, cfg *setting.Cfg) *DashboardSnapshotStore {
|
||||
return &DashboardSnapshotStore{store: db, log: log.New("dashboardsnapshot.store"), cfg: cfg}
|
||||
}
|
||||
|
||||
// DeleteExpiredSnapshots removes snapshots with old expiry dates.
|
||||
@@ -29,7 +30,7 @@ func ProvideStore(db db.DB) *DashboardSnapshotStore {
|
||||
// Snapshot expiry is decided by the user when they share the snapshot.
|
||||
func (d *DashboardSnapshotStore) DeleteExpiredSnapshots(ctx context.Context, cmd *dashboardsnapshots.DeleteExpiredSnapshotsCommand) error {
|
||||
return d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
if !setting.SnapShotRemoveExpired {
|
||||
if !d.cfg.SnapShotRemoveExpired {
|
||||
d.log.Warn("[Deprecated] The snapshot_remove_expired setting is outdated. Please remove from your config.")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestIntegrationDashboardSnapshotDBAccess(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
sqlstore := db.InitTestDB(t)
|
||||
dashStore := ProvideStore(sqlstore)
|
||||
dashStore := ProvideStore(sqlstore, setting.NewCfg())
|
||||
|
||||
origSecret := setting.SecretKey
|
||||
setting.SecretKey = "dashboard_snapshot_testing"
|
||||
@@ -154,10 +154,10 @@ func TestIntegrationDeleteExpiredSnapshots(t *testing.T) {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
sqlstore := db.InitTestDB(t)
|
||||
dashStore := ProvideStore(sqlstore)
|
||||
dashStore := ProvideStore(sqlstore, setting.NewCfg())
|
||||
|
||||
t.Run("Testing dashboard snapshots clean up", func(t *testing.T) {
|
||||
setting.SnapShotRemoveExpired = true
|
||||
dashStore.cfg.SnapShotRemoveExpired = true
|
||||
|
||||
nonExpiredSnapshot := createTestSnapshot(t, dashStore, "key1", 48000)
|
||||
createTestSnapshot(t, dashStore, "key2", -1200)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
|
||||
func TestDashboardSnapshotsService(t *testing.T) {
|
||||
sqlStore := db.InitTestDB(t)
|
||||
dsStore := dashsnapdb.ProvideStore(sqlStore)
|
||||
dsStore := dashsnapdb.ProvideStore(sqlStore, setting.NewCfg())
|
||||
secretsService := secretsManager.SetupTestService(t, database.ProvideSecretsStore(sqlStore))
|
||||
s := ProvideService(dsStore, secretsService)
|
||||
|
||||
|
||||
@@ -376,13 +376,15 @@ func (s *ServiceImpl) buildDashboardNavLinks(c *models.ReqContext, hasEditPerm b
|
||||
})
|
||||
|
||||
if c.IsSignedIn {
|
||||
dashboardChildNavs = append(dashboardChildNavs, &navtree.NavLink{
|
||||
Text: "Snapshots",
|
||||
SubTitle: "Interactive, publically available, point-in-time representations of dashboards",
|
||||
Id: "dashboards/snapshots",
|
||||
Url: s.cfg.AppSubURL + "/dashboard/snapshots",
|
||||
Icon: "camera",
|
||||
})
|
||||
if s.cfg.SnapshotEnabled {
|
||||
dashboardChildNavs = append(dashboardChildNavs, &navtree.NavLink{
|
||||
Text: "Snapshots",
|
||||
SubTitle: "Interactive, publically available, point-in-time representations of dashboards",
|
||||
Id: "dashboards/snapshots",
|
||||
Url: s.cfg.AppSubURL + "/dashboard/snapshots",
|
||||
Icon: "camera",
|
||||
})
|
||||
}
|
||||
|
||||
dashboardChildNavs = append(dashboardChildNavs, &navtree.NavLink{
|
||||
Text: "Library panels",
|
||||
|
||||
Reference in New Issue
Block a user