Merge pull request #3446 from utkarshcmu/new-columns

Displaying Last UpdatedBy as Metadata
This commit is contained in:
Carl Bergquist
2015-12-20 15:11:20 -05:00
5 changed files with 42 additions and 0 deletions

View File

@@ -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")

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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,
}))
}