From 3d90340446feaf8065b0d44b002021b6d074bd9a Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 6 Dec 2015 23:51:43 -0800 Subject: [PATCH 1/9] Added new columns to dashboard table --- pkg/services/sqlstore/migrations/dashboard_mig.go | 10 ++++++++++ pkg/services/sqlstore/migrator/migrations.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 5d440d85ebc..66ad02ba27d 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -92,4 +92,14 @@ func addDashboardMigration(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) + + // add column to store creator of a dashboard + mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) + + // add column to store updater of a dashboard + mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) } diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index a65c7ec7e81..26387fcb7db 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -64,6 +64,10 @@ type AddColumnMigration struct { column *Column } +func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { + return &AddColumnMigration{tableName: table.Name, column: col} +} + func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { m.tableName = tableName return m From 42d12052606ef788a7abe8061aa54aade1c40761 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Sun, 6 Dec 2015 23:59:58 -0800 Subject: [PATCH 2/9] Fixed gofmt checks --- .../sqlstore/migrations/dashboard_mig.go | 16 ++++++++-------- pkg/services/sqlstore/migrator/migrations.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 66ad02ba27d..331dbf0ef2f 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -93,13 +93,13 @@ func addDashboardMigration(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) - // add column to store creator of a dashboard - mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "created_by", Type: DB_BigInt, Nullable: true, - })) + // add column to store creator of a dashboard + mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) - // add column to store updater of a dashboard - mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "updated_by", Type: DB_BigInt, Nullable: true, - })) + // add column to store updater of a dashboard + mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) } diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index 26387fcb7db..7d97abb6bb9 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -65,7 +65,7 @@ type AddColumnMigration struct { } func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { - return &AddColumnMigration{tableName: table.Name, column: col} + return &AddColumnMigration{tableName: table.Name, column: col} } func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { From 79d0f47ee70ac62c2d7a62a7d84c5277d3ec5b84 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Mon, 7 Dec 2015 04:24:29 -0800 Subject: [PATCH 3/9] Added columns in dashboard_snapshot --- .../sqlstore/migrations/dashboard_snapshot_mig.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index b08cc451e55..26e7cea0a6e 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -54,4 +54,15 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) + + // add column to store creator of a dashboard snapshot + mg.AddMigration("Add column created_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ + Name: "created_by", Type: DB_BigInt, Nullable: true, + })) + + // add column to store updater of a dashboard snapshot + mg.AddMigration("Add column updated_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ + Name: "updated_by", Type: DB_BigInt, Nullable: true, + })) + } From 78fe58833065c457440df16860feb2adaba0416e Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Wed, 16 Dec 2015 02:46:20 -0800 Subject: [PATCH 4/9] Removed NewAddColumnMigration via 3473 --- pkg/services/sqlstore/migrator/migrations.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/services/sqlstore/migrator/migrations.go b/pkg/services/sqlstore/migrator/migrations.go index 7d97abb6bb9..a65c7ec7e81 100644 --- a/pkg/services/sqlstore/migrator/migrations.go +++ b/pkg/services/sqlstore/migrator/migrations.go @@ -64,10 +64,6 @@ type AddColumnMigration struct { column *Column } -func NewAddColumnMigration(table Table, col *Column) *AddColumnMigration { - return &AddColumnMigration{tableName: table.Name, column: col} -} - func (m *AddColumnMigration) Table(tableName string) *AddColumnMigration { m.tableName = tableName return m From e0ffcda32ecc31a61fb88f998f6274d84aa61ac1 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 00:20:23 -0800 Subject: [PATCH 5/9] Added UI , DB settings --- pkg/api/dashboard.go | 2 + pkg/api/dtos/models.go | 3 ++ pkg/models/dashboards.go | 8 +++ .../sqlstore/migrations/dashboard_mig.go | 8 +-- .../features/dashboard/partials/settings.html | 54 ++++++++++++++++++- 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 6490a118861..77309a24560 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -59,6 +59,8 @@ func GetDashboard(c *middleware.Context) { CanEdit: canEditDashboard(c.OrgRole), Created: dash.Created, Updated: dash.Updated, + CreatedBy: dash.CreatedBy, + UpdatedBy: dash.UpdatedBy, }, } diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index 7af4c84f56d..a63a45d6695 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -41,6 +41,8 @@ type DashboardMeta struct { Expires time.Time `json:"expires"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` + CreatedBy string `json:"createdBy"` + UpdatedBy string `json:"updatedBy"` } type DashboardFullWithMeta struct { @@ -61,6 +63,7 @@ type DataSource struct { BasicAuth bool `json:"basicAuth"` BasicAuthUser string `json:"basicAuthUser"` BasicAuthPassword string `json:"basicAuthPassword"` + WithCredentials bool `json:"withCredentials"` IsDefault bool `json:"isDefault"` JsonData map[string]interface{} `json:"jsonData"` } diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 5b926c3e314..9c2350bb7dd 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -33,6 +33,9 @@ type Dashboard struct { Created time.Time Updated time.Time + CreatedBy string + UpdatedBy string + Title string Data map[string]interface{} } @@ -45,6 +48,8 @@ func NewDashboard(title string) *Dashboard { dash.Title = title dash.Created = time.Now() dash.Updated = time.Now() + // TODO:dash.CreatedBy = "Creator" + // TODO:dash.UpdatedBy = "Creator" dash.UpdateSlug() return dash } @@ -76,11 +81,14 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { if dash.Data["version"] != nil { dash.Version = int(dash.Data["version"].(float64)) dash.Updated = time.Now() + // TODO:dash.UpdatedBy = "Updater" } } else { dash.Data["version"] = 0 dash.Created = time.Now() dash.Updated = time.Now() + // TODO:dash.CreatedBy = "Creator" + // TODO:dash.UpdatedBy = "Creator" } return dash diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 331dbf0ef2f..4994cb0a234 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -94,12 +94,12 @@ func addDashboardMigration(mg *Migrator) { Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) // add column to store creator of a dashboard - mg.AddMigration("Add column created_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "created_by", Type: DB_BigInt, Nullable: true, + mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ + Name: "created_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", })) // add column to store updater of a dashboard - mg.AddMigration("Add column updated_by", NewAddColumnMigration(dashboardV2, &Column{ - Name: "updated_by", Type: DB_BigInt, Nullable: true, + mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ + Name: "updated_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", })) } diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 541ef45e9ab..36223f152a0 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -5,7 +5,7 @@
-
+
@@ -114,6 +114,58 @@
+
+
+
+
Info
+
+
    +
  • + Last updated at: +
  • +
  • + {{formatDate(dashboardMeta.updated)}} +
  • +
+
+
+
+
    +
  • + Last updated by: +
  • +
  • + {{dashboardMeta.updatedBy}} +
  • +
+
+
+
+
    +
  • + Created at: +
  • +
  • + {{formatDate(dashboardMeta.created)}} +
  • +
+
+
+
+
    +
  • + Created by: +
  • +
  • + {{dashboardMeta.createdBy}} +
  • +
+
+
+
+
+
+
From 22fd2aed02297e370ee6ad57ed32dea45b661a77 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 00:30:44 -0800 Subject: [PATCH 6/9] Removed columns from snapshot table --- .../sqlstore/migrations/dashboard_snapshot_mig.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index 26e7cea0a6e..0173617bf48 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -55,14 +55,4 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) - // add column to store creator of a dashboard snapshot - mg.AddMigration("Add column created_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ - Name: "created_by", Type: DB_BigInt, Nullable: true, - })) - - // add column to store updater of a dashboard snapshot - mg.AddMigration("Add column updated_by in dashboard_snapshot", NewAddColumnMigration(snapshotV5, &Column{ - Name: "updated_by", Type: DB_BigInt, Nullable: true, - })) - } From af371249f9056546807b36dda5d3a0785fe6f1e4 Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 01:52:05 -0800 Subject: [PATCH 7/9] Successfully displayed userdId in UI --- pkg/api/dashboard.go | 5 +++-- pkg/models/dashboards.go | 10 +++------ .../sqlstore/migrations/dashboard_mig.go | 7 +------ .../migrations/dashboard_snapshot_mig.go | 1 - .../features/dashboard/partials/settings.html | 21 +++++-------------- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index 77309a24560..d95f1c71f3e 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path" + "strconv" "strings" "github.com/grafana/grafana/pkg/api/dtos" @@ -59,8 +60,7 @@ func GetDashboard(c *middleware.Context) { CanEdit: canEditDashboard(c.OrgRole), Created: dash.Created, Updated: dash.Updated, - CreatedBy: dash.CreatedBy, - UpdatedBy: dash.UpdatedBy, + UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10), }, } @@ -89,6 +89,7 @@ func DeleteDashboard(c *middleware.Context) { func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) { cmd.OrgId = c.OrgId + cmd.UpdatedBy = c.UserId dash := cmd.GetDashboardModel() if dash.Id == 0 { diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 9c2350bb7dd..32922213a6a 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -33,8 +33,7 @@ type Dashboard struct { Created time.Time Updated time.Time - CreatedBy string - UpdatedBy string + UpdatedBy int64 Title string Data map[string]interface{} @@ -48,8 +47,6 @@ func NewDashboard(title string) *Dashboard { dash.Title = title dash.Created = time.Now() dash.Updated = time.Now() - // TODO:dash.CreatedBy = "Creator" - // TODO:dash.UpdatedBy = "Creator" dash.UpdateSlug() return dash } @@ -81,14 +78,11 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { if dash.Data["version"] != nil { dash.Version = int(dash.Data["version"].(float64)) dash.Updated = time.Now() - // TODO:dash.UpdatedBy = "Updater" } } else { dash.Data["version"] = 0 dash.Created = time.Now() dash.Updated = time.Now() - // TODO:dash.CreatedBy = "Creator" - // TODO:dash.UpdatedBy = "Creator" } return dash @@ -98,6 +92,7 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard { dash := NewDashboardFromJson(cmd.Dashboard) dash.OrgId = cmd.OrgId + dash.UpdatedBy = cmd.UpdatedBy dash.UpdateSlug() return dash } @@ -121,6 +116,7 @@ type SaveDashboardCommand struct { Dashboard map[string]interface{} `json:"dashboard" binding:"Required"` Overwrite bool `json:"overwrite"` OrgId int64 `json:"-"` + UpdatedBy int64 `json:"-"` Result *Dashboard } diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 4994cb0a234..b94f1a7d6ac 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -93,13 +93,8 @@ func addDashboardMigration(mg *Migrator) { Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;")) - // add column to store creator of a dashboard - mg.AddMigration("Add column created_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ - Name: "created_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", - })) - // add column to store updater of a dashboard mg.AddMigration("Add column updated_by in dashboard - v2", NewAddColumnMigration(dashboardV2, &Column{ - Name: "updated_by", Type: DB_NVarchar, Length: 255, Nullable: false, Default: "Anonymous", + Name: "updated_by", Type: DB_Int, Nullable: true, })) } diff --git a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go index 0173617bf48..b08cc451e55 100644 --- a/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_snapshot_mig.go @@ -54,5 +54,4 @@ func addDashboardSnapshotMigrations(mg *Migrator) { Sqlite("SELECT 0 WHERE 0;"). Postgres("SELECT 0;"). Mysql("ALTER TABLE dashboard_snapshot MODIFY dashboard MEDIUMTEXT;")) - } diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 36223f152a0..d9a71655667 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -117,7 +117,7 @@
-
Info
+
Dashboard info
  • @@ -129,17 +129,6 @@
-
-
    -
  • - Last updated by: -
  • -
  • - {{dashboardMeta.updatedBy}} -
  • -
-
-
  • @@ -151,14 +140,14 @@
-
+
  • - Created by: + Last updated by:
  • - {{dashboardMeta.createdBy}} -
  • + {{dashboardMeta.updatedBy}} +
From cb5c1bd24da97a2952a3e17debcf2b41554c291a Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 02:30:20 -0800 Subject: [PATCH 8/9] Removed created_by and fixed gofmt --- pkg/api/dtos/models.go | 1 - pkg/models/dashboards.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/api/dtos/models.go b/pkg/api/dtos/models.go index a63a45d6695..a7ff9353fa9 100644 --- a/pkg/api/dtos/models.go +++ b/pkg/api/dtos/models.go @@ -41,7 +41,6 @@ type DashboardMeta struct { Expires time.Time `json:"expires"` Created time.Time `json:"created"` Updated time.Time `json:"updated"` - CreatedBy string `json:"createdBy"` UpdatedBy string `json:"updatedBy"` } diff --git a/pkg/models/dashboards.go b/pkg/models/dashboards.go index 32922213a6a..ddf5dd244f5 100644 --- a/pkg/models/dashboards.go +++ b/pkg/models/dashboards.go @@ -92,7 +92,7 @@ func NewDashboardFromJson(data map[string]interface{}) *Dashboard { func (cmd *SaveDashboardCommand) GetDashboardModel() *Dashboard { dash := NewDashboardFromJson(cmd.Dashboard) dash.OrgId = cmd.OrgId - dash.UpdatedBy = cmd.UpdatedBy + dash.UpdatedBy = cmd.UpdatedBy dash.UpdateSlug() return dash } @@ -116,7 +116,7 @@ type SaveDashboardCommand struct { Dashboard map[string]interface{} `json:"dashboard" binding:"Required"` Overwrite bool `json:"overwrite"` OrgId int64 `json:"-"` - UpdatedBy int64 `json:"-"` + UpdatedBy int64 `json:"-"` Result *Dashboard } From d8b90721b35de087b7c4e9d71193f3e3c0b6d78e Mon Sep 17 00:00:00 2001 From: utkarshcmu Date: Fri, 18 Dec 2015 03:38:49 -0800 Subject: [PATCH 9/9] Able to display login Id of the user in Last Updated By --- pkg/api/dashboard.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/api/dashboard.go b/pkg/api/dashboard.go index d95f1c71f3e..79485fa8cca 100644 --- a/pkg/api/dashboard.go +++ b/pkg/api/dashboard.go @@ -4,7 +4,6 @@ import ( "encoding/json" "os" "path" - "strconv" "strings" "github.com/grafana/grafana/pkg/api/dtos" @@ -49,6 +48,20 @@ func GetDashboard(c *middleware.Context) { } dash := query.Result + + // Finding the last updater of the dashboard + updater := "Anonymous" + if dash.UpdatedBy != 0 { + userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy} + userErr := bus.Dispatch(&userQuery) + if userErr != nil { + updater = "Unknown" + } else { + user := userQuery.Result + updater = user.Login + } + } + dto := dtos.DashboardFullWithMeta{ Dashboard: dash.Data, Meta: dtos.DashboardMeta{ @@ -60,7 +73,7 @@ func GetDashboard(c *middleware.Context) { CanEdit: canEditDashboard(c.OrgRole), Created: dash.Created, Updated: dash.Updated, - UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10), + UpdatedBy: updater, }, } @@ -89,7 +102,12 @@ func DeleteDashboard(c *middleware.Context) { func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) { cmd.OrgId = c.OrgId - cmd.UpdatedBy = c.UserId + + if !c.IsSignedIn { + cmd.UpdatedBy = 0 + } else { + cmd.UpdatedBy = c.UserId + } dash := cmd.GetDashboardModel() if dash.Id == 0 {