Skip to content

Commit 6ea9563

Browse files
committed
add configuration option to restrict users by default
1 parent 1a1ce9b commit 6ea9563

File tree

10 files changed

+34
-0
lines changed

10 files changed

+34
-0
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ PATH =
649649
;; Default value for AllowCreateOrganization
650650
;; Every new user will have rights set to create organizations depending on this setting
651651
;DEFAULT_ALLOW_CREATE_ORGANIZATION = true
652+
;; Default value for IsRestricted
653+
;; Every new user will have restricted permissions depending on this setting
654+
;DEFAULT_USER_IS_RESTRICTED = true
652655
;;
653656
;; Either "public", "limited" or "private", default is "public"
654657
;; Limited is for signed user only

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ relation to port exhaustion.
499499
- `HCAPTCHA_SITEKEY`: **""**: Sign up at https://www.hcaptcha.com/ to get a sitekey for hcaptcha.
500500
- `DEFAULT_KEEP_EMAIL_PRIVATE`: **false**: By default set users to keep their email address private.
501501
- `DEFAULT_ALLOW_CREATE_ORGANIZATION`: **true**: Allow new users to create organizations by default.
502+
- `DEFAULT_USER_IS_RESTRICTED`: **false**: Give new users restricted permissions by default
502503
- `DEFAULT_ENABLE_DEPENDENCIES`: **true**: Enable this to have dependencies enabled by default.
503504
- `ALLOW_CROSS_REPOSITORY_DEPENDENCIES` : **true** Enable this to allow dependencies on issues from any repository where the user is granted access.
504505
- `ENABLE_USER_HEATMAP`: **true**: Enable this to display the heatmap on users profiles.

integrations/mssql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ENABLE_CAPTCHA = false
6565
REQUIRE_SIGNIN_VIEW = false
6666
DEFAULT_KEEP_EMAIL_PRIVATE = false
6767
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
68+
DEFAULT_USER_IS_RESTRICTED = false
6869
NO_REPLY_ADDRESS = noreply.example.org
6970
ENABLE_NOTIFY_MAIL = true
7071

integrations/mysql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ ENABLE_CAPTCHA = false
8585
REQUIRE_SIGNIN_VIEW = false
8686
DEFAULT_KEEP_EMAIL_PRIVATE = false
8787
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
88+
DEFAULT_USER_IS_RESTRICTED = false
8889
NO_REPLY_ADDRESS = noreply.example.org
8990
ENABLE_NOTIFY_MAIL = true
9091

integrations/mysql8.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ENABLE_CAPTCHA = false
6363
REQUIRE_SIGNIN_VIEW = false
6464
DEFAULT_KEEP_EMAIL_PRIVATE = false
6565
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
66+
DEFAULT_USER_IS_RESTRICTED = false
6667
NO_REPLY_ADDRESS = noreply.example.org
6768

6869
[picture]

integrations/pgsql.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ ENABLE_CAPTCHA = false
6666
REQUIRE_SIGNIN_VIEW = false
6767
DEFAULT_KEEP_EMAIL_PRIVATE = false
6868
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
69+
DEFAULT_USER_IS_RESTRICTED = false
6970
NO_REPLY_ADDRESS = noreply.example.org
7071
ENABLE_NOTIFY_MAIL = true
7172

integrations/sqlite.ini.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ENABLE_CAPTCHA = false
6262
REQUIRE_SIGNIN_VIEW = false
6363
DEFAULT_KEEP_EMAIL_PRIVATE = false
6464
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
65+
DEFAULT_USER_IS_RESTRICTED = false
6566
NO_REPLY_ADDRESS = noreply.example.org
6667

6768
[picture]

models/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ func CreateUser(u *User) (err error) {
843843
}
844844
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation
845845
u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
846+
u.IsRestricted = setting.Service.DefaultUserIsRestricted
846847
u.MaxRepoCreation = -1
847848
u.Theme = setting.UI.DefaultTheme
848849

models/user_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,28 @@ func TestCreateUser(t *testing.T) {
322322
assert.NoError(t, DeleteUser(user))
323323
}
324324

325+
func TestCreateUserWithRestrictedUserByDefault(t *testing.T) {
326+
user := &User{
327+
Name: "GiteaBot",
328+
Email: "GiteaBot@gitea.io",
329+
Passwd: ";p['////..-++']",
330+
IsAdmin: false,
331+
Theme: setting.UI.DefaultTheme,
332+
MustChangePassword: false,
333+
}
334+
335+
setting.Service.DefaultUserIsRestricted = true
336+
337+
assert.NoError(t, CreateUser(user))
338+
339+
savedUser, err := GetUserByEmail(user.Email)
340+
assert.NoError(t, err)
341+
342+
assert.Equal(t, savedUser.IsRestricted, true)
343+
344+
assert.NoError(t, DeleteUser(savedUser))
345+
}
346+
325347
func TestCreateUserInvalidEmail(t *testing.T) {
326348
user := &User{
327349
Name: "GiteaBot",

modules/setting/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var Service struct {
4444
HcaptchaSitekey string
4545
DefaultKeepEmailPrivate bool
4646
DefaultAllowCreateOrganization bool
47+
DefaultUserIsRestricted bool
4748
EnableTimetracking bool
4849
DefaultEnableTimetracking bool
4950
DefaultEnableDependencies bool
@@ -105,6 +106,7 @@ func newService() {
105106
Service.HcaptchaSitekey = sec.Key("HCAPTCHA_SITEKEY").MustString("")
106107
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
107108
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
109+
Service.DefaultUserIsRestricted = sec.Key("DEFAULT_USER_IS_RESTRICTED").MustBool(false)
108110
Service.EnableTimetracking = sec.Key("ENABLE_TIMETRACKING").MustBool(true)
109111
if Service.EnableTimetracking {
110112
Service.DefaultEnableTimetracking = sec.Key("DEFAULT_ENABLE_TIMETRACKING").MustBool(true)

0 commit comments

Comments
 (0)