Skip to content

Commit

Permalink
Add a option --bot to admin user create
Browse files Browse the repository at this point in the history
Partially solve #13044
  • Loading branch information
mscherer committed Nov 2, 2023
1 parent dc52f26 commit 46b6867
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/admin_user_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ var microcmdUserCreate = &cli.Command{
Name: "restricted",
Usage: "Make a restricted user account",
},
&cli.BoolFlag{
Name: "bot",
Usage: "Make a bot user account",
},
},
}

Expand Down Expand Up @@ -129,6 +133,13 @@ func runCreateUser(c *cli.Context) error {
restricted = util.OptionalBoolOf(c.Bool("restricted"))
}

userType := user_model.UserTypeIndividual
if c.IsSet("bot") {
if c.Bool("bot") {
userType = user_model.UserTypeBot
}
}

// default user visibility in app.ini
visibility := setting.Service.DefaultUserVisibilityMode

Expand All @@ -144,6 +155,7 @@ func runCreateUser(c *cli.Context) error {
overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolTrue,
IsRestricted: restricted,
Type: &userType,
}

if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ type CreateUserOverwriteOptions struct {
Theme *string
IsRestricted util.OptionalBool
IsActive util.OptionalBool
Type *UserType
}

// CreateUser creates record of a new user.
Expand Down Expand Up @@ -629,6 +630,9 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
if !overwrite.IsActive.IsNone() {
u.IsActive = overwrite.IsActive.IsTrue()
}
if overwrite.Type != nil {
u.Type = *overwrite.Type
}
}

// validate data
Expand Down

0 comments on commit 46b6867

Please sign in to comment.