summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-06-27 20:47:35 +0200
committerGitHub <noreply@github.com>2021-06-27 19:47:35 +0100
commit0b27b93728fd3cf2ecc82ac6a2b5859270543ef2 (patch)
treeadbbc5eaec25e5e2c88068d45e3fa75435431dfe /modules
parent2a98ec1c3cd2f8396f3b5148fc8c796802f9c236 (diff)
downloadgitea-0b27b93728fd3cf2ecc82ac6a2b5859270543ef2.tar.gz
gitea-0b27b93728fd3cf2ecc82ac6a2b5859270543ef2.zip
Make allowed Visiblity modes configurable for Users (#16271)
Now that #16069 is merged, some sites may wish to enforce that users are all public, limited or private, and/or disallow users from becoming private. This PR adds functionality and settings to constrain a user's ability to change their visibility. Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r--modules/setting/service.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/modules/setting/service.go b/modules/setting/service.go
index 3f689212f3..dbabfb8400 100644
--- a/modules/setting/service.go
+++ b/modules/setting/service.go
@@ -14,9 +14,11 @@ import (
)
// Service settings
-var Service struct {
+var Service = struct {
DefaultUserVisibility string
DefaultUserVisibilityMode structs.VisibleType
+ AllowedUserVisibilityModes []string
+ AllowedUserVisibilityModesSlice AllowedVisibility `ini:"-"`
DefaultOrgVisibility string
DefaultOrgVisibilityMode structs.VisibleType
ActiveCodeLives int
@@ -71,6 +73,29 @@ var Service struct {
RequireSigninView bool `ini:"REQUIRE_SIGNIN_VIEW"`
DisableUsersPage bool `ini:"DISABLE_USERS_PAGE"`
} `ini:"service.explore"`
+}{
+ AllowedUserVisibilityModesSlice: []bool{true, true, true},
+}
+
+// AllowedVisibility store in a 3 item bool array what is allowed
+type AllowedVisibility []bool
+
+// IsAllowedVisibility check if a AllowedVisibility allow a specific VisibleType
+func (a AllowedVisibility) IsAllowedVisibility(t structs.VisibleType) bool {
+ if int(t) >= len(a) {
+ return false
+ }
+ return a[t]
+}
+
+// ToVisibleTypeSlice convert a AllowedVisibility into a VisibleType slice
+func (a AllowedVisibility) ToVisibleTypeSlice() (result []structs.VisibleType) {
+ for i, v := range a {
+ if v {
+ result = append(result, structs.VisibleType(i))
+ }
+ }
+ return
}
func newService() {
@@ -122,6 +147,13 @@ func newService() {
Service.AutoWatchOnChanges = sec.Key("AUTO_WATCH_ON_CHANGES").MustBool(false)
Service.DefaultUserVisibility = sec.Key("DEFAULT_USER_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
Service.DefaultUserVisibilityMode = structs.VisibilityModes[Service.DefaultUserVisibility]
+ Service.AllowedUserVisibilityModes = sec.Key("ALLOWED_USER_VISIBILITY_MODES").Strings(",")
+ if len(Service.AllowedUserVisibilityModes) != 0 {
+ Service.AllowedUserVisibilityModesSlice = []bool{false, false, false}
+ for _, sMode := range Service.AllowedUserVisibilityModes {
+ Service.AllowedUserVisibilityModesSlice[structs.VisibilityModes[sMode]] = 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()