diff options
author | Rémy Boulanouar <rboulanouar@gmail.com> | 2019-02-18 17:00:27 +0100 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-02-18 18:00:27 +0200 |
commit | 64ce159a6eacc81962d07a8f5ef7f69c17365363 (patch) | |
tree | d6b94d035de14df8b1a773d97ab35937cce1d00a /modules | |
parent | ae3a913122d3430ccf14da22f09daf6f636a00f8 (diff) | |
download | gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.tar.gz gitea-64ce159a6eacc81962d07a8f5ef7f69c17365363.zip |
Allow to set organization visibility (public, internal, private) (#1763)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/org.go | 6 | ||||
-rw-r--r-- | modules/setting/service.go | 10 | ||||
-rw-r--r-- | modules/structs/org_type.go | 49 |
3 files changed, 63 insertions, 2 deletions
diff --git a/modules/auth/org.go b/modules/auth/org.go index d6c26b6336..e4921c2267 100644 --- a/modules/auth/org.go +++ b/modules/auth/org.go @@ -1,4 +1,5 @@ // Copyright 2014 The Gogs Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -6,6 +7,7 @@ package auth import ( "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/structs" "github.com/go-macaron/binding" "gopkg.in/macaron.v1" @@ -20,7 +22,8 @@ import ( // CreateOrgForm form for creating organization type CreateOrgForm struct { - OrgName string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"` + OrgName string `binding:"Required;AlphaDashDot;MaxSize(35)" locale:"org.org_name_holder"` + Visibility structs.VisibleType } // Validate validates the fields @@ -35,6 +38,7 @@ type UpdateOrgSettingForm struct { Description string `binding:"MaxSize(255)"` Website string `binding:"ValidUrl;MaxSize(255)"` Location string `binding:"MaxSize(50)"` + Visibility structs.VisibleType MaxRepoCreation int } diff --git a/modules/setting/service.go b/modules/setting/service.go index 4b9ddb055b..08bfb6c414 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -4,10 +4,16 @@ package setting -import "regexp" +import ( + "regexp" + + "code.gitea.io/gitea/modules/structs" +) // Service settings var Service struct { + DefaultOrgVisibility string + DefaultOrgVisibilityMode structs.VisibleType ActiveCodeLives int ResetPwdCodeLives int RegisterEmailConfirm bool @@ -68,6 +74,8 @@ func newService() { Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") Service.EnableUserHeatmap = sec.Key("ENABLE_USER_HEATMAP").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.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility] sec = Cfg.Section("openid") Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock) diff --git a/modules/structs/org_type.go b/modules/structs/org_type.go new file mode 100644 index 0000000000..86dc5c81cd --- /dev/null +++ b/modules/structs/org_type.go @@ -0,0 +1,49 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package structs + +// VisibleType defines the visibility (Organization only) +type VisibleType int + +const ( + // VisibleTypePublic Visible for everyone + VisibleTypePublic VisibleType = iota + + // VisibleTypeLimited Visible for every connected user + VisibleTypeLimited + + // VisibleTypePrivate Visible only for organization's members + VisibleTypePrivate +) + +// VisibilityModes is a map of org Visibility types +var VisibilityModes = map[string]VisibleType{ + "public": VisibleTypePublic, + "limited": VisibleTypeLimited, + "private": VisibleTypePrivate, +} + +// IsPublic returns true if VisibleType is public +func (vt VisibleType) IsPublic() bool { + return vt == VisibleTypePublic +} + +// IsLimited returns true if VisibleType is limited +func (vt VisibleType) IsLimited() bool { + return vt == VisibleTypeLimited +} + +// IsPrivate returns true if VisibleType is private +func (vt VisibleType) IsPrivate() bool { + return vt == VisibleTypePrivate +} + +// ExtractKeysFromMapString provides a slice of keys from map +func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { + for k := range in { + keys = append(keys, k) + } + return +} |