-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.go
executable file
·85 lines (70 loc) · 2.49 KB
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package user
import (
"strconv"
"github.com/go-bolo/bolo"
"github.com/go-bolo/system_settings"
"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)
type userSettingsJSONResponse struct {
AppName string `json:"appName"`
AppLogo string `json:"appLogo"`
Site string `json:"site"`
Hostname string `json:"hostname"`
QueryDefaultLimit int `json:"queryDefaultLimit"`
QueryMaxLimit int `json:"queryMaxLimit"`
Locales []string `json:"locales"`
DefaultLocale string `json:"defaultLocale"`
Date clientSideDateFormat `json:"date"`
Plugins []string `json:"plugins"`
User bolo.UserInterface `json:"authenticatedUser"`
ActiveLocale string `json:"activeLocale"`
UserPermissions map[string]bool `json:"userPermissions"`
SystemSettings map[string]string `json:"systemSettings"`
}
type clientSideDateFormat struct {
DefaultFormat string `json:"defaultFormat"`
}
func UserSettingsHandler(c echo.Context) error {
logrus.Debug("user.UserSettingsHandler running")
ctx := c.(*bolo.RequestContext)
cfgs := bolo.GetConfiguration()
queryDefaultLimit, _ := strconv.Atoi(cfgs.GetF("PAGER_LIMIT", "20"))
queryMaxLimit, _ := strconv.Atoi(cfgs.GetF("PAGER_LIMIT_MAX", "50"))
ss, err := system_settings.FindAllAsMap()
if err != nil {
return err
}
data := userSettingsJSONResponse{
AppName: cfgs.GetF("SITE_NAME", "App"),
Hostname: ctx.AppOrigin,
ActiveLocale: cfgs.GetF("DEFAULT_LOCALE", "en-us"),
DefaultLocale: cfgs.GetF("DEFAULT_LOCALE", "en-us"),
Date: clientSideDateFormat{DefaultFormat: "L HH:mm"},
QueryDefaultLimit: queryDefaultLimit,
QueryMaxLimit: queryMaxLimit,
Locales: []string{"pt-br"},
Plugins: []string{},
UserPermissions: make(map[string]bool),
SystemSettings: ss,
}
if ctx.IsAuthenticated {
data.User = ctx.AuthenticatedUser
// TODO! add all user authenticated data
AUserLang := ctx.AuthenticatedUser.GetLanguage()
if AUserLang != "" {
data.ActiveLocale = AUserLang
}
}
roles := ctx.GetAuthenticatedRoles()
for _, roleName := range *roles {
role := ctx.App.GetRole(roleName)
if role == nil {
continue
}
for _, permissionName := range role.Permissions {
data.UserPermissions[permissionName] = true
}
}
return c.JSON(200, &data)
}