summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-03-07 11:39:41 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2018-03-07 17:00:50 +0100
commitcfa9d1ed6b870dbc635148219b42d73c382eb90a (patch)
treeaa7eeedfa4af657c518093aa776ff54f3f1197e3 /app/models/project.rb
parent558e9cd92bab44a0b323132b2f2e6a3bb6dcc738 (diff)
downloadgitlab-ce-cfa9d1ed6b870dbc635148219b42d73c382eb90a.tar.gz
Only allow users that can merge to push to sourcebvl-allow-maintainer-to-push
We only allow users that can merge the merge request to push to the fork.
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index a2b2e0554b1..5f9d9785d64 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1951,12 +1951,20 @@ class Project < ActiveRecord::Base
end
def fetch_branch_allows_maintainer_push?(user, branch_name)
+ check_access = -> do
+ merge_request = source_of_merge_requests.opened
+ .where(allow_maintainer_to_push: true)
+ .find_by(source_branch: branch_name)
+
+ merge_request&.can_be_merged_by?(user)
+ end
+
if RequestStore.active?
RequestStore.fetch("project-#{id}:branch-#{branch_name}:user-#{user.id}:branch_allows_maintainer_push") do
- merge_requests_allowing_push_to_user(user).where(source_branch: branch_name).any?
+ check_access.call
end
else
- merge_requests_allowing_push_to_user(user).where(source_branch: branch_name).any?
+ check_access.call
end
end
end