diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/models/protected_branch | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/models/protected_branch')
-rw-r--r-- | app/models/protected_branch/push_access_level.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/protected_branch/push_access_level.rb b/app/models/protected_branch/push_access_level.rb index 63d577a4866..f28440f2444 100644 --- a/app/models/protected_branch/push_access_level.rb +++ b/app/models/protected_branch/push_access_level.rb @@ -18,6 +18,14 @@ class ProtectedBranch::PushAccessLevel < ApplicationRecord end end + def check_access(user) + if Feature.enabled?(:deploy_keys_on_protected_branches, project) && user && deploy_key.present? + return true if user.can?(:read_project, project) && enabled_deploy_key_for_user?(deploy_key, user) + end + + super + end + private def validate_deploy_key_membership @@ -27,4 +35,8 @@ class ProtectedBranch::PushAccessLevel < ApplicationRecord self.errors.add(:deploy_key, 'is not enabled for this project') end end + + def enabled_deploy_key_for_user?(deploy_key, user) + deploy_key.user_id == user.id && DeployKey.with_write_access_for_project(protected_branch.project, deploy_key: deploy_key).any? + end end |