From daef2a1f8789798796198d0d4675f9b3f01d7b13 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Mon, 29 Jul 2019 22:51:11 -0300 Subject: [PATCH 1/5] Add support for DEFAULT_ORG_MEMBER_VISIBLE --- custom/conf/app.ini.sample | 3 +++ docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + models/org.go | 2 ++ modules/setting/service.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 991a2a3e6b4b1..18d8537604b51 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -401,6 +401,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 6f3bc465a659a..78162e8f3cba8 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -243,6 +243,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** Set default visibility for organisation members when added. ## Webhook (`webhook`) diff --git a/models/org.go b/models/org.go index d86109de57e10..1a41cc4af4be3 100644 --- a/models/org.go +++ b/models/org.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/setting" "github.com/Unknwon/com" "github.com/go-xorm/xorm" @@ -481,6 +482,7 @@ func AddOrgUser(orgID, uid int64) error { ou := &OrgUser{ UID: uid, OrgID: orgID, + IsPublic: setting.Service.DefaultOrgMemberVisible, } if _, err := sess.Insert(ou); err != nil { diff --git a/modules/setting/service.go b/modules/setting/service.go index 97babc5aaf215..1c3160bc494d1 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) From 9d3f076ac97b0d4d1cdd4663cb818a1aa108cca6 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Tue, 30 Jul 2019 00:30:17 -0300 Subject: [PATCH 2/5] Correct formatting --- models/org.go | 6 +++--- modules/setting/service.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/org.go b/models/org.go index 1a41cc4af4be3..8a2174678e32e 100644 --- a/models/org.go +++ b/models/org.go @@ -12,8 +12,8 @@ import ( "strings" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/structs" "github.com/Unknwon/com" "github.com/go-xorm/xorm" @@ -480,8 +480,8 @@ func AddOrgUser(orgID, uid int64) error { } ou := &OrgUser{ - UID: uid, - OrgID: orgID, + UID: uid, + OrgID: orgID, IsPublic: setting.Service.DefaultOrgMemberVisible, } diff --git a/modules/setting/service.go b/modules/setting/service.go index 1c3160bc494d1..905b1326f78d6 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -42,7 +42,7 @@ var Service struct { NoReplyAddress string EnableUserHeatmap bool AutoWatchNewRepos bool - DefaultOrgMemberVisible bool + DefaultOrgMemberVisible bool // OpenID settings EnableOpenIDSignIn bool From c7e9d696b563a1b37673958b8304c1cf41cd44d3 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Wed, 31 Jul 2019 10:48:21 -0300 Subject: [PATCH 3/5] Improved description in cheat sheet. --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 78162e8f3cba8..57f078b692750 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -243,7 +243,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** Set default visibility for organisation members when added. +- `DEFAULT_ORG_MEMBER_VISIBLE`: **false** True will make the membership of the users visible when added to the organisation. ## Webhook (`webhook`) From 9a26cbb5ab5fc05ac1f83cdf12754dcb440d8b8a Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Fri, 23 Aug 2019 22:50:37 -0300 Subject: [PATCH 4/5] Add test for DefaultOrgMemberVisible --- models/org_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/models/org_test.go b/models/org_test.go index a2ebf1f60bce8..f66aa7debeb8c 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,23 +430,34 @@ 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{}) } +func TestDefaultOrgMemberVisible(t *testing.T) { +} + func TestRemoveOrgUser(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) testSuccess := func(orgID, userID int64) { From 592653a041c603b194705a33665a0259f73234b7 Mon Sep 17 00:00:00 2001 From: Guillermo Prandi Date: Fri, 23 Aug 2019 23:28:21 -0300 Subject: [PATCH 5/5] Remove dead code --- models/org_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/models/org_test.go b/models/org_test.go index f66aa7debeb8c..6c1c4fee0e693 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -455,9 +455,6 @@ func TestAddOrgUser(t *testing.T) { CheckConsistencyFor(t, &User{}, &Team{}) } -func TestDefaultOrgMemberVisible(t *testing.T) { -} - func TestRemoveOrgUser(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) testSuccess := func(orgID, userID int64) {