diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-12-04 14:55:49 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-12-04 14:55:49 +0300 |
commit | 6ed50b62e739a438676653acfc9b7718b83b6f00 (patch) | |
tree | 664138a791b1d0986920275d0dcb012db5018d7c /lib/gitlab/checks/push_check.rb | |
parent | 87186cbc922465875e299ed761ed4d6143ae501a (diff) |
CE port Refactor Gitlab::Checks::ChangeAccess class
Diffstat (limited to 'lib/gitlab/checks/push_check.rb')
-rw-r--r-- | lib/gitlab/checks/push_check.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/checks/push_check.rb b/lib/gitlab/checks/push_check.rb new file mode 100644 index 00000000000..f3a52f09868 --- /dev/null +++ b/lib/gitlab/checks/push_check.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Gitlab + module Checks + class PushCheck < BaseChecker + def validate! + logger.log_timed("Checking if you are allowed to push...") do + unless can_push? + raise GitAccess::UnauthorizedError, 'You are not allowed to push code to this project.' + end + end + end + + private + + def can_push? + user_access.can_do_action?(:push_code) || + user_access.can_push_to_branch?(branch_name) + end + end + end +end |