mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
enforce admin user requirement in context for command execution
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
5c7e35b793
commit
2178a57f8c
@ -7,14 +7,21 @@ import (
|
|||||||
|
|
||||||
"github.com/navidrome/navidrome/core/auth"
|
"github.com/navidrome/navidrome/core/auth"
|
||||||
"github.com/navidrome/navidrome/db"
|
"github.com/navidrome/navidrome/db"
|
||||||
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
|
"github.com/navidrome/navidrome/model/request"
|
||||||
"github.com/navidrome/navidrome/persistence"
|
"github.com/navidrome/navidrome/persistence"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAdminContext(ctx context.Context) (model.DataStore, context.Context) {
|
func getAdminContext(ctx context.Context) (model.DataStore, context.Context) {
|
||||||
sqlDB := db.Db()
|
sqlDB := db.Db()
|
||||||
ds := persistence.New(sqlDB)
|
ds := persistence.New(sqlDB)
|
||||||
return ds, auth.WithAdminUser(ctx, ds)
|
ctx = auth.WithAdminUser(ctx, ds)
|
||||||
|
u, _ := request.UserFrom(ctx)
|
||||||
|
if !u.IsAdmin {
|
||||||
|
log.Fatal(ctx, "There must be at least one admin user to run this command.")
|
||||||
|
}
|
||||||
|
return ds, ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUser(ctx context.Context, id string, ds model.DataStore) (*model.User, error) {
|
func getUser(ctx context.Context, id string, ds model.DataStore) (*model.User, error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user