summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2022-04-29 21:38:11 +0200
committerGitHub <noreply@github.com>2022-04-29 15:38:11 -0400
commit5aebc4f000354d9fa448033445c6f313f4c6ab08 (patch)
treec081c5eff890a454b4c4c3a6aa9d1329eba09052 /cmd
parent219c87e7d889f5c62097968e5ec8ad04f244cd3c (diff)
downloadgitea-5aebc4f000354d9fa448033445c6f313f4c6ab08.tar.gz
gitea-5aebc4f000354d9fa448033445c6f313f4c6ab08.zip
Respect DefaultUserIsRestricted system default when creating new user (#19310)
* Apply DefaultUserIsRestricted in CreateUser * Enforce system defaults in CreateUser Allow for overwrites with CreateUserOverwriteOptions * Fix compilation errors * Add "restricted" option to create user command * Add "restricted" option to create user admin api * Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed * Revert "Respect default setting.Service.RegisterEmailConfirm and setting.Service.RegisterManualConfirm where needed" This reverts commit ee95d3e8dc9e9fff4fa66a5111e4d3930280e033.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index e4a254c613..36cac50a47 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -25,6 +25,7 @@ import (
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
+ "code.gitea.io/gitea/modules/util"
auth_service "code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/auth/source/oauth2"
"code.gitea.io/gitea/services/auth/source/smtp"
@@ -114,6 +115,10 @@ var (
Name: "access-token",
Usage: "Generate access token for the user",
},
+ cli.BoolFlag{
+ Name: "restricted",
+ Usage: "Make a restricted user account",
+ },
},
}
@@ -559,17 +564,26 @@ func runCreateUser(c *cli.Context) error {
changePassword = c.Bool("must-change-password")
}
+ restricted := util.OptionalBoolNone
+
+ if c.IsSet("restricted") {
+ restricted = util.OptionalBoolOf(c.Bool("restricted"))
+ }
+
u := &user_model.User{
Name: username,
Email: c.String("email"),
Passwd: password,
- IsActive: true,
IsAdmin: c.Bool("admin"),
MustChangePassword: changePassword,
- Theme: setting.UI.DefaultTheme,
}
- if err := user_model.CreateUser(u); err != nil {
+ overwriteDefault := &user_model.CreateUserOverwriteOptions{
+ IsActive: util.OptionalBoolTrue,
+ IsRestricted: restricted,
+ }
+
+ if err := user_model.CreateUser(u, overwriteDefault); err != nil {
return fmt.Errorf("CreateUser: %v", err)
}