Don't discard the value of DISABLE_REGULAR_ORG_CREATION (#5886)

* Consider the configuration value of DISABLE_REGULAR_ORG_CREATION when
creating a user
release/v1.8
Lanre Adelowo 5 years ago committed by techknowlogick
parent 7933a950d0
commit 6dc2f401c9

@ -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

@ -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))
}
}

Loading…
Cancel
Save