diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2019-08-24 09:28:59 -0300 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-08-24 15:28:59 +0300 |
commit | e3115cc019211fa2549f6943d379bf58fe7b7d7d (patch) | |
tree | 050115e3cdf4e0334d081459312f711e55f4ea86 /models | |
parent | f83db078f0603c775cd1b1bb016f996b65a04835 (diff) | |
download | gitea-e3115cc019211fa2549f6943d379bf58fe7b7d7d.tar.gz gitea-e3115cc019211fa2549f6943d379bf58fe7b7d7d.zip |
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
Diffstat (limited to 'models')
-rw-r--r-- | models/org.go | 6 | ||||
-rw-r--r-- | models/org_test.go | 19 |
2 files changed, 18 insertions, 7 deletions
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{}) } |