From 5d6aac24658854cd19311d3451c3a01dd28fd7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Fri, 5 May 2017 18:05:22 +0300 Subject: [PATCH 1/3] Add configuration option for defaul permission for regular users to create Organizations --- conf/app.ini | 3 +++ integrations/mysql.ini | 1 + integrations/pgsql.ini | 1 + integrations/sqlite.ini | 1 + models/user.go | 2 +- modules/auth/user_form.go | 1 + modules/setting/setting.go | 2 ++ options/locale/locale_en-US.ini | 3 +++ public/css/index.css | 4 ++-- public/less/_admin.less | 4 ++-- routers/install.go | 2 ++ templates/admin/config.tmpl | 2 ++ templates/install.tmpl | 6 ++++++ 13 files changed, 27 insertions(+), 5 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index b1eb953cdffc..b4e1cb86448d 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -240,6 +240,9 @@ ENABLE_CAPTCHA = true ; Default value for KeepEmailPrivate ; New user will get the value of this setting copied into their profile DEFAULT_KEEP_EMAIL_PRIVATE = false +; Default value for AllowCreateOrganization +; New user will get the value of this setting copied into their profile +DEFAULT_ALLOW_CREATE_ORGANIZATION = false ; 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. diff --git a/integrations/mysql.ini b/integrations/mysql.ini index b15588c867c7..1ac1e4d0ba96 100644 --- a/integrations/mysql.ini +++ b/integrations/mysql.ini @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = false NO_REPLY_ADDRESS = noreply.example.org [picture] diff --git a/integrations/pgsql.ini b/integrations/pgsql.ini index 920a5190d498..626ff41e6519 100644 --- a/integrations/pgsql.ini +++ b/integrations/pgsql.ini @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = false NO_REPLY_ADDRESS = noreply.example.org [picture] diff --git a/integrations/sqlite.ini b/integrations/sqlite.ini index dc17b23ec87f..0a68f78d6c66 100644 --- a/integrations/sqlite.ini +++ b/integrations/sqlite.ini @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = false NO_REPLY_ADDRESS = noreply.example.org [picture] diff --git a/models/user.go b/models/user.go index 59ce63117222..e95bf5cd44fe 100644 --- a/models/user.go +++ b/models/user.go @@ -706,7 +706,7 @@ func CreateUser(u *User) (err error) { return err } u.EncodePasswd() - u.AllowCreateOrganization = true + u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization u.MaxRepoCreation = -1 sess := x.NewSession() diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 9e19c78a456f..ea6e464a7f7c 100644 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -45,6 +45,7 @@ type InstallForm struct { EnableCaptcha bool RequireSignInView bool DefaultKeepEmailPrivate bool + DefaultAllowCreateOrganization bool NoReplyAddress string AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"` diff --git a/modules/setting/setting.go b/modules/setting/setting.go index a00db16d3a67..f1a39cf0706a 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -972,6 +972,7 @@ var Service struct { EnableReverseProxyAutoRegister bool EnableCaptcha bool DefaultKeepEmailPrivate bool + DefaultAllowCreateOrganization bool NoReplyAddress string // OpenID settings @@ -992,6 +993,7 @@ func newService() { Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool() Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool() Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() + Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool() Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") sec = Cfg.Section("openid") diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6f4866e3738e..fadb90a9e367 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -132,6 +132,8 @@ install_success = Welcome! We're glad that you chose Gitea, have fun and take ca invalid_log_root_path = Log root path is invalid: %v default_keep_email_private = Default Value for Keep Email Private default_keep_email_private_popup = This is the default value for the visibility of the user's email address. If set to true the email address of all new users will be hidden until the user changes his setting. +default_allow_create_organization = Default permission value for new users to create Organizations +default_allow_create_organization_popup = This is default permission value that will be assigned for new users. If set to true new users will be allowed to create Organizations. no_reply_address = No-reply Address no_reply_address_helper = Domain for the user's email address in git logs if he keeps his email address private. E.g. user 'joe' and 'noreply.example.org' will be 'joe@noreply.example.org' @@ -1260,6 +1262,7 @@ config.enable_captcha = Enable Captcha config.active_code_lives = Active Code Lives config.reset_password_code_lives = Reset Password Code Lives config.default_keep_email_private = Default Value for Keep Email Private +config.default_allow_create_organization = Default permission to create Organizations config.no_reply_address = No-reply Address config.webhook_config = Webhook Configuration diff --git a/public/css/index.css b/public/css/index.css index 6c5be7f0b55f..5721d8e9bc2b 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -2938,12 +2938,12 @@ footer .ui.language .menu { margin: 0; } .admin dl.admin-dl-horizontal dd { - margin-left: 240px; + margin-left: 275px; } .admin dl.admin-dl-horizontal dt { font-weight: bolder; float: left; - width: 250px; + width: 285px; clear: left; overflow: hidden; text-overflow: ellipsis; diff --git a/public/less/_admin.less b/public/less/_admin.less index eab7b15efa05..92efc3825f45 100644 --- a/public/less/_admin.less +++ b/public/less/_admin.less @@ -45,12 +45,12 @@ margin: 0; dd { - margin-left: 240px; + margin-left: 275px; } dt { font-weight: bolder; float: left; - width: 250px; + width: 285px; clear: left; overflow: hidden; text-overflow: ellipsis; diff --git a/routers/install.go b/routers/install.go index 1ab409d00d24..57311e13a4fd 100644 --- a/routers/install.go +++ b/routers/install.go @@ -112,6 +112,7 @@ func Install(ctx *context.Context) { form.EnableCaptcha = setting.Service.EnableCaptcha form.RequireSignInView = setting.Service.RequireSignInView form.DefaultKeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate + form.DefaultAllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization form.NoReplyAddress = setting.Service.NoReplyAddress auth.AssignForm(form, ctx.Data) @@ -295,6 +296,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha)) cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView)) cfg.Section("service").Key("DEFAULT_KEEP_EMAIL_PRIVATE").SetValue(com.ToStr(form.DefaultKeepEmailPrivate)) + cfg.Section("service").Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").SetValue(com.ToStr(form.DefaultAllowCreateOrganization)) cfg.Section("service").Key("NO_REPLY_ADDRESS").SetValue(com.ToStr(form.NoReplyAddress)) cfg.Section("").Key("RUN_MODE").SetValue("prod") diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 7348ab7b9e7c..0fbd0befcf6b 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -128,6 +128,8 @@
{{.i18n.Tr "admin.config.default_keep_email_private"}}
+
{{.i18n.Tr "admin.config.default_allow_create_organization"}}
+
{{.i18n.Tr "admin.config.no_reply_address"}}
{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}
diff --git a/templates/install.tmpl b/templates/install.tmpl index d084005c8cfa..ede1d4399f38 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -212,6 +212,12 @@ +
+
+ + +
+
From 0c2bb8a7030b786b7e91882ce06f05d92b3214d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Mon, 8 May 2017 19:51:11 +0300 Subject: [PATCH 2/3] Change default to keep it backward compatible --- conf/app.ini | 4 ++-- integrations/mysql.ini | 2 +- integrations/pgsql.ini | 2 +- integrations/sqlite.ini | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index b4e1cb86448d..47fd4b1182ab 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -241,8 +241,8 @@ ENABLE_CAPTCHA = true ; New user will get the value of this setting copied into their profile DEFAULT_KEEP_EMAIL_PRIVATE = false ; Default value for AllowCreateOrganization -; New user will get the value of this setting copied into their profile -DEFAULT_ALLOW_CREATE_ORGANIZATION = false +; New user will have rights set to create organizations depending on this setting +DEFAULT_ALLOW_CREATE_ORGANIZATION = true ; 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. diff --git a/integrations/mysql.ini b/integrations/mysql.ini index 1ac1e4d0ba96..9560b4ff9f99 100644 --- a/integrations/mysql.ini +++ b/integrations/mysql.ini @@ -32,7 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false -DEFAULT_ALLOW_CREATE_ORGANIZATION = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org [picture] diff --git a/integrations/pgsql.ini b/integrations/pgsql.ini index 626ff41e6519..a0cae0dabc1d 100644 --- a/integrations/pgsql.ini +++ b/integrations/pgsql.ini @@ -32,7 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false -DEFAULT_ALLOW_CREATE_ORGANIZATION = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org [picture] diff --git a/integrations/sqlite.ini b/integrations/sqlite.ini index 0a68f78d6c66..9ced8c025b91 100644 --- a/integrations/sqlite.ini +++ b/integrations/sqlite.ini @@ -32,7 +32,7 @@ DISABLE_REGISTRATION = false ENABLE_CAPTCHA = false REQUIRE_SIGNIN_VIEW = false DEFAULT_KEEP_EMAIL_PRIVATE = false -DEFAULT_ALLOW_CREATE_ORGANIZATION = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true NO_REPLY_ADDRESS = noreply.example.org [picture] From 8ebc8f957253a0f3150174d49770eaba84998bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20Buk=C5=A1is-Haberkorns?= Date: Mon, 8 May 2017 20:20:32 +0300 Subject: [PATCH 3/3] Set default in service configuration init --- modules/setting/setting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index f1a39cf0706a..c3ed4ef97175 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -993,7 +993,7 @@ func newService() { Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool() Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool() Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool() - Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool() + Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true) Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org") sec = Cfg.Section("openid")