aboutsummaryrefslogtreecommitdiffstats
path: root/models
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 /models
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 'models')
-rw-r--r--models/user/user.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/models/user/user.go b/models/user/user.go
index c848895239..5b556c9884 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -621,7 +621,14 @@ func IsUsableUsername(name string) error {
// CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
type CreateUserOverwriteOptions struct {
- Visibility structs.VisibleType
+ KeepEmailPrivate util.OptionalBool
+ Visibility *structs.VisibleType
+ AllowCreateOrganization util.OptionalBool
+ EmailNotificationsPreference *string
+ MaxRepoCreation *int
+ Theme *string
+ IsRestricted util.OptionalBool
+ IsActive util.OptionalBool
}
// CreateUser creates record of a new user.
@@ -637,10 +644,36 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
u.MaxRepoCreation = -1
u.Theme = setting.UI.DefaultTheme
+ u.IsRestricted = setting.Service.DefaultUserIsRestricted
+ u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm)
// overwrite defaults if set
if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
- u.Visibility = overwriteDefault[0].Visibility
+ overwrite := overwriteDefault[0]
+ if !overwrite.KeepEmailPrivate.IsNone() {
+ u.KeepEmailPrivate = overwrite.KeepEmailPrivate.IsTrue()
+ }
+ if overwrite.Visibility != nil {
+ u.Visibility = *overwrite.Visibility
+ }
+ if !overwrite.AllowCreateOrganization.IsNone() {
+ u.AllowCreateOrganization = overwrite.AllowCreateOrganization.IsTrue()
+ }
+ if overwrite.EmailNotificationsPreference != nil {
+ u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference
+ }
+ if overwrite.MaxRepoCreation != nil {
+ u.MaxRepoCreation = *overwrite.MaxRepoCreation
+ }
+ if overwrite.Theme != nil {
+ u.Theme = *overwrite.Theme
+ }
+ if !overwrite.IsRestricted.IsNone() {
+ u.IsRestricted = overwrite.IsRestricted.IsTrue()
+ }
+ if !overwrite.IsActive.IsNone() {
+ u.IsActive = overwrite.IsActive.IsTrue()
+ }
}
// validate data