Skip to content

Commit 44d63a7

Browse files
committed
Add a option --bot to admin user create
Partially solve #13044
1 parent dcb648e commit 44d63a7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cmd/admin_user_create.go

+12
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ var microcmdUserCreate = &cli.Command{
6262
Name: "restricted",
6363
Usage: "Make a restricted user account",
6464
},
65+
&cli.BoolFlag{
66+
Name: "bot",
67+
Usage: "Make a bot user account",
68+
},
6569
},
6670
}
6771

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

136+
userType := user_model.UserTypeIndividual
137+
if c.IsSet("bot") {
138+
if c.Bool("bot") {
139+
userType = user_model.UserTypeBot
140+
}
141+
}
142+
132143
// default user visibility in app.ini
133144
visibility := setting.Service.DefaultUserVisibilityMode
134145

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

149161
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {

models/user/user.go

+4
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ type CreateUserOverwriteOptions struct {
579579
Theme *string
580580
IsRestricted util.OptionalBool
581581
IsActive util.OptionalBool
582+
Type *UserType
582583
}
583584

584585
// CreateUser creates record of a new user.
@@ -629,6 +630,9 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
629630
if !overwrite.IsActive.IsNone() {
630631
u.IsActive = overwrite.IsActive.IsTrue()
631632
}
633+
if overwrite.Type != nil {
634+
u.Type = *overwrite.Type
635+
}
632636
}
633637

634638
// validate data

0 commit comments

Comments
 (0)