Skip to content

Don't discard the value of DISABLE_REGULAR_ORG_CREATION #5886

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

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions models/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
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: "[email protected]", Passwd: passwd, MustChangePassword: false}, false},
{&User{Name: "GiteaBot2", Email: "[email protected]", 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))
}
}