mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Public Dashboards: fix updating public dashboard configuration (#51350)
* Public Dashboards: fix updating public dashboard configuration
This commit is contained in:
parent
0d9389e1f4
commit
9e80e44b45
@ -32,7 +32,7 @@ var (
|
||||
)
|
||||
|
||||
type PublicDashboard struct {
|
||||
Uid string `json:"uid" xorm:"uid"`
|
||||
Uid string `json:"uid" xorm:"pk uid"`
|
||||
DashboardUid string `json:"dashboardUid" xorm:"dashboard_uid"`
|
||||
OrgId int64 `json:"-" xorm:"org_id"` // Don't ever marshal orgId to Json
|
||||
TimeSettings *simplejson.Json `json:"timeSettings" xorm:"time_settings"`
|
||||
|
@ -124,7 +124,7 @@ func (d *DashboardStore) SavePublicDashboardConfig(ctx context.Context, cmd mode
|
||||
// updates existing public dashboard configuration
|
||||
func (d *DashboardStore) UpdatePublicDashboardConfig(ctx context.Context, cmd models.SavePublicDashboardConfigCommand) error {
|
||||
err := d.sqlStore.WithTransactionalDbSession(ctx, func(sess *sqlstore.DBSession) error {
|
||||
_, err := sess.UseBool("is_enabled").Update(&cmd.PublicDashboard)
|
||||
_, err := sess.ID(cmd.PublicDashboard.Uid).UseBool("is_enabled").Update(&cmd.PublicDashboard)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -190,19 +190,37 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
||||
var sqlStore *sqlstore.SQLStore
|
||||
var dashboardStore *DashboardStore
|
||||
var savedDashboard *models.Dashboard
|
||||
var anotherSavedDashboard *models.Dashboard
|
||||
|
||||
setup := func() {
|
||||
sqlStore = sqlstore.InitTestDB(t, sqlstore.InitTestDBOpt{FeatureFlags: []string{featuremgmt.FlagPublicDashboards}})
|
||||
dashboardStore = ProvideDashboardStore(sqlStore)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, true)
|
||||
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, true)
|
||||
}
|
||||
|
||||
t.Run("updates an existing dashboard", func(t *testing.T) {
|
||||
setup()
|
||||
|
||||
pdUid := "asdf1234"
|
||||
|
||||
// inserting two different public dashboards to test update works and only affect the desired pd by uid
|
||||
anotherPdUid := "anotherUid"
|
||||
_, err := dashboardStore.SavePublicDashboardConfig(context.Background(), models.SavePublicDashboardConfigCommand{
|
||||
DashboardUid: anotherSavedDashboard.Uid,
|
||||
OrgId: anotherSavedDashboard.OrgId,
|
||||
PublicDashboard: models.PublicDashboard{
|
||||
Uid: anotherPdUid,
|
||||
DashboardUid: anotherSavedDashboard.Uid,
|
||||
OrgId: anotherSavedDashboard.OrgId,
|
||||
IsEnabled: true,
|
||||
CreatedAt: DefaultTime,
|
||||
CreatedBy: 7,
|
||||
AccessToken: "fakeaccesstoken",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
pdUid := "asdf1234"
|
||||
_, err = dashboardStore.SavePublicDashboardConfig(context.Background(), models.SavePublicDashboardConfigCommand{
|
||||
DashboardUid: savedDashboard.Uid,
|
||||
OrgId: savedDashboard.OrgId,
|
||||
PublicDashboard: models.PublicDashboard{
|
||||
@ -234,6 +252,7 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// updated dashboard should have changed
|
||||
pdRetrieved, err := dashboardStore.GetPublicDashboardConfig(context.Background(), savedDashboard.OrgId, savedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -241,5 +260,12 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
||||
// make sure we're correctly updated IsEnabled because we have to call
|
||||
// UseBool with xorm
|
||||
assert.Equal(t, updatedPublicDashboard.IsEnabled, pdRetrieved.IsEnabled)
|
||||
|
||||
// not updated dashboard shouldn't have changed
|
||||
pdNotUpdatedRetrieved, err := dashboardStore.GetPublicDashboardConfig(context.Background(), anotherSavedDashboard.OrgId, anotherSavedDashboard.Uid)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotEqual(t, updatedPublicDashboard.UpdatedAt, pdNotUpdatedRetrieved.UpdatedAt)
|
||||
assert.NotEqual(t, updatedPublicDashboard.IsEnabled, pdNotUpdatedRetrieved.IsEnabled)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user