Skip to content

Commit 51d0bec

Browse files
lafriksbkcsoft
authored andcommitted
Add configuration option for default permission to create Organizations (#1686)
1 parent a85c5ab commit 51d0bec

File tree

13 files changed

+27
-5
lines changed

13 files changed

+27
-5
lines changed

conf/app.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ ENABLE_CAPTCHA = true
240240
; Default value for KeepEmailPrivate
241241
; New user will get the value of this setting copied into their profile
242242
DEFAULT_KEEP_EMAIL_PRIVATE = false
243+
; Default value for AllowCreateOrganization
244+
; New user will have rights set to create organizations depending on this setting
245+
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
243246
; Default value for the domain part of the user's email address in the git log
244247
; if he has set KeepEmailPrivate true. The user's email replaced with a
245248
; concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS.

integrations/mysql.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
3232
ENABLE_CAPTCHA = false
3333
REQUIRE_SIGNIN_VIEW = false
3434
DEFAULT_KEEP_EMAIL_PRIVATE = false
35+
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
3536
NO_REPLY_ADDRESS = noreply.example.org
3637

3738
[picture]

integrations/pgsql.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
3232
ENABLE_CAPTCHA = false
3333
REQUIRE_SIGNIN_VIEW = false
3434
DEFAULT_KEEP_EMAIL_PRIVATE = false
35+
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
3536
NO_REPLY_ADDRESS = noreply.example.org
3637

3738
[picture]

integrations/sqlite.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
3232
ENABLE_CAPTCHA = false
3333
REQUIRE_SIGNIN_VIEW = false
3434
DEFAULT_KEEP_EMAIL_PRIVATE = false
35+
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
3536
NO_REPLY_ADDRESS = noreply.example.org
3637

3738
[picture]

models/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ func CreateUser(u *User) (err error) {
706706
return err
707707
}
708708
u.EncodePasswd()
709-
u.AllowCreateOrganization = true
709+
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
710710
u.MaxRepoCreation = -1
711711

712712
sess := x.NewSession()

modules/auth/user_form.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type InstallForm struct {
4545
EnableCaptcha bool
4646
RequireSignInView bool
4747
DefaultKeepEmailPrivate bool
48+
DefaultAllowCreateOrganization bool
4849
NoReplyAddress string
4950

5051
AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ var Service struct {
972972
EnableReverseProxyAutoRegister bool
973973
EnableCaptcha bool
974974
DefaultKeepEmailPrivate bool
975+
DefaultAllowCreateOrganization bool
975976
NoReplyAddress string
976977

977978
// OpenID settings
@@ -992,6 +993,7 @@ func newService() {
992993
Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()
993994
Service.EnableCaptcha = sec.Key("ENABLE_CAPTCHA").MustBool()
994995
Service.DefaultKeepEmailPrivate = sec.Key("DEFAULT_KEEP_EMAIL_PRIVATE").MustBool()
996+
Service.DefaultAllowCreateOrganization = sec.Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").MustBool(true)
995997
Service.NoReplyAddress = sec.Key("NO_REPLY_ADDRESS").MustString("noreply.example.org")
996998

997999
sec = Cfg.Section("openid")

options/locale/locale_en-US.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ install_success = Welcome! We're glad that you chose Gitea, have fun and take ca
132132
invalid_log_root_path = Log root path is invalid: %v
133133
default_keep_email_private = Default Value for Keep Email Private
134134
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.
135+
default_allow_create_organization = Default permission value for new users to create Organizations
136+
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.
135137
no_reply_address = No-reply Address
136138
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 '[email protected]'
137139
@@ -1260,6 +1262,7 @@ config.enable_captcha = Enable Captcha
12601262
config.active_code_lives = Active Code Lives
12611263
config.reset_password_code_lives = Reset Password Code Lives
12621264
config.default_keep_email_private = Default Value for Keep Email Private
1265+
config.default_allow_create_organization = Default permission to create Organizations
12631266
config.no_reply_address = No-reply Address
12641267

12651268
config.webhook_config = Webhook Configuration

public/css/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,12 +2938,12 @@ footer .ui.language .menu {
29382938
margin: 0;
29392939
}
29402940
.admin dl.admin-dl-horizontal dd {
2941-
margin-left: 240px;
2941+
margin-left: 275px;
29422942
}
29432943
.admin dl.admin-dl-horizontal dt {
29442944
font-weight: bolder;
29452945
float: left;
2946-
width: 250px;
2946+
width: 285px;
29472947
clear: left;
29482948
overflow: hidden;
29492949
text-overflow: ellipsis;

public/less/_admin.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
margin: 0;
4646

4747
dd {
48-
margin-left: 240px;
48+
margin-left: 275px;
4949
}
5050
dt {
5151
font-weight: bolder;
5252
float: left;
53-
width: 250px;
53+
width: 285px;
5454
clear: left;
5555
overflow: hidden;
5656
text-overflow: ellipsis;

routers/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func Install(ctx *context.Context) {
112112
form.EnableCaptcha = setting.Service.EnableCaptcha
113113
form.RequireSignInView = setting.Service.RequireSignInView
114114
form.DefaultKeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
115+
form.DefaultAllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
115116
form.NoReplyAddress = setting.Service.NoReplyAddress
116117

117118
auth.AssignForm(form, ctx.Data)
@@ -295,6 +296,7 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
295296
cfg.Section("service").Key("ENABLE_CAPTCHA").SetValue(com.ToStr(form.EnableCaptcha))
296297
cfg.Section("service").Key("REQUIRE_SIGNIN_VIEW").SetValue(com.ToStr(form.RequireSignInView))
297298
cfg.Section("service").Key("DEFAULT_KEEP_EMAIL_PRIVATE").SetValue(com.ToStr(form.DefaultKeepEmailPrivate))
299+
cfg.Section("service").Key("DEFAULT_ALLOW_CREATE_ORGANIZATION").SetValue(com.ToStr(form.DefaultAllowCreateOrganization))
298300
cfg.Section("service").Key("NO_REPLY_ADDRESS").SetValue(com.ToStr(form.NoReplyAddress))
299301

300302
cfg.Section("").Key("RUN_MODE").SetValue("prod")

templates/admin/config.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
<dd><i class="fa fa{{if .Service.EnableCaptcha}}-check{{end}}-square-o"></i></dd>
129129
<dt>{{.i18n.Tr "admin.config.default_keep_email_private"}}</dt>
130130
<dd><i class="fa fa{{if .Service.DefaultKeepEmailPrivate}}-check{{end}}-square-o"></i></dd>
131+
<dt>{{.i18n.Tr "admin.config.default_allow_create_organization"}}</dt>
132+
<dd><i class="fa fa{{if .Service.DefaultAllowCreateOrganization}}-check{{end}}-square-o"></i></dd>
131133
<dt>{{.i18n.Tr "admin.config.no_reply_address"}}</dt>
132134
<dd>{{if .Service.NoReplyAddress}}{{.Service.NoReplyAddress}}{{else}}-{{end}}</dd>
133135
<div class="ui divider"></div>

templates/install.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@
212212
<input name="default_keep_email_private" type="checkbox" {{if .default_keep_email_private}}checked{{end}}>
213213
</div>
214214
</div>
215+
<div class="inline field">
216+
<div class="ui checkbox">
217+
<label class="poping up" data-content="{{.i18n.Tr "install.default_allow_create_organization_popup"}}"><strong>{{.i18n.Tr "install.default_allow_create_organization"}}</strong></label>
218+
<input name="default_allow_create_organization" type="checkbox" {{if .default_allow_create_organization}}checked{{end}}>
219+
</div>
220+
</div>
215221
<div class="inline field">
216222
<label for="no_reply_address">{{.i18n.Tr "install.no_reply_address"}}</label>
217223
<input id="_no_reply_address" name="no_reply_address" value="{{.no_reply_address}}">

0 commit comments

Comments
 (0)