Implement global configuration for new organizations

This commit is contained in:
Remy Boulanouar 2017-05-22 12:00:08 +02:00
parent 7bdc6e8bbc
commit fb0c45abb1
5 changed files with 22 additions and 1 deletions

View File

@ -245,6 +245,11 @@ DEFAULT_KEEP_EMAIL_PRIVATE = false
; Default value for AllowCreateOrganization
; New user will have rights set to create organizations depending on this setting
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Either "public", "limited" or "private", default is "public"
; Limited is for signed user only
; Private is only for member of the organization
; Public is for everyone
DEFAULT_VISIBILITY = public
; Default value for the domain part of the user's email address in the git log
; if he has set KeepEmailPrivate true. The user's email replaced with a
; concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS.

View File

@ -10,6 +10,8 @@ import (
"os"
"strings"
"code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/com"
"github.com/go-xorm/builder"
"github.com/go-xorm/xorm"
@ -125,7 +127,7 @@ func CreateOrganization(org, owner *User) (err error) {
org.NumTeams = 1
org.NumMembers = 1
org.Type = UserTypeOrganization
org.Visibility = VisibleTypePublic
org.Visibility = VisibleType(setting.Service.DefaultVisibilityMode)
sess := x.NewSession()
defer sessionRelease(sess)

View File

@ -991,6 +991,8 @@ var Service struct {
DefaultKeepEmailPrivate bool
DefaultAllowCreateOrganization bool
NoReplyAddress string
DefaultVisibility string
DefaultVisibilityMode int
// OpenID settings
EnableOpenIDSignIn bool
@ -999,6 +1001,12 @@ var Service struct {
OpenIDBlacklist []*regexp.Regexp
}
var visibilityModes = map[string]int{
"public": 1,
"limited": 2,
"private": 3,
}
func newService() {
sec := Cfg.Section("service")
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
@ -1012,6 +1020,8 @@ func newService() {
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
Service.DefaultVisibility = sec.Key("DEFAULT_VISIBILITY").In("public", []string{"public", "limited", "private"})
Service.DefaultVisibilityMode = visibilityModes[Service.DefaultVisibility]
sec = Cfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(false)

View File

@ -1286,6 +1286,7 @@ config.active_code_lives = Active Code Lives
config.reset_password_code_lives = Reset Password Code Expiry Time
config.default_keep_email_private = Default Value for Keep Email Private
config.default_allow_create_organization = Default permission to create Organizations
config.default_visibility_organization = Default visibility for new Organizations
config.no_reply_address = No-reply Address
config.webhook_config = Webhook Configuration

View File

@ -130,6 +130,9 @@
<dd><i class="fa fa{{if .Service.DefaultKeepEmailPrivate}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_allow_create_organization"}}</dt>
<dd><i class="fa fa{{if .Service.DefaultAllowCreateOrganization}}-check{{end}}-square-o"></i></dd>
<dt>{{.i18n.Tr "admin.config.default_visibility_organization"}}</dt>
<dd>{{.Service.DefaultVisibility}}</dd>
<dt>{{.i18n.Tr "admin.config.no_reply_address"}}</dt>
<dd>{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}</dd>
<div class="ui divider"></div>