GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Consider all matching MRs to determine if user can push

parent 8c2172f2
......@@ -1933,14 +1933,8 @@ def merge_requests_allowing_push_to_user(user)
def any_branch_allows_collaboration?(user)
return false unless user
return false if empty_repo?
# Issue for N+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/49322
Gitlab::GitalyClient.allow_n_plus_1_calls do
merge_requests_allowing_collaboration.any? do |merge_request|
merge_request.can_be_merged_by?(user)
end
end
fetch_branch_allows_collaboration(user)
end
def branch_allows_collaboration?(user, branch_name)
......@@ -1950,7 +1944,7 @@ def branch_allows_collaboration?(user, branch_name)
memoized_results = strong_memoize(:branch_allows_collaboration) do
Hash.new do |result, cache_key|
result[cache_key] = fetch_branch_allows_collaboration?(user, branch_name)
result[cache_key] = fetch_branch_allows_collaboration(user, branch_name)
end
end
......@@ -2028,8 +2022,10 @@ def leave_pool_repository
private
def merge_requests_allowing_collaboration
source_of_merge_requests.opened.where(allow_collaboration: true)
def merge_requests_allowing_collaboration(source_branch = nil)
relation = source_of_merge_requests.opened.where(allow_collaboration: true)
relation = relation.where(source_branch: source_branch) if source_branch
relation
end
def create_new_pool_repository
......@@ -2156,12 +2152,16 @@ def handle_update_attribute_error(ex, value)
raise ex
end
def fetch_branch_allows_collaboration?(user, branch_name)
def fetch_branch_allows_collaboration(user, branch_name = nil)
Gitlab::SafeRequestStore.fetch("project-#{id}:branch-#{branch_name}:user-#{user.id}:branch_allows_collaboration") do
next false if empty_repo?
merge_request = merge_requests_allowing_collaboration.find_by(source_branch: branch_name)
merge_request&.can_be_merged_by?(user)
# Issue for N+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/49322
Gitlab::GitalyClient.allow_n_plus_1_calls do
merge_requests_allowing_collaboration(branch_name).any? do |merge_request|
merge_request.can_be_merged_by?(user)
end
end
end
end
......
......@@ -3831,6 +3831,16 @@ def domain_variable
let(:user) { create(:user) }
let(:target_project) { create(:project, :repository) }
let(:project) { fork_project(target_project, nil, repository: true) }
let!(:local_merge_request) do
create(
:merge_request,
target_project: project,
target_branch: 'target-branch',
source_project: project,
source_branch: 'awesome-feature-1',
allow_collaboration: true
)
end
let!(:merge_request) do
create(
:merge_request,
......
......@@ -285,7 +285,7 @@
end
it 'allows to retry failed pipeline' do
allow_any_instance_of(Project).to receive(:fetch_branch_allows_collaboration?).and_return(true)
allow_any_instance_of(Project).to receive(:branch_allows_collaboration?).and_return(true)
allow_any_instance_of(Project).to receive(:empty_repo?).and_return(false)
service.execute(pipeline)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment