Skip to content

Commit 9bdbfbf

Browse files
techknowlogicklafriks
authored andcommitted
Disable custom Git Hooks globally via configuration file (#2450)
* Create option to disable githooks globally via configuration file * Update comment in app.ini to align with @ethantkoenig's suggestion Signed-off-by: Matti Ranta <[email protected]>
1 parent 3fecf94 commit 9bdbfbf

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

conf/app.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
206206
MIN_PASSWORD_LENGTH = 6
207207
; True when users are allowed to import local server paths
208208
IMPORT_LOCAL_PATHS = false
209+
; Prevent all users (including admin) from creating custom git hooks
210+
DISABLE_GIT_HOOKS = false
209211

210212
[openid]
211213
;

models/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (u *User) CanCreateOrganization() bool {
237237

238238
// CanEditGitHook returns true if user can edit Git hooks.
239239
func (u *User) CanEditGitHook() bool {
240-
return u.IsAdmin || u.AllowGitHook
240+
return !setting.DisableGitHooks && (u.IsAdmin || u.AllowGitHook)
241241
}
242242

243243
// CanImportLocal returns true if user can migrate repository by local path.

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ var (
124124
ReverseProxyAuthUser string
125125
MinPasswordLength int
126126
ImportLocalPaths bool
127+
DisableGitHooks bool
127128

128129
// Database settings
129130
UseSQLite3 bool
@@ -817,6 +818,7 @@ func NewContext() {
817818
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
818819
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
819820
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
821+
DisableGitHooks = sec.Key("DISABLE_GIT_HOOKS").MustBool(false)
820822
InternalToken = sec.Key("INTERNAL_TOKEN").String()
821823
if len(InternalToken) == 0 {
822824
secretBytes := make([]byte, 32)

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func NewFuncMap() []template.FuncMap {
155155
}
156156
return out.String()
157157
},
158+
"DisableGitHooks": func() bool {
159+
return setting.DisableGitHooks
160+
},
158161
}}
159162
}
160163

templates/admin/user/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<div class="inline field">
8787
<div class="ui checkbox">
8888
<label><strong>{{.i18n.Tr "admin.users.allow_git_hook"}}</strong></label>
89-
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}}>
89+
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
9090
</div>
9191
</div>
9292
<div class="inline field">

0 commit comments

Comments
 (0)