Preferences: Use dashboard uid for the home dashboard (#106666)
This commit is contained in:
+23
-4
@@ -30,8 +30,8 @@ func (hs *HTTPServer) SetHomeDashboard(c *contextmodel.ReqContext) response.Resp
|
||||
cmd.UserID = userID
|
||||
cmd.OrgID = c.GetOrgID()
|
||||
|
||||
// the default value of HomeDashboardID is taken from input, when HomeDashboardID is set also,
|
||||
// UID is used in preference to identify dashboard
|
||||
// convert dashboard UID to ID in order to store internally if it exists in the query, otherwise take the id from query
|
||||
// nolint:staticcheck
|
||||
dashboardID := cmd.HomeDashboardID
|
||||
if cmd.HomeDashboardUID != nil {
|
||||
query := dashboards.GetDashboardQuery{UID: *cmd.HomeDashboardUID}
|
||||
@@ -44,8 +44,16 @@ func (hs *HTTPServer) SetHomeDashboard(c *contextmodel.ReqContext) response.Resp
|
||||
}
|
||||
dashboardID = queryResult.ID
|
||||
}
|
||||
} else if cmd.HomeDashboardID != 0 { // nolint:staticcheck
|
||||
// make sure uid is always set if id is set
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &dashboards.GetDashboardQuery{ID: cmd.HomeDashboardID, OrgID: cmd.OrgID}) // nolint:staticcheck
|
||||
if err != nil {
|
||||
return response.Error(http.StatusNotFound, "Dashboard not found", err)
|
||||
}
|
||||
cmd.HomeDashboardUID = &queryResult.UID
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
cmd.HomeDashboardID = dashboardID
|
||||
|
||||
if err := hs.preferenceService.Save(c.Req.Context(), &cmd); err != nil {
|
||||
@@ -76,7 +84,7 @@ func (hs *HTTPServer) GetUserPreferences(c *contextmodel.ReqContext) response.Re
|
||||
//
|
||||
// Update user preferences.
|
||||
//
|
||||
// Omitting a key (`theme`, `homeDashboardId`, `timezone`) will cause the current value to be replaced with the system default value.
|
||||
// Omitting a key (`theme`, `homeDashboardUID`, `timezone`) will cause the current value to be replaced with the system default value.
|
||||
//
|
||||
// Responses:
|
||||
// 200: okResponse
|
||||
@@ -127,6 +135,7 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
|
||||
}
|
||||
|
||||
// convert dashboard UID to ID in order to store internally if it exists in the query, otherwise take the id from query
|
||||
// nolint:staticcheck
|
||||
dashboardID := dtoCmd.HomeDashboardID
|
||||
if dtoCmd.HomeDashboardUID != nil {
|
||||
query := dashboards.GetDashboardQuery{UID: *dtoCmd.HomeDashboardUID, OrgID: orgID}
|
||||
@@ -141,7 +150,16 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
|
||||
}
|
||||
dashboardID = &queryResult.ID
|
||||
}
|
||||
} else if dtoCmd.HomeDashboardID != nil {
|
||||
// make sure uid is always set if id is set
|
||||
queryResult, err := hs.DashboardService.GetDashboard(ctx, &dashboards.GetDashboardQuery{ID: *dtoCmd.HomeDashboardID, OrgID: orgID}) // nolint:staticcheck
|
||||
if err != nil {
|
||||
return response.Error(http.StatusNotFound, "Dashboard not found", err)
|
||||
}
|
||||
dtoCmd.HomeDashboardUID = &queryResult.UID
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
dtoCmd.HomeDashboardID = dashboardID
|
||||
|
||||
patchCmd := pref.PatchPreferenceCommand{
|
||||
@@ -151,7 +169,8 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
|
||||
Theme: dtoCmd.Theme,
|
||||
Timezone: dtoCmd.Timezone,
|
||||
WeekStart: dtoCmd.WeekStart,
|
||||
HomeDashboardID: dtoCmd.HomeDashboardID,
|
||||
HomeDashboardID: dtoCmd.HomeDashboardID, // nolint:staticcheck
|
||||
HomeDashboardUID: dtoCmd.HomeDashboardUID,
|
||||
Language: dtoCmd.Language,
|
||||
Locale: dtoCmd.Locale,
|
||||
QueryHistory: dtoCmd.QueryHistory,
|
||||
|
||||
Reference in New Issue
Block a user