-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal.go
56 lines (46 loc) · 1.27 KB
/
internal.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
package views
import (
"fmt"
"time"
"github.com/dustin/go-humanize"
"github.com/labstack/echo/v4"
"github.com/ystv/web-auth/templates"
"github.com/ystv/web-auth/user"
)
type (
// InternalTemplate represents the context for the internal template
InternalTemplate struct {
UserID int
Nickname string
LastLogin string
CountAll user.CountUsers
TemplateHelper
}
)
// InternalFunc handles a request to the internal template
func (v *Views) InternalFunc(c echo.Context) error {
c1 := v.getSessionData(c)
lastLogin := time.Now()
if c1.User.LastLogin.Valid {
lastLogin = c1.User.LastLogin.Time
}
countAll, err := v.user.CountUsersAll(c.Request().Context())
if err != nil {
return fmt.Errorf("failed to get count users all for interal: %w", err)
}
p1, err := v.user.GetPermissionsForUser(c.Request().Context(), c1.User)
if err != nil {
return fmt.Errorf("failed to get permissions for internal: %w", err)
}
ctx := InternalTemplate{
Nickname: c1.User.Nickname,
LastLogin: humanize.Time(lastLogin),
CountAll: countAll,
TemplateHelper: TemplateHelper{
UserPermissions: p1,
ActivePage: "dashboard",
Assumed: c1.Assumed,
},
}
return v.template.RenderTemplate(c.Response(), ctx, templates.InternalTemplate, templates.RegularType)
}