Update to new goprogram version
This commit is contained in:
parent
7bd9570bc0
commit
873fdcd5c2
106 changed files with 478 additions and 825 deletions
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/tkw1536/pkglib/lifetime"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/tkw1536/pkglib/httpx"
|
||||
|
|
@ -20,7 +19,7 @@ import (
|
|||
|
||||
type Admin struct {
|
||||
component.Base
|
||||
Dependencies struct {
|
||||
dependencies struct {
|
||||
Fetchers []component.DistilleryFetcher
|
||||
|
||||
Instances *instances.Instances
|
||||
|
|
@ -33,8 +32,6 @@ type Admin struct {
|
|||
|
||||
Sockets *socket.Sockets
|
||||
}
|
||||
|
||||
Analytics *lifetime.Analytics
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -47,12 +44,12 @@ func (admin *Admin) Routes() component.Routes {
|
|||
return component.Routes{
|
||||
Prefix: "/admin/",
|
||||
CSRF: true,
|
||||
Decorator: admin.Dependencies.Auth.Require(false, scopes.ScopeUserAdmin, nil),
|
||||
Decorator: admin.dependencies.Auth.Require(false, scopes.ScopeUserAdmin, nil),
|
||||
}
|
||||
}
|
||||
|
||||
func (admin *Admin) Menu(r *http.Request) []component.MenuItem {
|
||||
if admin.Dependencies.Auth.CheckScope("", scopes.ScopeUserAdmin, r) != nil {
|
||||
if admin.dependencies.Auth.CheckScope("", scopes.ScopeUserAdmin, r) != nil {
|
||||
return nil
|
||||
}
|
||||
return []component.MenuItem{
|
||||
|
|
@ -65,8 +62,7 @@ func (admin *Admin) Menu(r *http.Request) []component.MenuItem {
|
|||
}
|
||||
|
||||
var (
|
||||
menuAdmin = component.MenuItem{Title: "Admin", Path: "/admin/"}
|
||||
menuComponents = component.MenuItem{Title: "Components", Path: "/admin/components/", Priority: component.SmallButton}
|
||||
menuAdmin = component.MenuItem{Title: "Admin", Path: "/admin/"}
|
||||
|
||||
menuUsers = component.MenuItem{Title: "Users", Path: "/admin/users/"}
|
||||
menuUserCreate = component.MenuItem{Title: "Create User", Path: "/admin/users/create/"}
|
||||
|
|
@ -121,18 +117,6 @@ func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http
|
|||
router.Handler(http.MethodPost, route+"users/impersonate", admin.usersImpersonateHandler(ctx))
|
||||
router.Handler(http.MethodPost, route+"users/unsetpassword", admin.usersUnsetPasswordHandler(ctx))
|
||||
|
||||
// add a handler for the component page
|
||||
{
|
||||
components := admin.components(ctx)
|
||||
router.Handler(http.MethodGet, route+"components", components)
|
||||
}
|
||||
|
||||
// add a handler for the ingredients page
|
||||
{
|
||||
ingredients := admin.ingredients(ctx)
|
||||
router.Handler(http.MethodGet, route+"ingredients/:slug", ingredients)
|
||||
}
|
||||
|
||||
// add a handler for the instance page
|
||||
{
|
||||
instance := admin.instance(ctx)
|
||||
|
|
@ -167,7 +151,7 @@ func (admin *Admin) loginHandler(ctx context.Context) http.Handler {
|
|||
}
|
||||
|
||||
// get the instance
|
||||
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), r.PostFormValue("slug"))
|
||||
instance, err := admin.dependencies.Instances.WissKI(r.Context(), r.PostFormValue("slug"))
|
||||
if err != nil {
|
||||
return "", 0, httpx.ErrNotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,83 +0,0 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/tkw1536/pkglib/httpx"
|
||||
"github.com/tkw1536/pkglib/lifetime"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed "html/anal.html"
|
||||
var analHTML []byte
|
||||
var analTemplate = templating.Parse[analContext](
|
||||
"anal.html", analHTML, nil,
|
||||
|
||||
templating.Assets(assets.AssetsAdmin),
|
||||
)
|
||||
|
||||
type analContext struct {
|
||||
templating.RuntimeFlags
|
||||
|
||||
Analytics lifetime.Analytics
|
||||
}
|
||||
|
||||
func (admin *Admin) components(ctx context.Context) http.Handler {
|
||||
tpl := analTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
menuComponents,
|
||||
),
|
||||
templating.Title("Components"),
|
||||
)
|
||||
|
||||
return tpl.HTMLHandler(func(r *http.Request) (ac analContext, err error) {
|
||||
ac.Analytics = *admin.Analytics
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func (admin *Admin) ingredients(ctx context.Context) http.Handler {
|
||||
tpl := analTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
menuInstance,
|
||||
menuIngredients,
|
||||
),
|
||||
)
|
||||
|
||||
return tpl.HTMLHandlerWithFlags(func(r *http.Request) (ac analContext, funcs []templating.FlagFunc, err error) {
|
||||
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||
|
||||
// find the instance itself!
|
||||
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||
if err == instances.ErrWissKINotFound {
|
||||
return ac, nil, httpx.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return ac, nil, err
|
||||
}
|
||||
funcs = []templating.FlagFunc{
|
||||
templating.ReplaceCrumb(menuInstance, component.MenuItem{Title: "Instance", Path: template.URL("/admin/instance/" + slug)}),
|
||||
templating.ReplaceCrumb(menuIngredients, component.MenuItem{Title: "Ingredients", Path: template.URL("/admin/instance/" + slug + "/ingredients/")}),
|
||||
templating.Title(instance.Name() + " - Ingredients"),
|
||||
}
|
||||
|
||||
// and get the components
|
||||
ac.Analytics = *instance.Info().Analytics
|
||||
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ type grantsContext struct {
|
|||
|
||||
func (admin *Admin) grants(ctx context.Context) http.Handler {
|
||||
tpl := grantsTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
|
|
@ -100,13 +100,13 @@ func (admin *Admin) postGrants(r *http.Request) (gc grantsContext, funcs []templ
|
|||
|
||||
if delete {
|
||||
// delete the user grant
|
||||
err := admin.Dependencies.Policy.Remove(r.Context(), distilleryUser, slug)
|
||||
err := admin.dependencies.Policy.Remove(r.Context(), distilleryUser, slug)
|
||||
if err != nil {
|
||||
return gc, nil, err
|
||||
}
|
||||
} else {
|
||||
// update the grant
|
||||
err := admin.Dependencies.Policy.Set(r.Context(), models.Grant{
|
||||
err := admin.dependencies.Policy.Set(r.Context(), models.Grant{
|
||||
User: distilleryUser,
|
||||
Slug: slug,
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ func (admin *Admin) postGrants(r *http.Request) (gc grantsContext, funcs []templ
|
|||
|
||||
func (gc *grantsContext) use(r *http.Request, slug string, admin *Admin) (funcs []templating.FlagFunc, err error) {
|
||||
// find the instance itself
|
||||
gc.instance, err = admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||
gc.instance, err = admin.dependencies.Instances.WissKI(r.Context(), slug)
|
||||
if err == instances.ErrWissKINotFound {
|
||||
return nil, httpx.ErrNotFound
|
||||
}
|
||||
|
|
@ -146,12 +146,12 @@ func (gc *grantsContext) use(r *http.Request, slug string, admin *Admin) (funcs
|
|||
}
|
||||
|
||||
func (gc *grantsContext) useGrants(r *http.Request, admin *Admin) (err error) {
|
||||
gc.Grants, err = admin.Dependencies.Policy.Instance(r.Context(), gc.Instance.Slug)
|
||||
gc.Grants, err = admin.dependencies.Policy.Instance(r.Context(), gc.Instance.Slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
users, err := admin.Dependencies.Auth.Users(r.Context())
|
||||
users, err := admin.dependencies.Auth.Users(r.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,139 +0,0 @@
|
|||
<div class="pure-u-1-1">
|
||||
<h2 id="structs">Structs</h2>
|
||||
</div>
|
||||
|
||||
{{ range $name, $comp := .Analytics.Components }}
|
||||
<div class="pure-u-1-1" id="{{ $name }}">
|
||||
<div class="padding">
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
{{ $name }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Groups }}
|
||||
<tr>
|
||||
<td>
|
||||
Implements
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<code><a href="#{{.}}">{{ . }}</a></code><br />
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $comp := .CFields }}
|
||||
<tr>
|
||||
<td>Component Pointer</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $comp }}">{{ $comp }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $comp := .DCFields }}
|
||||
<tr>
|
||||
<td>Component Pointer</td>
|
||||
<td>
|
||||
<code>Dependencies/{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $comp }}">{{ $comp }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $iface := .IFields }}
|
||||
<tr>
|
||||
<td>Interface Slice</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $iface }}">[]{{ $iface }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $iface := .DIFields }}
|
||||
<tr>
|
||||
<td>Interface Slice</td>
|
||||
<td>
|
||||
<code>Dependencies/{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code><a href="#{{ $iface }}">[]{{ $iface }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $name, $sig := $comp.Methods }}
|
||||
<tr>
|
||||
<td>
|
||||
Method
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $sig }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<div class="pure-u-1-1">
|
||||
<h2 id="interfaces">Interfaces</h2>
|
||||
</div>
|
||||
|
||||
{{ range $name, $group := .Analytics.Groups }}
|
||||
<div class="pure-u-1-1" id="{{ $name }}">
|
||||
<div class="padding">
|
||||
|
||||
<div class="overflow">
|
||||
<table class="pure-table pure-table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
{{ $name }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range $name, $sig := $group.Methods }}
|
||||
<tr>
|
||||
<td>
|
||||
Method
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $name }}</code>
|
||||
</td>
|
||||
<td>
|
||||
<code>{{ $sig }}</code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
{{ range $group.Components }}
|
||||
<tr>
|
||||
<td>
|
||||
Implemented By
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<code><a href="#{{.}}">{{ . }}</a></code>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
@ -21,7 +21,7 @@ func (admin *Admin) Status(ctx context.Context, QuickInformation bool) (target s
|
|||
|
||||
group.Go(func() error {
|
||||
// list all the instances
|
||||
all, err := admin.Dependencies.Instances.All(ctx)
|
||||
all, err := admin.dependencies.Instances.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ func (admin *Admin) Status(ctx context.Context, QuickInformation bool) (target s
|
|||
flags := component.FetcherFlags{
|
||||
Context: ctx,
|
||||
}
|
||||
for _, o := range admin.Dependencies.Fetchers {
|
||||
for _, o := range admin.dependencies.Fetchers {
|
||||
o := o
|
||||
group.Go(func() error {
|
||||
return o.Fetch(flags, &target)
|
||||
|
|
@ -109,11 +109,10 @@ type indexContext struct {
|
|||
|
||||
func (admin *Admin) index(ctx context.Context) http.Handler {
|
||||
tpl := indexTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Actions(
|
||||
menuUsers,
|
||||
menuInstances,
|
||||
menuComponents,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -125,7 +124,7 @@ func (admin *Admin) index(ctx context.Context) http.Handler {
|
|||
|
||||
func (admin *Admin) instances(ctx context.Context) http.Handler {
|
||||
tpl := instancesTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ type instanceContext struct {
|
|||
|
||||
func (admin *Admin) instance(ctx context.Context) http.Handler {
|
||||
tpl := instanceTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuInstances,
|
||||
|
|
@ -51,7 +51,7 @@ func (admin *Admin) instance(ctx context.Context) http.Handler {
|
|||
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||
|
||||
// find the instance itself!
|
||||
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||
instance, err := admin.dependencies.Instances.WissKI(r.Context(), slug)
|
||||
if err == instances.ErrWissKINotFound {
|
||||
return ic, nil, httpx.ErrNotFound
|
||||
}
|
||||
|
|
@ -70,7 +70,6 @@ func (admin *Admin) instance(ctx context.Context) http.Handler {
|
|||
templating.ReplaceCrumb(menuInstance, component.MenuItem{Title: "Instance", Path: template.URL("/admin/instance/" + slug)}),
|
||||
templating.ReplaceAction(menuRebuild, component.MenuItem{Title: "Rebuild", Path: template.URL("/admin/rebuild/" + slug)}),
|
||||
templating.ReplaceAction(menuGrants, component.MenuItem{Title: "Grants", Path: template.URL("/admin/grants/" + slug)}),
|
||||
templating.ReplaceAction(menuIngredients, component.MenuItem{Title: "Ingredients", Path: template.URL("/admin/ingredients/" + slug), Priority: component.SmallButton}),
|
||||
|
||||
templating.Title(instance.Slug),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
func (admin *Admin) instanceProvision(ctx context.Context) http.Handler {
|
||||
tpl := instanceSystemTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
|
||||
templating.Title("Provision New Instance"),
|
||||
templating.Assets(assets.AssetsAdminProvision),
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func (isc *instanceSystemContext) prepare(rebuild bool) {
|
|||
|
||||
func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
||||
tpl := instanceSystemTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
|
||||
templating.Title("Rebuild Instance"),
|
||||
templating.Assets(assets.AssetsAdminRebuild),
|
||||
|
|
@ -65,7 +65,7 @@ func (admin *Admin) instanceRebuild(ctx context.Context) http.Handler {
|
|||
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||
|
||||
var instance *wisski.WissKI
|
||||
instance, err = admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||
instance, err = admin.dependencies.Instances.WissKI(r.Context(), slug)
|
||||
if err == instances.ErrWissKINotFound {
|
||||
return isc, nil, httpx.ErrNotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func (sockets *Sockets) Actions() ActionMap {
|
|||
return map[string]Action{
|
||||
// generic actions
|
||||
"backup": sockets.Generic(scopes.ScopeUserAdmin, "", 0, func(ctx context.Context, sockets *Sockets, in io.Reader, out io.Writer, params ...string) error {
|
||||
return sockets.Dependencies.Exporter.MakeExport(
|
||||
return sockets.dependencies.Exporter.MakeExport(
|
||||
ctx,
|
||||
out,
|
||||
exporter.ExportTask{
|
||||
|
|
@ -35,7 +35,7 @@ func (sockets *Sockets) Actions() ActionMap {
|
|||
return err
|
||||
}
|
||||
|
||||
instance, err := sockets.Dependencies.Provision.Provision(
|
||||
instance, err := sockets.dependencies.Provision.Provision(
|
||||
out,
|
||||
ctx,
|
||||
flags,
|
||||
|
|
@ -54,7 +54,7 @@ func (sockets *Sockets) Actions() ActionMap {
|
|||
// instance-specific actions!
|
||||
|
||||
"snapshot": sockets.Instance(scopes.ScopeUserAdmin, "", 0, func(ctx context.Context, socket *Sockets, instance *wisski.WissKI, in io.Reader, out io.Writer, params ...string) error {
|
||||
return socket.Dependencies.Exporter.MakeExport(
|
||||
return socket.dependencies.Exporter.MakeExport(
|
||||
ctx,
|
||||
out,
|
||||
exporter.ExportTask{
|
||||
|
|
@ -86,7 +86,7 @@ func (sockets *Sockets) Actions() ActionMap {
|
|||
return instance.Barrel().Stack().Down(ctx, out)
|
||||
}),
|
||||
"purge": sockets.Instance(scopes.ScopeUserAdmin, "", 0, func(ctx context.Context, sockets *Sockets, instance *wisski.WissKI, in io.Reader, out io.Writer, params ...string) error {
|
||||
return sockets.Dependencies.Purger.Purge(ctx, out, instance.Slug)
|
||||
return sockets.dependencies.Purger.Purge(ctx, out, instance.Slug)
|
||||
}),
|
||||
"never": sockets.Generic(scopes.ScopeNever, "", 0, func(ctx context.Context, sockets *Sockets, in io.Reader, out io.Writer, params ...string) error {
|
||||
panic("never called")
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type Sockets struct {
|
|||
|
||||
actions lazy.Lazy[ActionMap]
|
||||
|
||||
Dependencies struct {
|
||||
dependencies struct {
|
||||
Provision *provision.Provision
|
||||
Instances *instances.Instances
|
||||
Exporter *exporter.Exporter
|
||||
|
|
@ -40,7 +40,7 @@ func (socket *Sockets) Routes() component.Routes {
|
|||
return component.Routes{
|
||||
Prefix: "/api/v1/ws",
|
||||
Exact: true,
|
||||
Decorator: socket.Dependencies.Auth.Require(true, scopes.ScopeUserValid, nil),
|
||||
Decorator: socket.dependencies.Auth.Require(true, scopes.ScopeUserValid, nil),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ func (sockets *Sockets) HandleRoute(ctx context.Context, path string) (http.Hand
|
|||
// Serve handles a connection to the websocket api
|
||||
func (socket *Sockets) Serve(conn httpx.WebSocketConnection) {
|
||||
// handle the websocket connection!
|
||||
name, err := socket.actions.Get(socket.Actions).Handle(socket.Dependencies.Auth, conn)
|
||||
name, err := socket.actions.Get(socket.Actions).Handle(socket.dependencies.Auth, conn)
|
||||
if err != nil {
|
||||
zerolog.Ctx(conn.Context()).Err(err).Str("name", name).Msg("Error handling websocket")
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ func (sockets *Sockets) Instance(scope component.Scope, scopeParam string, numPa
|
|||
|
||||
NumParams: numParams + 1,
|
||||
Handle: func(ctx context.Context, in io.Reader, out io.Writer, params ...string) error {
|
||||
instance, err := sockets.Dependencies.Instances.WissKI(ctx, params[0])
|
||||
instance, err := sockets.dependencies.Instances.WissKI(ctx, params[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ type usersContext struct {
|
|||
|
||||
func (admin *Admin) users(ctx context.Context) http.Handler {
|
||||
tpl := usersTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuUsers,
|
||||
|
|
@ -45,7 +45,7 @@ func (admin *Admin) users(ctx context.Context) http.Handler {
|
|||
|
||||
return tpl.HTMLHandler(func(r *http.Request) (uc usersContext, err error) {
|
||||
uc.Error = r.URL.Query().Get("error")
|
||||
uc.Users, err = admin.Dependencies.Auth.Users(r.Context())
|
||||
uc.Users, err = admin.dependencies.Auth.Users(r.Context())
|
||||
return
|
||||
})
|
||||
}
|
||||
|
|
@ -72,7 +72,7 @@ type createUserResult struct {
|
|||
|
||||
func (admin *Admin) createUser(ctx context.Context) http.Handler {
|
||||
tpl := userCreateTemplate.Prepare(
|
||||
admin.Dependencies.Templating,
|
||||
admin.dependencies.Templating,
|
||||
templating.Crumbs(
|
||||
menuAdmin,
|
||||
menuUsers,
|
||||
|
|
@ -102,7 +102,7 @@ func (admin *Admin) createUser(ctx context.Context) http.Handler {
|
|||
}
|
||||
|
||||
// check the password policy
|
||||
err = admin.Dependencies.Auth.CheckPasswordPolicy(cu.Passsword, cu.User)
|
||||
err = admin.dependencies.Auth.CheckPasswordPolicy(cu.Passsword, cu.User)
|
||||
if err != nil {
|
||||
return cu, err
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ func (admin *Admin) createUser(ctx context.Context) http.Handler {
|
|||
|
||||
RenderSuccess: func(cu createUserResult, values map[string]string, w http.ResponseWriter, r *http.Request) error {
|
||||
// create the user
|
||||
user, err := admin.Dependencies.Auth.CreateUser(r.Context(), cu.User)
|
||||
user, err := admin.dependencies.Auth.CreateUser(r.Context(), cu.User)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -151,14 +151,14 @@ func (admin *Admin) useraction(ctx context.Context, name string, action func(r *
|
|||
}
|
||||
|
||||
username := r.PostFormValue("user")
|
||||
user, err := admin.Dependencies.Auth.User(r.Context(), username)
|
||||
user, err := admin.dependencies.Auth.User(r.Context(), username)
|
||||
if err != nil {
|
||||
logger.Err(err).Str("action", name).Msg("failed to get user")
|
||||
httpx.HTMLInterceptor.Fallback.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
me, err := admin.Dependencies.Auth.UserOfSession(r)
|
||||
me, err := admin.dependencies.Auth.UserOfSession(r)
|
||||
if err != nil {
|
||||
logger.Err(err).Str("action", name).Msg("failed to get current user")
|
||||
httpx.HTMLInterceptor.Fallback.ServeHTTP(w, r)
|
||||
|
|
@ -241,7 +241,7 @@ func (admin *Admin) usersImpersonateHandler(ctx context.Context) http.Handler {
|
|||
}
|
||||
|
||||
username := r.PostFormValue("user")
|
||||
user, err := admin.Dependencies.Auth.User(r.Context(), username)
|
||||
user, err := admin.dependencies.Auth.User(r.Context(), username)
|
||||
if err != nil {
|
||||
logger.Err(err).Str("action", "impersonate").Msg("failed to get user")
|
||||
httpx.HTMLInterceptor.Fallback.ServeHTTP(w, r)
|
||||
|
|
@ -249,7 +249,7 @@ func (admin *Admin) usersImpersonateHandler(ctx context.Context) http.Handler {
|
|||
}
|
||||
|
||||
// login the user into the session of the provided user
|
||||
if err := admin.Dependencies.Auth.Login(w, r, user); err != nil {
|
||||
if err := admin.dependencies.Auth.Login(w, r, user); err != nil {
|
||||
logger.Err(err).Str("action", "impersonate").Msg("failed to login user")
|
||||
httpx.HTMLInterceptor.Fallback.ServeHTTP(w, r)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue