mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Api stores dashboard creator
This commit is contained in:
@@ -49,17 +49,13 @@ func GetDashboard(c *middleware.Context) {
|
|||||||
|
|
||||||
dash := query.Result
|
dash := query.Result
|
||||||
|
|
||||||
// Finding the last updater of the dashboard
|
// Finding the last creator and updater of the dashboard
|
||||||
updater := "Anonymous"
|
updater, creator := "Anonymous", "Anonymous"
|
||||||
if dash.UpdatedBy != 0 {
|
if dash.UpdatedBy > 0 {
|
||||||
userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy}
|
updater = getUserLogin(dash.UpdatedBy)
|
||||||
userErr := bus.Dispatch(&userQuery)
|
|
||||||
if userErr != nil {
|
|
||||||
updater = "Unknown"
|
|
||||||
} else {
|
|
||||||
user := userQuery.Result
|
|
||||||
updater = user.Login
|
|
||||||
}
|
}
|
||||||
|
if dash.CreatedBy > 0 {
|
||||||
|
creator = getUserLogin(dash.CreatedBy)
|
||||||
}
|
}
|
||||||
|
|
||||||
dto := dtos.DashboardFullWithMeta{
|
dto := dtos.DashboardFullWithMeta{
|
||||||
@@ -74,12 +70,24 @@ func GetDashboard(c *middleware.Context) {
|
|||||||
Created: dash.Created,
|
Created: dash.Created,
|
||||||
Updated: dash.Updated,
|
Updated: dash.Updated,
|
||||||
UpdatedBy: updater,
|
UpdatedBy: updater,
|
||||||
|
CreatedBy: creator,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(200, dto)
|
c.JSON(200, dto)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserLogin(userId int64) string {
|
||||||
|
query := m.GetUserByIdQuery{Id: userId}
|
||||||
|
err := bus.Dispatch(&query)
|
||||||
|
if err != nil {
|
||||||
|
return "Anonymous"
|
||||||
|
} else {
|
||||||
|
user := query.Result
|
||||||
|
return user.Login
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func DeleteDashboard(c *middleware.Context) {
|
func DeleteDashboard(c *middleware.Context) {
|
||||||
slug := c.Params(":slug")
|
slug := c.Params(":slug")
|
||||||
|
|
||||||
@@ -104,9 +112,9 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
|
|||||||
cmd.OrgId = c.OrgId
|
cmd.OrgId = c.OrgId
|
||||||
|
|
||||||
if !c.IsSignedIn {
|
if !c.IsSignedIn {
|
||||||
cmd.UpdatedBy = 0
|
cmd.UserId = -1
|
||||||
} else {
|
} else {
|
||||||
cmd.UpdatedBy = c.UserId
|
cmd.UserId = c.UserId
|
||||||
}
|
}
|
||||||
|
|
||||||
dash := cmd.GetDashboardModel()
|
dash := cmd.GetDashboardModel()
|
||||||
|
|||||||
Reference in New Issue
Block a user