user panel: Add admin interface button

This commit is contained in:
Tom 2023-05-04 15:49:37 +02:00
parent 8f362172db
commit 6d48261876
2 changed files with 22 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth/scopes"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/internal/models"
@ -26,7 +27,8 @@ type userContext struct {
templating.RuntimeFlags
*auth.AuthUser
Grants []GrantWithURL
ShowAdminURLs bool
Grants []GrantWithURL
}
type GrantWithURL struct {
@ -34,6 +36,10 @@ type GrantWithURL struct {
URL template.URL
}
func (g GrantWithURL) AdminURL() template.URL {
return template.URL("/admin/instance/" + g.Slug)
}
func (panel *UserPanel) routeUser(ctx context.Context) http.Handler {
tpl := userTemplate.Prepare(
@ -55,6 +61,8 @@ func (panel *UserPanel) routeUser(ctx context.Context) http.Handler {
return uc, nil, err
}
uc.ShowAdminURLs = panel.Dependencies.Auth.CheckScope("", scopes.ScopeAdminLoggedIn, r) == nil
// replace the totp action in the menu
var totpAction component.MenuItem
if uc.AuthUser.IsTOTPEnabled() {