Skip to content

Commit d8b9072

Browse files
committed
Able to display login Id of the user in Last Updated By
1 parent cb5c1bd commit d8b9072

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/api/dashboard.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"os"
66
"path"
7-
"strconv"
87
"strings"
98

109
"github.com/grafana/grafana/pkg/api/dtos"
@@ -49,6 +48,20 @@ func GetDashboard(c *middleware.Context) {
4948
}
5049

5150
dash := query.Result
51+
52+
// Finding the last updater of the dashboard
53+
updater := "Anonymous"
54+
if dash.UpdatedBy != 0 {
55+
userQuery := m.GetUserByIdQuery{Id: dash.UpdatedBy}
56+
userErr := bus.Dispatch(&userQuery)
57+
if userErr != nil {
58+
updater = "Unknown"
59+
} else {
60+
user := userQuery.Result
61+
updater = user.Login
62+
}
63+
}
64+
5265
dto := dtos.DashboardFullWithMeta{
5366
Dashboard: dash.Data,
5467
Meta: dtos.DashboardMeta{
@@ -60,7 +73,7 @@ func GetDashboard(c *middleware.Context) {
6073
CanEdit: canEditDashboard(c.OrgRole),
6174
Created: dash.Created,
6275
Updated: dash.Updated,
63-
UpdatedBy: strconv.FormatInt(dash.UpdatedBy, 10),
76+
UpdatedBy: updater,
6477
},
6578
}
6679

@@ -89,7 +102,12 @@ func DeleteDashboard(c *middleware.Context) {
89102

90103
func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
91104
cmd.OrgId = c.OrgId
92-
cmd.UpdatedBy = c.UserId
105+
106+
if !c.IsSignedIn {
107+
cmd.UpdatedBy = 0
108+
} else {
109+
cmd.UpdatedBy = c.UserId
110+
}
93111

94112
dash := cmd.GetDashboardModel()
95113
if dash.Id == 0 {

0 commit comments

Comments
 (0)