diff --git a/pkg/services/dashboardversion/dashverimpl/sqlx_store.go b/pkg/services/dashboardversion/dashverimpl/sqlx_store.go index b8a564bbc23..e4a6eab8893 100644 --- a/pkg/services/dashboardversion/dashverimpl/sqlx_store.go +++ b/pkg/services/dashboardversion/dashverimpl/sqlx_store.go @@ -67,9 +67,9 @@ func (ss *sqlxStore) List(ctx context.Context, query *dashver.ListDashboardVersi dashboard_version.restored_from, dashboard_version.version, dashboard_version.created, + dashboard_version.created_by, dashboard_version.message FROM dashboard_version - LEFT JOIN "user" ON "user".id = dashboard_version.created_by LEFT JOIN dashboard ON dashboard.id = dashboard_version.dashboard_id WHERE dashboard_version.dashboard_id=? AND dashboard.org_id=? ORDER BY dashboard_version.version DESC diff --git a/pkg/services/dashboardversion/dashverimpl/store_test.go b/pkg/services/dashboardversion/dashverimpl/store_test.go index 8ee0fcb6b41..d45d5a9f6e3 100644 --- a/pkg/services/dashboardversion/dashverimpl/store_test.go +++ b/pkg/services/dashboardversion/dashverimpl/store_test.go @@ -5,15 +5,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/dashboards" dashver "github.com/grafana/grafana/pkg/services/dashboardversion" "github.com/grafana/grafana/pkg/util" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) type getStore func(db.DB) store @@ -37,6 +37,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) { require.Nil(t, err) assert.Equal(t, query.DashboardID, savedDash.Id) assert.Equal(t, query.Version, savedDash.Version) + assert.Equal(t, createdById, res.CreatedBy) dashCmd := &models.Dashboard{ Id: res.ID, @@ -48,6 +49,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) { assert.EqualValues(t, dashCmd.Data.Get("uid"), res.Data.Get("uid")) assert.EqualValues(t, dashCmd.Data.Get("orgId"), res.Data.Get("orgId")) + assert.Equal(t, createdById, res.CreatedBy) }) t.Run("Attempt to get a version that doesn't exist", func(t *testing.T) { @@ -128,6 +130,10 @@ func getDashboard(t *testing.T, sqlStore db.DB, dashboard *models.Dashboard) err }) } +var ( + createdById = int64(3) +) + func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64, folderId int64, isFolder bool, tags ...interface{}) *models.Dashboard { t.Helper() @@ -140,6 +146,7 @@ func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64 "title": title, "tags": tags, }), + UserId: createdById, } var dash *models.Dashboard diff --git a/pkg/services/dashboardversion/dashverimpl/xorm_store.go b/pkg/services/dashboardversion/dashverimpl/xorm_store.go index ac9b3e080f1..36109c9fa4b 100644 --- a/pkg/services/dashboardversion/dashverimpl/xorm_store.go +++ b/pkg/services/dashboardversion/dashverimpl/xorm_store.go @@ -81,11 +81,9 @@ func (ss *sqlStore) List(ctx context.Context, query *dashver.ListDashboardVersio dashboard_version.restored_from, dashboard_version.version, dashboard_version.created, - dashboard_version.created_by as created_by_id, + dashboard_version.created_by, dashboard_version.message, - dashboard_version.data,`+ - ss.dialect.Quote("user")+`.login as created_by`). - Join("LEFT", ss.dialect.Quote("user"), `dashboard_version.created_by = `+ss.dialect.Quote("user")+`.id`). + dashboard_version.data`). Join("LEFT", "dashboard", `dashboard.id = dashboard_version.dashboard_id`). Where("dashboard_version.dashboard_id=? AND dashboard.org_id=?", query.DashboardID, query.OrgID). OrderBy("dashboard_version.version DESC").