summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2019-01-30 18:04:14 +0100
committertechknowlogick <matti@mdranta.net>2019-01-30 12:04:14 -0500
commit6dc2f401c9d4d07ca672d4f3a304799e70364f1b (patch)
tree8e353d2d1caf2a1b3fcd7d94c92575206b34f65b
parent7933a950d065d0b4399f2efc40bff75d2a7ed927 (diff)
downloadgitea-6dc2f401c9d4d07ca672d4f3a304799e70364f1b.tar.gz
gitea-6dc2f401c9d4d07ca672d4f3a304799e70364f1b.zip
Don't discard the value of DISABLE_REGULAR_ORG_CREATION (#5886)
* Consider the configuration value of DISABLE_REGULAR_ORG_CREATION when creating a user
-rw-r--r--models/user.go1
-rw-r--r--models/user_test.go44
2 files changed, 45 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go
index 4ab78ec04e..5eb9db1e5e 100644
--- a/models/user.go
+++ b/models/user.go
@@ -814,6 +814,7 @@ func CreateUser(u *User) (err error) {
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
u.MaxRepoCreation = -1
u.Theme = setting.UI.DefaultTheme
+ u.AllowCreateOrganization = !setting.Admin.DisableRegularOrgCreation
if _, err = sess.Insert(u); err != nil {
return err
diff --git a/models/user_test.go b/models/user_test.go
index 9d011f32a0..35efc3959a 100644
--- a/models/user_test.go
+++ b/models/user_test.go
@@ -213,3 +213,47 @@ func TestDisplayName(t *testing.T) {
assert.NotEqual(t, len(strings.TrimSpace(displayName)), 0)
}
}
+
+func TestCreateUser(t *testing.T) {
+ user := &User{
+ Name: "GiteaBot",
+ Email: "GiteaBot@gitea.io",
+ Passwd: ";p['////..-++']",
+ IsAdmin: false,
+ Theme: setting.UI.DefaultTheme,
+ MustChangePassword: false,
+ }
+
+ assert.NoError(t, CreateUser(user))
+
+ assert.NoError(t, DeleteUser(user))
+}
+
+func TestCreateUser_Issue5882(t *testing.T) {
+
+ // Init settings
+ _ = setting.Admin
+
+ passwd := ".//.;1;;//.,-=_"
+
+ tt := []struct {
+ user *User
+ disableOrgCreation bool
+ }{
+ {&User{Name: "GiteaBot", Email: "GiteaBot@gitea.io", Passwd: passwd, MustChangePassword: false}, false},
+ {&User{Name: "GiteaBot2", Email: "GiteaBot2@gitea.io", Passwd: passwd, MustChangePassword: false}, true},
+ }
+
+ for _, v := range tt {
+ setting.Admin.DisableRegularOrgCreation = v.disableOrgCreation
+
+ assert.NoError(t, CreateUser(v.user))
+
+ u, err := GetUserByEmail(v.user.Email)
+ assert.NoError(t, err)
+
+ assert.Equal(t, !u.AllowCreateOrganization, v.disableOrgCreation)
+
+ assert.NoError(t, DeleteUser(v.user))
+ }
+}