Commit a18607e4 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-fix-issue-33011' into 'master'

Fix Error 500 when viewing a merge request with a deleted source project

Closes gitlab-ce#33011

See merge request !1996
parents e402a8c8 29cbf520
......@@ -182,6 +182,8 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end
def user_can_push_to_source_branch?
return false unless source_branch_exists?
::Gitlab::UserAccess
.new(current_user, project: source_project)
.can_push_to_branch?(source_branch)
......
......@@ -443,6 +443,10 @@ describe MergeRequestPresenter do
let(:can_push_to_branch) { true }
let(:should_be_rebased) { true }
before do
allow(resource).to receive(:source_branch_exists?) { true }
end
it 'returns path' do
is_expected
.to eq("/#{project.full_path}/merge_requests/#{resource.iid}/rebase")
......
......@@ -146,4 +146,20 @@ describe MergeRequestEntity do
end
end
end
describe 'when source project is deleted' do
let(:project) { create(:project, :repository) }
let(:fork_project) { create(:project, :repository, forked_from_project: project) }
let(:merge_request) { create(:merge_request, source_project: fork_project, target_project: project) }
it 'returns a blank rebase_path' do
allow(merge_request).to receive(:should_be_rebased?).and_return(true)
fork_project.destroy
merge_request.reload
entity = described_class.new(merge_request, request: request).as_json
expect(entity[:rebase_path]).to be_nil
end
end
end
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