templating: Move actions into template
This commit is contained in:
parent
313af2b9e3
commit
202599aaeb
23 changed files with 153 additions and 105 deletions
|
|
@ -36,13 +36,17 @@ type GrantWithURL struct {
|
|||
|
||||
func (panel *UserPanel) routeUser(ctx context.Context) http.Handler {
|
||||
userTemplate := panel.Dependencies.Custom.Template(userTemplate)
|
||||
crumbs := []component.MenuItem{
|
||||
{Title: "User", Path: "/user/"},
|
||||
gaps := custom.BaseContextGaps{
|
||||
Crumbs: []component.MenuItem{
|
||||
{Title: "User", Path: "/user/"},
|
||||
},
|
||||
Actions: []component.MenuItem{
|
||||
{Title: "Change Password", Path: "/user/password"},
|
||||
},
|
||||
}
|
||||
|
||||
return &httpx.HTMLHandler[routeUserContext]{
|
||||
Handler: func(r *http.Request) (ruc routeUserContext, err error) {
|
||||
panel.Dependencies.Custom.Update(&ruc, r, crumbs)
|
||||
|
||||
// find the user
|
||||
ruc.AuthUser, err = panel.Dependencies.Auth.UserOf(r)
|
||||
|
|
@ -50,6 +54,21 @@ func (panel *UserPanel) routeUser(ctx context.Context) http.Handler {
|
|||
return ruc, err
|
||||
}
|
||||
|
||||
// build the gaps
|
||||
gaps := gaps.Clone()
|
||||
if ruc.AuthUser.IsTOTPEnabled() {
|
||||
gaps.Actions = append(gaps.Actions, component.MenuItem{
|
||||
Title: "Disable Passcode (TOTP)",
|
||||
Path: "/user/totp/disable/",
|
||||
})
|
||||
} else {
|
||||
gaps.Actions = append(gaps.Actions, component.MenuItem{
|
||||
Title: "Enable Passcode (TOTP)",
|
||||
Path: "/user/totp/enable/",
|
||||
})
|
||||
}
|
||||
panel.Dependencies.Custom.Update(&ruc, r, gaps)
|
||||
|
||||
// find the grants
|
||||
grants, err := panel.Dependencies.Policy.User(r.Context(), ruc.AuthUser.User.User)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue