API: Add theme validation (#38432) (#38480)

* Add theme validation

* Fix lint for const

(cherry picked from commit ccab9611cb)

Co-authored-by: idafurjes <36131195+idafurjes@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)andidafurjes authored and GitHub committed 2021-08-24 10:30:49 +02:00
1 parent 79016c5d39
commit 70a0dc57ac
1 file changed
+9
+9
View File
@@ -7,6 +7,12 @@ import (
"github.com/grafana/grafana/pkg/models"
)
const (
defaultTheme string = ""
darkTheme string = "dark"
lightTheme string = "light"
)
// POST /api/preferences/set-home-dash
func SetHomeDashboard(c *models.ReqContext, cmd models.SavePreferencesCommand) response.Response {
cmd.UserId = c.UserId
@@ -46,6 +52,9 @@ func UpdateUserPreferences(c *models.ReqContext, dtoCmd dtos.UpdatePrefsCmd) res
}
func updatePreferencesFor(orgID, userID, teamId int64, dtoCmd *dtos.UpdatePrefsCmd) response.Response {
if dtoCmd.Theme != lightTheme && dtoCmd.Theme != darkTheme && dtoCmd.Theme != defaultTheme {
return response.Error(400, "Invalid theme", nil)
}
saveCmd := models.SavePreferencesCommand{
UserId: userID,
OrgId: orgID,