lash/admin-tool #8

Merged
lash merged 7 commits from lash/admin-tool into master 2025-01-17 10:02:04 +01:00
3 changed files with 7 additions and 66 deletions
Showing only changes of commit 104db94826 - Show all commits

View File

@ -70,7 +70,6 @@ type MenuHandlers struct {
st *state.State st *state.State
ca cache.Memory ca cache.Memory
userdataStore store.DataStore userdataStore store.DataStore
adminstore *store.AdminStore
flagManager *FlagManager flagManager *FlagManager
accountService remote.AccountService accountService remote.AccountService
prefixDb storedb.PrefixDb prefixDb storedb.PrefixDb
@ -79,7 +78,7 @@ type MenuHandlers struct {
} }
// NewHandlers creates a new instance of the Handlers struct with the provided dependencies. // NewHandlers creates a new instance of the Handlers struct with the provided dependencies.
func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, adminstore *store.AdminStore, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) { func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) {
if userdataStore == nil { if userdataStore == nil {
return nil, fmt.Errorf("cannot create handler with nil userdata store") return nil, fmt.Errorf("cannot create handler with nil userdata store")
} }
@ -94,7 +93,6 @@ func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, adminstore *sto
h := &MenuHandlers{ h := &MenuHandlers{
userdataStore: userDb, userdataStore: userDb,
flagManager: appFlags, flagManager: appFlags,
adminstore: adminstore,
accountService: accountService, accountService: accountService,
prefixDb: prefixDb, prefixDb: prefixDb,
profile: &profile.Profile{Max: 6}, profile: &profile.Profile{Max: 6},

View File

@ -11,7 +11,6 @@ import (
"git.grassecon.net/grassrootseconomics/sarafu-api/remote" "git.grassecon.net/grassrootseconomics/sarafu-api/remote"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
) )
type HandlerService interface { type HandlerService interface {
@ -23,7 +22,6 @@ type LocalHandlerService struct {
DbRs *resource.DbResource DbRs *resource.DbResource
Pe *persist.Persister Pe *persist.Persister
UserdataStore *db.Db UserdataStore *db.Db
AdminStore *store.AdminStore
Cfg engine.Config Cfg engine.Config
Rs resource.Resource Rs resource.Resource
} }
@ -36,16 +34,12 @@ func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResour
if debug { if debug {
parser.SetDebug() parser.SetDebug()
} }
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
if err != nil {
return nil, err
}
return &LocalHandlerService{ return &LocalHandlerService{
Parser: parser, Parser: parser,
DbRs: dbResource, DbRs: dbResource,
AdminStore: adminstore, Cfg: cfg,
Cfg: cfg, Rs: rs,
Rs: rs,
}, nil }, nil
} }
@ -62,7 +56,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator) return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
} }
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc) appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, accountService, replaceSeparatorFunc)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,51 +0,0 @@
package store
import (
"context"
"git.defalsify.org/vise.git/db"
fsdb "git.defalsify.org/vise.git/db/fs"
"git.defalsify.org/vise.git/logging"
)
var (
logg = logging.NewVanilla().WithDomain("adminstore")
)
type AdminStore struct {
ctx context.Context
FsStore db.Db
}
func NewAdminStore(ctx context.Context, fileName string) (*AdminStore, error) {
fsStore, err := getFsStore(ctx, fileName)
if err != nil {
return nil, err
}
return &AdminStore{ctx: ctx, FsStore: fsStore}, nil
}
func getFsStore(ctx context.Context, connectStr string) (db.Db, error) {
fsStore := fsdb.NewFsDb()
err := fsStore.Connect(ctx, connectStr)
fsStore.SetPrefix(db.DATATYPE_USERDATA)
if err != nil {
return nil, err
}
return fsStore, nil
}
// Checks if the given sessionId is listed as an admin.
func (as *AdminStore) IsAdmin(sessionId string) (bool, error) {
_, err := as.FsStore.Get(as.ctx, []byte(sessionId))
if err != nil {
if db.IsNotFound(err) {
logg.Printf(logging.LVL_INFO, "Returning false because session id was not found")
return false, nil
} else {
return false, err
}
}
return true, nil
}