This commit is contained in:
Torkel Ödegaard
2016-04-01 17:34:30 -07:00
parent f165ba6480
commit 38a10f8be4
14 changed files with 189 additions and 67 deletions
+2
View File
@@ -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)
-1
View File
@@ -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
View File
@@ -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"`
+35
View File
@@ -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")
}