progress
This commit is contained in:
@@ -100,6 +100,8 @@ func Register(r *macaron.Macaron) {
|
||||
r.Delete("/stars/dashboard/:id", wrap(UnstarDashboard))
|
||||
r.Put("/password", bind(m.ChangeUserPasswordCommand{}), wrap(ChangeUserPassword))
|
||||
r.Get("/quotas", wrap(GetUserQuotas))
|
||||
r.Get("/preferences", wrap(GetUserPreferences))
|
||||
r.Put("/preferences", bind(dtos.UpdateUserPrefsCmd{}), wrap(UpdateUserPreferences))
|
||||
})
|
||||
|
||||
// users (admin permission required)
|
||||
|
||||
@@ -159,7 +159,6 @@ func canEditDashboard(role m.RoleType) bool {
|
||||
}
|
||||
|
||||
func GetHomeDashboard(c *middleware.Context) {
|
||||
|
||||
// Checking if there is any preference set for home dashboard
|
||||
query := m.GetPreferencesQuery{UserId: c.UserId, OrgId: c.OrgId}
|
||||
|
||||
|
||||
+10
-1
@@ -1,6 +1,15 @@
|
||||
package dtos
|
||||
|
||||
type Preferences struct {
|
||||
type UserPrefs struct {
|
||||
Theme string `json:"theme"`
|
||||
ThemeDefault string `json:"themeDefault"`
|
||||
HomeDashboardId int64 `json:"homeDashboardId"`
|
||||
HomeDashboardIdDefault int64 `json:"homeDashboardIdDefault"`
|
||||
Timezone string `json:"timezone"`
|
||||
TimezoneDefault string `json:"timezoneDefault"`
|
||||
}
|
||||
|
||||
type UpdateUserPrefsCmd struct {
|
||||
Theme string `json:"theme"`
|
||||
HomeDashboardId int64 `json:"homeDashboardId"`
|
||||
Timezone string `json:"timezone"`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
@@ -18,3 +19,37 @@ func SetHomeDashboard(c *middleware.Context, cmd m.SavePreferencesCommand) Respo
|
||||
|
||||
return ApiSuccess("Home dashboard set")
|
||||
}
|
||||
|
||||
// GET /api/user/preferences
|
||||
func GetUserPreferences(c *middleware.Context) Response {
|
||||
userPrefs := m.GetPreferencesQuery{UserId: c.UserId, OrgId: c.OrgId}
|
||||
|
||||
if err := bus.Dispatch(&userPrefs); err != nil {
|
||||
c.JsonApiErr(500, "Failed to get preferences", err)
|
||||
}
|
||||
|
||||
dto := dtos.UserPrefs{
|
||||
Theme: userPrefs.Result.Theme,
|
||||
HomeDashboardId: userPrefs.Result.HomeDashboardId,
|
||||
Timezone: userPrefs.Result.Timezone,
|
||||
}
|
||||
|
||||
return Json(200, &dto)
|
||||
}
|
||||
|
||||
// PUT /api/user/preferences
|
||||
func UpdateUserPreferences(c *middleware.Context, dtoCmd dtos.UpdateUserPrefsCmd) Response {
|
||||
saveCmd := m.SavePreferencesCommand{
|
||||
UserId: c.UserId,
|
||||
OrgId: c.OrgId,
|
||||
Theme: dtoCmd.Theme,
|
||||
Timezone: dtoCmd.Timezone,
|
||||
HomeDashboardId: dtoCmd.HomeDashboardId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&saveCmd); err != nil {
|
||||
c.JsonApiErr(500, "Failed to save preferences", err)
|
||||
}
|
||||
|
||||
return ApiSuccess("User preferences updated")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user