User Management: Fix regressions
This commit is contained in:
parent
6f257bd27f
commit
66e57183d6
6 changed files with 17 additions and 10 deletions
|
|
@ -23,7 +23,7 @@
|
||||||
{{ if .User.IsTOTPEnabled }}
|
{{ if .User.IsTOTPEnabled }}
|
||||||
<li>Passcode Enabled: <b>true</b></li>
|
<li>Passcode Enabled: <b>true</b></li>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<li>Passcode Enabled: <b>false</b> <small>(some actions are disabled)</small></li>
|
<li>Passcode Enabled: <b>false</b> {{ if .User.IsAdmin }}<small>(some admin actions are disabled)</small>{{ end }}</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ var Admin Permission = func(user *AuthUser, r *http.Request) (ok Grant, err erro
|
||||||
return Bool2Grant(user != nil && user.IsAdmin() && user.IsTOTPEnabled(), "user needs to have admin permissions and passcode enabled"), nil
|
return Bool2Grant(user != nil && user.IsAdmin() && user.IsTOTPEnabled(), "user needs to have admin permissions and passcode enabled"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// User represents a permission that checks if a user has totp enabled.
|
// User represents a permission that checks if a user is enabled
|
||||||
var User Permission = func(user *AuthUser, r *http.Request) (ok Grant, err error) {
|
var User Permission = func(user *AuthUser, r *http.Request) (ok Grant, err error) {
|
||||||
return Bool2Grant(user != nil && user.IsEnabled() && user.IsTOTPEnabled(), "user needs to have passcode enabled"), nil
|
return Bool2Grant(user != nil && user.IsEnabled(), "user needs to be enabled"), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
"github.com/FAU-CDI/wisski-distillery/pkg/lazy"
|
||||||
"github.com/gorilla/mux"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed "html/components.html"
|
//go:embed "html/components.html"
|
||||||
|
|
@ -52,7 +52,8 @@ func (admin *Admin) ingredients(r *http.Request) (cp ingredientsContext, err err
|
||||||
admin.Dependencies.Custom.Update(&cp, r)
|
admin.Dependencies.Custom.Update(&cp, r)
|
||||||
|
|
||||||
// find the instance itself!
|
// find the instance itself!
|
||||||
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||||
|
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||||
if err == instances.ErrWissKINotFound {
|
if err == instances.ErrWissKINotFound {
|
||||||
return cp, httpx.ErrNotFound
|
return cp, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx/field"
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx/field"
|
||||||
"github.com/gorilla/mux"
|
"github.com/julienschmidt/httprouter"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
@ -94,7 +94,8 @@ func (gc *grantsContext) useGrants(r *http.Request, admin *Admin) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (admin *Admin) getGrants(r *http.Request) (gc grantsContext, err error) {
|
func (admin *Admin) getGrants(r *http.Request) (gc grantsContext, err error) {
|
||||||
if err := gc.use(r, mux.Vars(r)["slug"], admin); err != nil {
|
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||||
|
if err := gc.use(r, slug, admin); err != nil {
|
||||||
return gc, err
|
return gc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||||
"github.com/gorilla/mux"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed "html/instance.html"
|
//go:embed "html/instance.html"
|
||||||
|
|
@ -31,7 +31,8 @@ func (admin *Admin) instance(r *http.Request) (is instanceContext, err error) {
|
||||||
admin.Dependencies.Custom.Update(&is, r)
|
admin.Dependencies.Custom.Update(&is, r)
|
||||||
|
|
||||||
// find the instance itself!
|
// find the instance itself!
|
||||||
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), mux.Vars(r)["slug"])
|
slug := httprouter.ParamsFromContext(r.Context()).ByName("slug")
|
||||||
|
instance, err := admin.Dependencies.Instances.WissKI(r.Context(), slug)
|
||||||
if err == instances.ErrWissKINotFound {
|
if err == instances.ErrWissKINotFound {
|
||||||
return is, httpx.ErrNotFound
|
return is, httpx.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ func (instances *Instances) use(wisski *wisski.WissKI) {
|
||||||
// WissKI returns the WissKI with the provided slug, if it exists.
|
// WissKI returns the WissKI with the provided slug, if it exists.
|
||||||
// It the WissKI does not exist, returns ErrWissKINotFound.
|
// It the WissKI does not exist, returns ErrWissKINotFound.
|
||||||
func (instances *Instances) WissKI(ctx context.Context, slug string) (wissKI *wisski.WissKI, err error) {
|
func (instances *Instances) WissKI(ctx context.Context, slug string) (wissKI *wisski.WissKI, err error) {
|
||||||
|
if slug == "" {
|
||||||
|
return nil, ErrWissKINotFound
|
||||||
|
}
|
||||||
|
|
||||||
sql := instances.Dependencies.SQL
|
sql := instances.Dependencies.SQL
|
||||||
if err := sql.WaitQueryTable(ctx); err != nil {
|
if err := sql.WaitQueryTable(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -61,7 +65,7 @@ func (instances *Instances) WissKI(ctx context.Context, slug string) (wissKI *wi
|
||||||
wissKI = new(wisski.WissKI)
|
wissKI = new(wisski.WissKI)
|
||||||
|
|
||||||
// find the instance by slug
|
// find the instance by slug
|
||||||
query := table.Where(&models.Instance{Slug: slug}).Find(&wissKI.Liquid.Instance)
|
query := table.Find(&wissKI.Liquid.Instance, &models.Instance{Slug: slug})
|
||||||
switch {
|
switch {
|
||||||
case query.Error != nil:
|
case query.Error != nil:
|
||||||
return nil, errSQL.WithMessageF(query.Error)
|
return nil, errSQL.WithMessageF(query.Error)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue