Commit 161b776d authored by Stan Hu's avatar Stan Hu

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

If the merge request can be rebased based on the history of the commits,
users attempting to view the merge request would hit an Error 500. This
occurred because `user_can_push_to_source_branch?` would be called
on a non-existent project.

Closes gitlab-org/gitlab-ce#33011
parent 3b328475
......@@ -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)
......
......@@ -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