From e3115cc019211fa2549f6943d379bf58fe7b7d7d Mon Sep 17 00:00:00 2001 From: guillep2k <18600385+guillep2k@users.noreply.github.com> Date: Sat, 24 Aug 2019 09:28:59 -0300 Subject: [PATCH] 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 --- custom/conf/app.ini.sample | 3 +++ .../doc/advanced/config-cheat-sheet.en-us.md | 1 + models/org.go | 6 ++++-- models/org_test.go | 19 ++++++++++++++----- modules/setting/service.go | 2 ++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index f2763e44df..a2842c56b4 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -405,6 +405,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true ; Private is only for member of the organization ; Public is for everyone DEFAULT_ORG_VISIBILITY = public +; Default value for DefaultOrgMemberVisible +; True will make the membership of the users visible when added to the organisation +DEFAULT_ORG_MEMBER_VISIBLE = false ; Default value for EnableDependencies ; Repositories will use dependencies by default depending on this setting DEFAULT_ENABLE_DEPENDENCIES = true diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 8b5235f716..996b0aa65f 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -246,6 +246,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button - `AUTO_WATCH_NEW_REPOS`: **true**: Enable this to let all organisation users watch new repos when they are created - `DEFAULT_ORG_VISIBILITY`: **public**: Set default visibility mode for organisations, either "public", "limited" or "private". +- `DEFAULT_ORG_MEMBER_VISIBLE`: **false** True will make the membership of the users visible when added to the organisation. ## Webhook (`webhook`) diff --git a/models/org.go b/models/org.go index 909657cffd..e00bef5798 100644 --- a/models/org.go +++ b/models/org.go @@ -12,6 +12,7 @@ import ( "strings" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "github.com/go-xorm/xorm" @@ -480,8 +481,9 @@ func AddOrgUser(orgID, uid int64) error { } ou := &OrgUser{ - UID: uid, - OrgID: orgID, + UID: uid, + OrgID: orgID, + IsPublic: setting.Service.DefaultOrgMemberVisible, } if _, err := sess.Insert(ou); err != nil { diff --git a/models/org_test.go b/models/org_test.go index a2ebf1f60b..6c1c4fee0e 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -7,6 +7,7 @@ package models import ( "testing" + "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" @@ -429,20 +430,28 @@ func TestChangeOrgUserStatus(t *testing.T) { func TestAddOrgUser(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) - testSuccess := func(orgID, userID int64) { + testSuccess := func(orgID, userID int64, isPublic bool) { org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User) expectedNumMembers := org.NumMembers if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) { expectedNumMembers++ } assert.NoError(t, AddOrgUser(orgID, userID)) - AssertExistsAndLoadBean(t, &OrgUser{OrgID: orgID, UID: userID}) + ou := &OrgUser{OrgID: orgID, UID: userID} + AssertExistsAndLoadBean(t, ou) + assert.Equal(t, ou.IsPublic, isPublic) org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User) assert.EqualValues(t, expectedNumMembers, org.NumMembers) } - testSuccess(3, 5) - testSuccess(3, 5) - testSuccess(6, 2) + + setting.Service.DefaultOrgMemberVisible = false + testSuccess(3, 5, false) + testSuccess(3, 5, false) + testSuccess(6, 2, false) + + setting.Service.DefaultOrgMemberVisible = true + testSuccess(6, 3, true) + CheckConsistencyFor(t, &User{}, &Team{}) } diff --git a/modules/setting/service.go b/modules/setting/service.go index 97babc5aaf..905b1326f7 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -42,6 +42,7 @@ var Service struct { NoReplyAddress string EnableUserHeatmap bool AutoWatchNewRepos bool + DefaultOrgMemberVisible bool // OpenID settings EnableOpenIDSignIn bool @@ -82,6 +83,7 @@ func newService() { Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true) Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes)) Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] + Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool() sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)