Commit af9b864b by Carl Bergquist

Merge pull request #3446 from utkarshcmu/new-columns

Displaying Last UpdatedBy as Metadata
parents 406ee43a d8b90721
......@@ -48,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{
......@@ -59,6 +73,7 @@ func GetDashboard(c *middleware.Context) {
CanEdit: canEditDashboard(c.OrgRole),
Created: dash.Created,
Updated: dash.Updated,
UpdatedBy: updater,
},
}
......@@ -88,6 +103,12 @@ func DeleteDashboard(c *middleware.Context) {
func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
cmd.OrgId = c.OrgId
if !c.IsSignedIn {
cmd.UpdatedBy = 0
} else {
cmd.UpdatedBy = c.UserId
}
dash := cmd.GetDashboardModel()
if dash.Id == 0 {
limitReached, err := middleware.QuotaReached(c, "dashboard")
......
......@@ -41,6 +41,7 @@ type DashboardMeta struct {
Expires time.Time `json:"expires"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
UpdatedBy string `json:"updatedBy"`
}
type DashboardFullWithMeta struct {
......
......@@ -33,6 +33,8 @@ type Dashboard struct {
Created time.Time
Updated time.Time
UpdatedBy int64
Title string
Data map[string]interface{}
}
......@@ -90,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
}
......@@ -113,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
}
......
......@@ -92,4 +92,9 @@ func addDashboardMigration(mg *Migrator) {
Sqlite("SELECT 0 WHERE 0;").
Postgres("SELECT 0;").
Mysql("ALTER TABLE dashboard MODIFY data MEDIUMTEXT;"))
// 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_Int, Nullable: true,
}))
}
......@@ -140,6 +140,17 @@
</ul>
<div class="clearfix"></div>
</div>
<div class="tight-form">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 120px">
Last updated by:
</li>
<li class="tight-form-item" style="width: 180px">
{{dashboardMeta.updatedBy}}
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment