diff options
Diffstat (limited to 'cmd/gotosocial/action/admin/account/account.go')
-rw-r--r-- | cmd/gotosocial/action/admin/account/account.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go index 4871d89e8..4f45fd1b2 100644 --- a/cmd/gotosocial/action/admin/account/account.go +++ b/cmd/gotosocial/action/admin/account/account.go @@ -21,6 +21,8 @@ import ( "context" "errors" "fmt" + "os" + "text/tabwriter" "time" "github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action" @@ -93,6 +95,51 @@ var Create action.GTSAction = func(ctx context.Context) error { return dbConn.Stop(ctx) } +// List returns all existing local accounts. +var List action.GTSAction = func(ctx context.Context) error { + var state state.State + state.Caches.Init() + state.Workers.Start() + + dbConn, err := bundb.NewBunDBService(ctx, &state) + if err != nil { + return fmt.Errorf("error creating dbservice: %s", err) + } + + // Set the state DB connection + state.DB = dbConn + + users, err := dbConn.GetAllUsers(ctx) + if err != nil { + return err + } + + fmtBool := func(b *bool) string { + if b == nil { + return "unknown" + } + if *b { + return "yes" + } + return "no" + } + + fmtDate := func(t time.Time) string { + if t.Equal(time.Time{}) { + return "no" + } + return "yes" + } + + w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) + fmt.Fprintln(w, "user\taccount\tapproved\tadmin\tmoderator\tsuspended\tconfirmed") + for _, u := range users { + fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", u.Account.Username, u.AccountID, fmtBool(u.Approved), fmtBool(u.Admin), fmtBool(u.Moderator), fmtDate(u.Account.SuspendedAt), fmtDate(u.ConfirmedAt)) + } + w.Flush() + return nil +} + // Confirm sets a user to Approved, sets Email to the current UnconfirmedEmail value, and sets ConfirmedAt to now. var Confirm action.GTSAction = func(ctx context.Context) error { var state state.State |