Commit b244be6c authored by Thibault's avatar Thibault Committed by Igor Drozdov

Check source project is existing before editing merge request

parent c9d043c6
......@@ -946,6 +946,7 @@ class MergeRequest < ApplicationRecord
end
def can_remove_source_branch?(current_user)
source_project &&
!ProtectedBranch.protected?(source_project, source_branch) &&
!source_project.root_ref?(source_branch) &&
Ability.allowed?(current_user, :push_code, source_project) &&
......
......@@ -1170,6 +1170,12 @@ describe MergeRequest do
expect(subject.can_remove_source_branch?(user)).to be_falsey
end
it "can't be removed because source project has been deleted" do
subject.source_project = nil
expect(subject.can_remove_source_branch?(user)).to be_falsey
end
it "can't remove a root ref" do
subject.update(source_branch: 'master', target_branch: 'feature')
......
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