Skip to content

Disable custom Git Hooks globally via configuration file #2450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ REVERSE_PROXY_AUTHENTICATION_USER = X-WEBAUTH-USER
MIN_PASSWORD_LENGTH = 6
; True when users are allowed to import local server paths
IMPORT_LOCAL_PATHS = false
; Prevent all users (including admin) from creating custom git hooks
DISABLE_GIT_HOOKS = false

[openid]
;
Expand Down
2 changes: 1 addition & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (u *User) CanCreateOrganization() bool {

// CanEditGitHook returns true if user can edit Git hooks.
func (u *User) CanEditGitHook() bool {
return u.IsAdmin || u.AllowGitHook
return !setting.DisableGitHooks && (u.IsAdmin || u.AllowGitHook)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this feedback, especially linking me to where I could look. Investigating this (by calling the API to see what the response would be), I found that it only returns the standard gitea/slack/discord/etc.. hooks, and couldn't find it returning the githooks.

}

// CanImportLocal returns true if user can migrate repository by local path.
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ var (
ReverseProxyAuthUser string
MinPasswordLength int
ImportLocalPaths bool
DisableGitHooks bool

// Database settings
UseSQLite3 bool
Expand Down Expand Up @@ -817,6 +818,7 @@ func NewContext() {
ReverseProxyAuthUser = sec.Key("REVERSE_PROXY_AUTHENTICATION_USER").MustString("X-WEBAUTH-USER")
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
DisableGitHooks = sec.Key("DISABLE_GIT_HOOKS").MustBool(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this also to the app.ini file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonasFranzDEV Thanks for this feedback. I've just pushed a new commit with the option in app.ini

InternalToken = sec.Key("INTERNAL_TOKEN").String()
if len(InternalToken) == 0 {
secretBytes := make([]byte, 32)
Expand Down
3 changes: 3 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func NewFuncMap() []template.FuncMap {
}
return out.String()
},
"DisableGitHooks": func() bool {
return setting.DisableGitHooks
},
}}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/admin/user/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.allow_git_hook"}}</strong></label>
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}}>
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since User.CanEditGitHook already checks this, is this change needed?

https://github.com/go-gitea/gitea/pull/2450/files#diff-46259196476f860fea33754fcb22e9eeR240

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @bkcsoft. This change is needed so that an admin doesn't get confused. If the global setting is set to disable githooks, then the template change will prevent the admin from checking the box in the admin dashboard and wondering why the change doesn't take effect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah right, missed the "disabled" part :)

</div>
</div>
<div class="inline field">
Expand Down