summaryrefslogtreecommitdiff
path: root/internal/clitools/admin
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-30 13:12:00 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-30 13:12:00 +0200
commit3d77f81c7fed002c628db82d822cc46c56a57e64 (patch)
treeba6eea80246fc2b1466ccc1435f50a3f63fd02df /internal/clitools/admin
parentfix some lil bugs in search (diff)
downloadgotosocial-3d77f81c7fed002c628db82d822cc46c56a57e64.tar.xz
Move a lot of stuff + tidy stuff (#37)
Lots of renaming and moving stuff, some bug fixes, more lenient parsing of notifications and home timeline.
Diffstat (limited to 'internal/clitools/admin')
-rw-r--r--internal/clitools/admin/account/account.go209
1 files changed, 0 insertions, 209 deletions
diff --git a/internal/clitools/admin/account/account.go b/internal/clitools/admin/account/account.go
deleted file mode 100644
index da4de4711..000000000
--- a/internal/clitools/admin/account/account.go
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package account
-
-import (
- "context"
- "errors"
- "fmt"
- "time"
-
- "github.com/sirupsen/logrus"
- "github.com/superseriousbusiness/gotosocial/internal/action"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/db/pg"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/util"
-)
-
-// Create creates a new account in the database using the provided flags.
-var Create action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
- dbConn, err := pg.NewPostgresService(ctx, c, log)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := util.ValidateUsername(username); err != nil {
- return err
- }
-
- email, ok := c.AccountCLIFlags[config.EmailFlag]
- if !ok {
- return errors.New("no email set")
- }
- if err := util.ValidateEmail(email); err != nil {
- return err
- }
-
- password, ok := c.AccountCLIFlags[config.PasswordFlag]
- if !ok {
- return errors.New("no password set")
- }
- if err := util.ValidateNewPassword(password); err != nil {
- return err
- }
-
- _, err = dbConn.NewSignup(username, "", false, email, password, nil, "", "")
- if err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// 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, c *config.Config, log *logrus.Logger) error {
- dbConn, err := pg.NewPostgresService(ctx, c, log)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := util.ValidateUsername(username); err != nil {
- return err
- }
-
- a := &gtsmodel.Account{}
- if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere([]db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
-
- u.Approved = true
- u.Email = u.UnconfirmedEmail
- u.ConfirmedAt = time.Now()
- if err := dbConn.UpdateByID(u.ID, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Promote sets a user to admin.
-var Promote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
- dbConn, err := pg.NewPostgresService(ctx, c, log)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := util.ValidateUsername(username); err != nil {
- return err
- }
-
- a := &gtsmodel.Account{}
- if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere([]db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Admin = true
- if err := dbConn.UpdateByID(u.ID, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Demote sets admin on a user to false.
-var Demote action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
- dbConn, err := pg.NewPostgresService(ctx, c, log)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := util.ValidateUsername(username); err != nil {
- return err
- }
-
- a := &gtsmodel.Account{}
- if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere([]db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Admin = false
- if err := dbConn.UpdateByID(u.ID, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-// Disable sets Disabled to true on a user.
-var Disable action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
- dbConn, err := pg.NewPostgresService(ctx, c, log)
- if err != nil {
- return fmt.Errorf("error creating dbservice: %s", err)
- }
-
- username, ok := c.AccountCLIFlags[config.UsernameFlag]
- if !ok {
- return errors.New("no username set")
- }
- if err := util.ValidateUsername(username); err != nil {
- return err
- }
-
- a := &gtsmodel.Account{}
- if err := dbConn.GetLocalAccountByUsername(username, a); err != nil {
- return err
- }
-
- u := &gtsmodel.User{}
- if err := dbConn.GetWhere([]db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil {
- return err
- }
- u.Disabled = true
- if err := dbConn.UpdateByID(u.ID, u); err != nil {
- return err
- }
-
- return dbConn.Stop(ctx)
-}
-
-var Suspend action.GTSAction = func(ctx context.Context, c *config.Config, log *logrus.Logger) error {
- // TODO
- return nil
-}