Skip to content

Commit e3115cc

Browse files
guillep2klafriks
authored andcommitted
Add support for DEFAULT_ORG_MEMBER_VISIBLE (#7669)
* Add support for DEFAULT_ORG_MEMBER_VISIBLE * Correct formatting * Improved description in cheat sheet. * Add test for DefaultOrgMemberVisible * Remove dead code
1 parent f83db07 commit e3115cc

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

custom/conf/app.ini.sample

+3
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
405405
; Private is only for member of the organization
406406
; Public is for everyone
407407
DEFAULT_ORG_VISIBILITY = public
408+
; Default value for DefaultOrgMemberVisible
409+
; True will make the membership of the users visible when added to the organisation
410+
DEFAULT_ORG_MEMBER_VISIBLE = false
408411
; Default value for EnableDependencies
409412
; Repositories will use dependencies by default depending on this setting
410413
DEFAULT_ENABLE_DEPENDENCIES = true

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

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
246246
- `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button
247247
- `AUTO_WATCH_NEW_REPOS`: **true**: Enable this to let all organisation users watch new repos when they are created
248248
- `DEFAULT_ORG_VISIBILITY`: **public**: Set default visibility mode for organisations, either "public", "limited" or "private".
249+
- `DEFAULT_ORG_MEMBER_VISIBLE`: **false** True will make the membership of the users visible when added to the organisation.
249250

250251
## Webhook (`webhook`)
251252

models/org.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/setting"
1516
"code.gitea.io/gitea/modules/structs"
1617

1718
"github.com/go-xorm/xorm"
@@ -480,8 +481,9 @@ func AddOrgUser(orgID, uid int64) error {
480481
}
481482

482483
ou := &OrgUser{
483-
UID: uid,
484-
OrgID: orgID,
484+
UID: uid,
485+
OrgID: orgID,
486+
IsPublic: setting.Service.DefaultOrgMemberVisible,
485487
}
486488

487489
if _, err := sess.Insert(ou); err != nil {

models/org_test.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package models
77
import (
88
"testing"
99

10+
"code.gitea.io/gitea/modules/setting"
1011
"code.gitea.io/gitea/modules/structs"
1112

1213
"github.com/stretchr/testify/assert"
@@ -429,20 +430,28 @@ func TestChangeOrgUserStatus(t *testing.T) {
429430

430431
func TestAddOrgUser(t *testing.T) {
431432
assert.NoError(t, PrepareTestDatabase())
432-
testSuccess := func(orgID, userID int64) {
433+
testSuccess := func(orgID, userID int64, isPublic bool) {
433434
org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
434435
expectedNumMembers := org.NumMembers
435436
if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
436437
expectedNumMembers++
437438
}
438439
assert.NoError(t, AddOrgUser(orgID, userID))
439-
AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID})
440+
ou := &OrgUser{OrgID: orgID, UID: userID}
441+
AssertExistsAndLoadBean(t, ou)
442+
assert.Equal(t, ou.IsPublic, isPublic)
440443
org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
441444
assert.EqualValues(t, expectedNumMembers, org.NumMembers)
442445
}
443-
testSuccess(3, 5)
444-
testSuccess(3, 5)
445-
testSuccess(6, 2)
446+
447+
setting.Service.DefaultOrgMemberVisible = false
448+
testSuccess(3, 5, false)
449+
testSuccess(3, 5, false)
450+
testSuccess(6, 2, false)
451+
452+
setting.Service.DefaultOrgMemberVisible = true
453+
testSuccess(6, 3, true)
454+
446455
CheckConsistencyFor(t, &User{}, &Team{})
447456
}
448457

modules/setting/service.go

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var Service struct {
4242
NoReplyAddress string
4343
EnableUserHeatmap bool
4444
AutoWatchNewRepos bool
45+
DefaultOrgMemberVisible bool
4546

4647
// OpenID settings
4748
EnableOpenIDSignIn bool
@@ -82,6 +83,7 @@ func newService() {
8283
Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
8384
Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
8485
Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]
86+
Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
8587

8688
sec = Cfg.Section("openid")
8789
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)

0 commit comments

Comments
 (0)