diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gotosocial/action/admin/account/account.go | 47 | ||||
-rw-r--r-- | cmd/gotosocial/admin.go | 12 |
2 files changed, 59 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 diff --git a/cmd/gotosocial/admin.go b/cmd/gotosocial/admin.go index 185880e3d..810d57e54 100644 --- a/cmd/gotosocial/admin.go +++ b/cmd/gotosocial/admin.go @@ -54,6 +54,18 @@ func adminCommands() *cobra.Command { config.AddAdminAccountCreate(adminAccountCreateCmd) adminAccountCmd.AddCommand(adminAccountCreateCmd) + adminAccountListCmd := &cobra.Command{ + Use: "list", + Short: "list all existing local accounts", + PreRunE: func(cmd *cobra.Command, args []string) error { + return preRun(preRunArgs{cmd: cmd}) + }, + RunE: func(cmd *cobra.Command, args []string) error { + return run(cmd.Context(), account.List) + }, + } + adminAccountCmd.AddCommand(adminAccountListCmd) + adminAccountConfirmCmd := &cobra.Command{ Use: "confirm", Short: "confirm an existing local account manually, thereby skipping email confirmation", |