From 104db94826d7a8d5e0354511a37984ac7b3c801f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 17 Jan 2025 11:44:33 +0300 Subject: [PATCH] remove unused adminstore --- handlers/application/menuhandler.go | 4 +-- handlers/local.go | 18 ++++------ store/adminstore.go | 51 ----------------------------- 3 files changed, 7 insertions(+), 66 deletions(-) delete mode 100644 store/adminstore.go diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 45aa369..11b551c 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -70,7 +70,6 @@ type MenuHandlers struct { st *state.State ca cache.Memory userdataStore store.DataStore - adminstore *store.AdminStore flagManager *FlagManager accountService remote.AccountService prefixDb storedb.PrefixDb @@ -79,7 +78,7 @@ type MenuHandlers struct { } // 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 { 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{ userdataStore: userDb, flagManager: appFlags, - adminstore: adminstore, accountService: accountService, prefixDb: prefixDb, profile: &profile.Profile{Max: 6}, diff --git a/handlers/local.go b/handlers/local.go index a060f1a..325fe89 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -11,7 +11,6 @@ import ( "git.grassecon.net/grassrootseconomics/sarafu-api/remote" "git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application" - "git.grassecon.net/grassrootseconomics/sarafu-vise/store" ) type HandlerService interface { @@ -23,7 +22,6 @@ type LocalHandlerService struct { DbRs *resource.DbResource Pe *persist.Persister UserdataStore *db.Db - AdminStore *store.AdminStore Cfg engine.Config Rs resource.Resource } @@ -36,16 +34,12 @@ func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResour if debug { parser.SetDebug() } - adminstore, err := store.NewAdminStore(ctx, "admin_numbers") - if err != nil { - return nil, err - } + return &LocalHandlerService{ - Parser: parser, - DbRs: dbResource, - AdminStore: adminstore, - Cfg: cfg, - Rs: rs, + Parser: parser, + DbRs: dbResource, + Cfg: cfg, + Rs: rs, }, nil } @@ -62,7 +56,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) 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 { return nil, err } diff --git a/store/adminstore.go b/store/adminstore.go deleted file mode 100644 index d20c5e1..0000000 --- a/store/adminstore.go +++ /dev/null @@ -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 -}