models.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "regexp"
  6. "strings"
  7. "github.com/grafana/grafana/pkg/components/simplejson"
  8. m "github.com/grafana/grafana/pkg/models"
  9. "github.com/grafana/grafana/pkg/setting"
  10. )
  11. type AnyId struct {
  12. Id int64 `json:"id"`
  13. }
  14. type LoginCommand struct {
  15. User string `json:"user" binding:"Required"`
  16. Password string `json:"password" binding:"Required"`
  17. Remember bool `json:"remember"`
  18. }
  19. type CurrentUser struct {
  20. IsSignedIn bool `json:"isSignedIn"`
  21. Id int64 `json:"id"`
  22. Login string `json:"login"`
  23. Email string `json:"email"`
  24. Name string `json:"name"`
  25. LightTheme bool `json:"lightTheme"`
  26. OrgCount int `json:"orgCount"`
  27. OrgId int64 `json:"orgId"`
  28. OrgName string `json:"orgName"`
  29. OrgRole m.RoleType `json:"orgRole"`
  30. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  31. GravatarUrl string `json:"gravatarUrl"`
  32. Timezone string `json:"timezone"`
  33. Locale string `json:"locale"`
  34. HelpFlags1 m.HelpFlags1 `json:"helpFlags1"`
  35. HasEditPermissionInFolders bool `json:"hasEditPermissionInFolders"`
  36. }
  37. type MetricRequest struct {
  38. From string `json:"from"`
  39. To string `json:"to"`
  40. Queries []*simplejson.Json `json:"queries"`
  41. Debug bool `json:"debug"`
  42. }
  43. type UserStars struct {
  44. DashboardIds map[string]bool `json:"dashboardIds"`
  45. }
  46. func GetGravatarUrl(text string) string {
  47. if setting.DisableGravatar {
  48. return setting.AppSubUrl + "/public/img/user_profile.png"
  49. }
  50. if text == "" {
  51. return ""
  52. }
  53. hasher := md5.New()
  54. hasher.Write([]byte(strings.ToLower(text)))
  55. return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
  56. }
  57. func GetGravatarUrlWithDefault(text string, defaultText string) string {
  58. if text != "" {
  59. return GetGravatarUrl(text)
  60. }
  61. reg, err := regexp.Compile("[^a-zA-Z0-9]+")
  62. if err != nil {
  63. return ""
  64. }
  65. text = reg.ReplaceAllString(defaultText, "") + "@localhost"
  66. return GetGravatarUrl(text)
  67. }