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
This commit is contained in:
guillep2k 2019-08-24 09:28:59 -03:00 committed by Lauris BH
parent f83db078f0
commit e3115cc019
5 changed files with 24 additions and 7 deletions

View File

@ -405,6 +405,9 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Private is only for member of the organization ; Private is only for member of the organization
; Public is for everyone ; Public is for everyone
DEFAULT_ORG_VISIBILITY = public 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 ; Default value for EnableDependencies
; Repositories will use dependencies by default depending on this setting ; Repositories will use dependencies by default depending on this setting
DEFAULT_ENABLE_DEPENDENCIES = true DEFAULT_ENABLE_DEPENDENCIES = true

View File

@ -246,6 +246,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `SHOW_REGISTRATION_BUTTON`: **! DISABLE\_REGISTRATION**: Show Registration Button - `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 - `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_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`) ## Webhook (`webhook`)

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
@ -480,8 +481,9 @@ func AddOrgUser(orgID, uid int64) error {
} }
ou := &OrgUser{ ou := &OrgUser{
UID: uid, UID: uid,
OrgID: orgID, OrgID: orgID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
} }
if _, err := sess.Insert(ou); err != nil { if _, err := sess.Insert(ou); err != nil {

View File

@ -7,6 +7,7 @@ package models
import ( import (
"testing" "testing"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -429,20 +430,28 @@ func TestChangeOrgUserStatus(t *testing.T) {
func TestAddOrgUser(t *testing.T) { func TestAddOrgUser(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())
testSuccess := func(orgID, userID int64) { testSuccess := func(orgID, userID int64, isPublic bool) {
org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User) org := AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
expectedNumMembers := org.NumMembers expectedNumMembers := org.NumMembers
if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) { if !BeanExists(t, &OrgUser{OrgID: orgID, UID: userID}) {
expectedNumMembers++ expectedNumMembers++
} }
assert.NoError(t, AddOrgUser(orgID, userID)) 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) org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User)
assert.EqualValues(t, expectedNumMembers, org.NumMembers) assert.EqualValues(t, expectedNumMembers, org.NumMembers)
} }
testSuccess(3, 5)
testSuccess(3, 5) setting.Service.DefaultOrgMemberVisible = false
testSuccess(6, 2) testSuccess(3, 5, false)
testSuccess(3, 5, false)
testSuccess(6, 2, false)
setting.Service.DefaultOrgMemberVisible = true
testSuccess(6, 3, true)
CheckConsistencyFor(t, &User{}, &Team{}) CheckConsistencyFor(t, &User{}, &Team{})
} }

View File

@ -42,6 +42,7 @@ var Service struct {
NoReplyAddress string NoReplyAddress string
EnableUserHeatmap bool EnableUserHeatmap bool
AutoWatchNewRepos bool AutoWatchNewRepos bool
DefaultOrgMemberVisible bool
// OpenID settings // OpenID settings
EnableOpenIDSignIn bool EnableOpenIDSignIn bool
@ -82,6 +83,7 @@ func newService() {
Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true) Service.AutoWatchNewRepos = sec.Key("AUTO_WATCH_NEW_REPOS").MustBool(true)
Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes)) Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]
Service.DefaultOrgMemberVisible = sec.Key("DEFAULT_ORG_MEMBER_VISIBLE").MustBool()
sec = Cfg.Section("openid") sec = Cfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock) Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)