PublicDashboards: add time picker enabled column (#59324)

This commit is contained in:
Ezequiel Victorero 2022-12-01 11:37:08 -03:00 committed by GitHub
parent 3a9d4cc688
commit c6cf774ac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 47 deletions

View File

@ -233,9 +233,10 @@ func (d *PublicDashboardStoreImpl) Update(ctx context.Context, cmd SavePublicDas
return err
}
sqlResult, err := sess.Exec("UPDATE dashboard_public SET is_enabled = ?, annotations_enabled = ?, time_settings = ?, updated_by = ?, updated_at = ? WHERE uid = ?",
sqlResult, err := sess.Exec("UPDATE dashboard_public SET is_enabled = ?, annotations_enabled = ?, time_selection_enabled = ?, time_settings = ?, updated_by = ?, updated_at = ? WHERE uid = ?",
cmd.PublicDashboard.IsEnabled,
cmd.PublicDashboard.AnnotationsEnabled,
cmd.PublicDashboard.TimeSelectionEnabled,
string(timeSettingsJSON),
cmd.PublicDashboard.UpdatedBy,
cmd.PublicDashboard.UpdatedAt.UTC().Format("2006-01-02 15:04:05"),

View File

@ -400,15 +400,16 @@ func TestIntegrationCreatePublicDashboard(t *testing.T) {
setup()
cmd := SavePublicDashboardCommand{
PublicDashboard: PublicDashboard{
IsEnabled: true,
AnnotationsEnabled: true,
Uid: "pubdash-uid",
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
TimeSettings: DefaultTimeSettings,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "NOTAREALUUID",
IsEnabled: true,
AnnotationsEnabled: true,
TimeSelectionEnabled: true,
Uid: "pubdash-uid",
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
TimeSettings: DefaultTimeSettings,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "NOTAREALUUID",
},
}
affectedRows, err := publicdashboardStore.Create(context.Background(), cmd)
@ -418,6 +419,9 @@ func TestIntegrationCreatePublicDashboard(t *testing.T) {
pubdash, err := publicdashboardStore.FindByDashboardUid(context.Background(), savedDashboard.OrgId, savedDashboard.Uid)
require.NoError(t, err)
assert.Equal(t, pubdash.AccessToken, "NOTAREALUUID")
assert.True(t, pubdash.IsEnabled)
assert.True(t, pubdash.AnnotationsEnabled)
assert.True(t, pubdash.TimeSelectionEnabled)
// verify we didn't update all dashboards
pubdash2, err := publicdashboardStore.FindByDashboardUid(context.Background(), savedDashboard2.OrgId, savedDashboard2.Uid)
@ -474,14 +478,15 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
pdUid := "asdf1234"
cmd := SavePublicDashboardCommand{
PublicDashboard: PublicDashboard{
Uid: pdUid,
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
IsEnabled: false,
AnnotationsEnabled: true,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "NOTAREALUUID",
Uid: pdUid,
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
IsEnabled: false,
AnnotationsEnabled: true,
TimeSelectionEnabled: true,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "NOTAREALUUID",
},
}
affectedRows, err := publicdashboardStore.Create(context.Background(), cmd)
@ -492,14 +497,15 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
anotherPdUid := "anotherUid"
cmd = SavePublicDashboardCommand{
PublicDashboard: PublicDashboard{
Uid: anotherPdUid,
DashboardUid: anotherSavedDashboard.Uid,
OrgId: anotherSavedDashboard.OrgId,
IsEnabled: true,
AnnotationsEnabled: false,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "fakeaccesstoken",
Uid: anotherPdUid,
DashboardUid: anotherSavedDashboard.Uid,
OrgId: anotherSavedDashboard.OrgId,
IsEnabled: true,
AnnotationsEnabled: false,
TimeSelectionEnabled: false,
CreatedAt: DefaultTime,
CreatedBy: 7,
AccessToken: "fakeaccesstoken",
},
}
@ -508,14 +514,15 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
assert.EqualValues(t, affectedRows, 1)
updatedPublicDashboard := PublicDashboard{
Uid: pdUid,
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
IsEnabled: false,
AnnotationsEnabled: true,
TimeSettings: &TimeSettings{From: "now-8", To: "now"},
UpdatedAt: time.Now().UTC().Round(time.Second),
UpdatedBy: 8,
Uid: pdUid,
DashboardUid: savedDashboard.Uid,
OrgId: savedDashboard.OrgId,
IsEnabled: false,
AnnotationsEnabled: true,
TimeSelectionEnabled: true,
TimeSettings: &TimeSettings{From: "now-8", To: "now"},
UpdatedAt: time.Now().UTC().Round(time.Second),
UpdatedBy: 8,
}
// update initial record
@ -533,6 +540,7 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
// UseBool with xorm
assert.Equal(t, updatedPublicDashboard.IsEnabled, pdRetrieved.IsEnabled)
assert.Equal(t, updatedPublicDashboard.AnnotationsEnabled, pdRetrieved.AnnotationsEnabled)
assert.Equal(t, updatedPublicDashboard.TimeSelectionEnabled, pdRetrieved.TimeSelectionEnabled)
// not updated dashboard shouldn't have changed
pdNotUpdatedRetrieved, err := publicdashboardStore.FindByDashboardUid(context.Background(), anotherSavedDashboard.OrgId, anotherSavedDashboard.Uid)

View File

@ -31,13 +31,14 @@ const QueryFailure = "failure"
var QueryResultStatuses = []string{QuerySuccess, QueryFailure}
type PublicDashboard struct {
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 *TimeSettings `json:"timeSettings" xorm:"time_settings"`
IsEnabled bool `json:"isEnabled" xorm:"is_enabled"`
AccessToken string `json:"accessToken" xorm:"access_token"`
AnnotationsEnabled bool `json:"annotationsEnabled" xorm:"annotations_enabled"`
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 *TimeSettings `json:"timeSettings" xorm:"time_settings"`
IsEnabled bool `json:"isEnabled" xorm:"is_enabled"`
AccessToken string `json:"accessToken" xorm:"access_token"`
AnnotationsEnabled bool `json:"annotationsEnabled" xorm:"annotations_enabled"`
TimeSelectionEnabled bool `json:"timeSelectionEnabled" xorm:"time_selection_enabled"`
CreatedBy int64 `json:"createdBy" xorm:"created_by"`
UpdatedBy int64 `json:"updatedBy" xorm:"updated_by"`

View File

@ -218,12 +218,13 @@ func (pd *PublicDashboardServiceImpl) Update(ctx context.Context, u *user.Signed
// set values to update
cmd := SavePublicDashboardCommand{
PublicDashboard: PublicDashboard{
Uid: existingPubdash.Uid,
IsEnabled: dto.PublicDashboard.IsEnabled,
AnnotationsEnabled: dto.PublicDashboard.AnnotationsEnabled,
TimeSettings: dto.PublicDashboard.TimeSettings,
UpdatedBy: dto.UserId,
UpdatedAt: time.Now(),
Uid: existingPubdash.Uid,
IsEnabled: dto.PublicDashboard.IsEnabled,
AnnotationsEnabled: dto.PublicDashboard.AnnotationsEnabled,
TimeSelectionEnabled: dto.PublicDashboard.TimeSelectionEnabled,
TimeSettings: dto.PublicDashboard.TimeSettings,
UpdatedBy: dto.UserId,
UpdatedAt: time.Now(),
},
}

View File

@ -75,6 +75,13 @@ func addPublicDashboardMigration(mg *Migrator) {
Default: "0",
}))
mg.AddMigration("add time_selection_enabled column", NewAddColumnMigration(dashboardPublicCfgV2, &Column{
Name: "time_selection_enabled",
Type: DB_Bool,
Nullable: false,
Default: "0",
}))
mg.AddMigration("delete orphaned public dashboards", NewRawSQLMigration(
"DELETE FROM dashboard_public WHERE dashboard_uid NOT IN (SELECT uid FROM dashboard)"))
}