Skip to content

Commit 6dc2f40

Browse files
adelowotechknowlogick
authored andcommitted
Don't discard the value of DISABLE_REGULAR_ORG_CREATION (#5886)
* Consider the configuration value of DISABLE_REGULAR_ORG_CREATION when creating a user
1 parent 7933a95 commit 6dc2f40

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

models/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ func CreateUser(u *User) (err error) {
814814
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
815815
u.MaxRepoCreation = -1
816816
u.Theme = setting.UI.DefaultTheme
817+
u.AllowCreateOrganization = !setting.Admin.DisableRegularOrgCreation
817818

818819
if _, err = sess.Insert(u); err != nil {
819820
return err

models/user_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,47 @@ func TestDisplayName(t *testing.T) {
213213
assert.NotEqual(t, len(strings.TrimSpace(displayName)), 0)
214214
}
215215
}
216+
217+
func TestCreateUser(t *testing.T) {
218+
user := &User{
219+
Name: "GiteaBot",
220+
221+
Passwd: ";p['////..-++']",
222+
IsAdmin: false,
223+
Theme: setting.UI.DefaultTheme,
224+
MustChangePassword: false,
225+
}
226+
227+
assert.NoError(t, CreateUser(user))
228+
229+
assert.NoError(t, DeleteUser(user))
230+
}
231+
232+
func TestCreateUser_Issue5882(t *testing.T) {
233+
234+
// Init settings
235+
_ = setting.Admin
236+
237+
passwd := ".//.;1;;//.,-=_"
238+
239+
tt := []struct {
240+
user *User
241+
disableOrgCreation bool
242+
}{
243+
{&User{Name: "GiteaBot", Email: "[email protected]", Passwd: passwd, MustChangePassword: false}, false},
244+
{&User{Name: "GiteaBot2", Email: "[email protected]", Passwd: passwd, MustChangePassword: false}, true},
245+
}
246+
247+
for _, v := range tt {
248+
setting.Admin.DisableRegularOrgCreation = v.disableOrgCreation
249+
250+
assert.NoError(t, CreateUser(v.user))
251+
252+
u, err := GetUserByEmail(v.user.Email)
253+
assert.NoError(t, err)
254+
255+
assert.Equal(t, !u.AllowCreateOrganization, v.disableOrgCreation)
256+
257+
assert.NoError(t, DeleteUser(v.user))
258+
}
259+
}

0 commit comments

Comments
 (0)