Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add configuration option to restrict users by default #16256

Merged
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ PATH =
;; Default value for AllowCreateOrganization
;; Every new user will have rights set to create organizations depending on this setting
;DEFAULT_ALLOW_CREATE_ORGANIZATION = true
;; Default value for IsRestricted
;; Every new user will have restricted permissions depending on this setting
;DEFAULT_USER_IS_RESTRICTED = true
6543 marked this conversation as resolved.
Show resolved Hide resolved
;;
;; Either "public", "limited" or "private", default is "public"
;; Limited is for signed user only
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ relation to port exhaustion.
- `HCAPTCHA_SITEKEY`: **""**: Sign up at https://www.hcaptcha.com/ to get a sitekey for hcaptcha.
- `DEFAULT_KEEP_EMAIL_PRIVATE`: **false**: By default set users to keep their email address private.
- `DEFAULT_ALLOW_CREATE_ORGANIZATION`: **true**: Allow new users to create organizations by default.
- `DEFAULT_USER_IS_RESTRICTED`: **false**: Give new users restricted permissions by default
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
- `ALLOW_CROSS_REPOSITORY_DEPENDENCIES` : **true** Enable this to allow dependencies on issues from any repository where the user is granted access.
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.
Expand Down
1 change: 1 addition & 0 deletions integrations/mssql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_USER_IS_RESTRICTED = false
6543 marked this conversation as resolved.
Show resolved Hide resolved
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

Expand Down
1 change: 1 addition & 0 deletions integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_USER_IS_RESTRICTED = false
6543 marked this conversation as resolved.
Show resolved Hide resolved
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

Expand Down
1 change: 1 addition & 0 deletions integrations/mysql8.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_USER_IS_RESTRICTED = false
6543 marked this conversation as resolved.
Show resolved Hide resolved
NO_REPLY_ADDRESS = noreply.example.org

[picture]
Expand Down
1 change: 1 addition & 0 deletions integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_USER_IS_RESTRICTED = false
6543 marked this conversation as resolved.
Show resolved Hide resolved
NO_REPLY_ADDRESS = noreply.example.org
ENABLE_NOTIFY_MAIL = true

Expand Down
19 changes: 19 additions & 0 deletions integrations/signup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ func TestSignup(t *testing.T) {
MakeRequest(t, req, http.StatusOK)
}

func TestSignupAsRestricted(t *testing.T) {
defer prepareTestEnv(t)()

setting.Service.EnableCaptcha = false
setting.Service.DefaultUserIsRestricted = true

req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
"user_name": "restrictedUser",
"email": "[email protected]",
"password": "examplePassword!1",
"retype": "examplePassword!1",
})
MakeRequest(t, req, http.StatusFound)

// should be able to view new user's page
req = NewRequest(t, "GET", "/restrictedUser")
MakeRequest(t, req, http.StatusOK)
6543 marked this conversation as resolved.
Show resolved Hide resolved
}

func TestSignupEmail(t *testing.T) {
defer prepareTestEnv(t)()

Expand Down
1 change: 1 addition & 0 deletions integrations/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
DEFAULT_USER_IS_RESTRICTED = false
6543 marked this conversation as resolved.
Show resolved Hide resolved
NO_REPLY_ADDRESS = noreply.example.org

[picture]
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var Service struct {
HcaptchaSitekey string
DefaultKeepEmailPrivate bool
DefaultAllowCreateOrganization bool
DefaultUserIsRestricted bool
EnableTimetracking bool
DefaultEnableTimetracking bool
DefaultEnableDependencies bool
Expand Down Expand Up @@ -105,6 +106,7 @@ func newService() {
Service.HcaptchaSitekey = sec.Key("HCAPTCHA_SITEKEY").MustString("")
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
Service.DefaultUserIsRestricted = sec.Key("DEFAULT_USER_IS_RESTRICTED").MustBool(false)
Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
if Service.EnableTimetracking {
Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true)
Expand Down
9 changes: 5 additions & 4 deletions routers/web/user/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,11 @@ func SignUpPost(ctx *context.Context) {
}

u := &models.User{
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
IsRestricted: setting.Service.DefaultUserIsRestricted,
}

if !createAndHandleCreatedUser(ctx, tplSignUp, form, u, nil, false) {
Expand Down