mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:18:52 +00:00
[feature] add enable
CLI command to mirror existing disable
command
This commit is contained in:
parent
be259b13a7
commit
f0ff929704
3 changed files with 76 additions and 3 deletions
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/validate"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
@ -294,7 +295,43 @@ var Disable action.GTSAction = func(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
user.Disabled = func() *bool { d := true; return &d }()
|
||||
user.Disabled = util.Ptr(true)
|
||||
return state.DB.UpdateUser(
|
||||
ctx, user,
|
||||
"disabled",
|
||||
)
|
||||
}
|
||||
|
||||
// Enable sets Disabled to false on a user.
|
||||
var Enable action.GTSAction = func(ctx context.Context) error {
|
||||
state, err := initState(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// Ensure state gets stopped on return.
|
||||
if err := stopState(state); err != nil {
|
||||
log.Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
|
||||
username := config.GetAdminAccountUsername()
|
||||
if err := validate.Username(username); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
account, err := state.DB.GetAccountByUsernameDomain(ctx, username, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user, err := state.DB.GetUserByAccountID(ctx, account.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user.Disabled = util.Ptr(false)
|
||||
return state.DB.UpdateUser(
|
||||
ctx, user,
|
||||
"disabled",
|
||||
|
|
|
@ -108,7 +108,7 @@ func adminCommands() *cobra.Command {
|
|||
|
||||
adminAccountDisableCmd := &cobra.Command{
|
||||
Use: "disable",
|
||||
Short: "prevent a local account from signing in or posting etc, but don't delete anything",
|
||||
Short: "set 'disabled' to true on a local account to prevent it from signing in or posting etc, but don't delete anything",
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return preRun(preRunArgs{cmd: cmd})
|
||||
},
|
||||
|
@ -119,6 +119,19 @@ func adminCommands() *cobra.Command {
|
|||
config.AddAdminAccount(adminAccountDisableCmd)
|
||||
adminAccountCmd.AddCommand(adminAccountDisableCmd)
|
||||
|
||||
adminAccountEnableCmd := &cobra.Command{
|
||||
Use: "enable",
|
||||
Short: "undo a previous disable command by setting 'disabled' to false on a local account",
|
||||
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.Enable)
|
||||
},
|
||||
}
|
||||
config.AddAdminAccount(adminAccountEnableCmd)
|
||||
adminAccountCmd.AddCommand(adminAccountEnableCmd)
|
||||
|
||||
adminAccountPasswordCmd := &cobra.Command{
|
||||
Use: "password",
|
||||
Short: "set a new password for the given local account",
|
||||
|
|
|
@ -142,7 +142,7 @@ This command can be used to disable an account on your instance: prevent it from
|
|||
`gotosocial admin account disable --help`:
|
||||
|
||||
```text
|
||||
prevent a local account from signing in or posting etc, but don't delete anything
|
||||
set 'disabled' to true on a local account to prevent it from signing in or posting etc, but don't delete anything
|
||||
|
||||
Usage:
|
||||
gotosocial admin account disable [flags]
|
||||
|
@ -158,6 +158,29 @@ Example:
|
|||
gotosocial admin account disable --username some_username --config-path config.yaml
|
||||
```
|
||||
|
||||
### gotosocial admin account enable
|
||||
|
||||
This command can be used to reenable an account on your instance, undoing a previous `disable` command.
|
||||
|
||||
`gotosocial admin account enable --help`:
|
||||
|
||||
```text
|
||||
undo a previous disable command by setting 'disabled' to false on a local account
|
||||
|
||||
Usage:
|
||||
gotosocial admin account enable [flags]
|
||||
|
||||
Flags:
|
||||
-h, --help help for enable
|
||||
--username string the username to create/delete/etc
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
gotosocial admin account enable --username some_username --config-path config.yaml
|
||||
```
|
||||
|
||||
### gotosocial admin account password
|
||||
|
||||
This command can be used to set a new password on the given local account.
|
||||
|
|
Loading…
Reference in a new issue