Commit e364c8d5 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '218228-validate-source-missing' into 'master'

Ignore missing source project when editing MR

See merge request gitlab-org/gitlab!49311
parents a6981733 954c45ab
......@@ -83,7 +83,7 @@ module MergeRequestsHelper
end
def merge_request_button_hidden?(merge_request, closed)
merge_request.closed? == closed || (merge_request.merged? == closed && !merge_request.closed?) || merge_request.closed_without_fork?
merge_request.closed? == closed || (merge_request.merged? == closed && !merge_request.closed?) || merge_request.closed_or_merged_without_fork?
end
def merge_request_version_path(project, merge_request, merge_request_diff, start_sha = nil)
......
......@@ -233,13 +233,13 @@ class MergeRequest < ApplicationRecord
cannot_be_merged_rechecking? ? 'checking' : merge_status
end
validates :source_project, presence: true, unless: [:allow_broken, :importing?, :closed_without_fork?]
validates :source_project, presence: true, unless: [:allow_broken, :importing?, :closed_or_merged_without_fork?]
validates :source_branch, presence: true
validates :target_project, presence: true
validates :target_branch, presence: true
validates :merge_user, presence: true, if: :auto_merge_enabled?, unless: :importing?
validate :validate_branches, unless: [:allow_broken, :importing?, :closed_without_fork?]
validate :validate_fork, unless: :closed_without_fork?
validate :validate_branches, unless: [:allow_broken, :importing?, :closed_or_merged_without_fork?]
validate :validate_fork, unless: :closed_or_merged_without_fork?
validate :validate_target_project, on: :create
scope :by_source_or_target_branch, ->(branch_name) do
......@@ -883,8 +883,8 @@ class MergeRequest < ApplicationRecord
!!merge_jid && !merged? && Gitlab::SidekiqStatus.running?(merge_jid)
end
def closed_without_fork?
closed? && source_project_missing?
def closed_or_merged_without_fork?
(closed? || merged?) && source_project_missing?
end
def source_project_missing?
......
......@@ -11,7 +11,7 @@ module MergeRequests
params.delete(:target_project_id)
params.delete(:source_branch)
if merge_request.closed_without_fork?
if merge_request.closed_or_merged_without_fork?
params.delete(:target_branch)
params.delete(:force_remove_source_branch)
end
......
......@@ -4,7 +4,7 @@
- state_human_name, state_icon_name = state_name_with_icon(@merge_request)
- are_close_and_open_buttons_hidden = merge_request_button_hidden?(@merge_request, true) && merge_request_button_hidden?(@merge_request, false)
- if @merge_request.closed_without_fork?
- if @merge_request.closed_or_merged_without_fork?
.gl-alert.gl-alert-danger.gl-mb-5
= sprite_icon('error', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title')
.gl-alert-body
......
......@@ -2,7 +2,7 @@
- form = local_assigns.fetch(:form)
- return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_without_fork?
- return if issuable.closed_or_merged_without_fork?
- source_title, target_title = format_mr_branch_names(@merge_request)
......
......@@ -2,7 +2,7 @@
- project = local_assigns.fetch(:project)
- return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_without_fork?
- return if issuable.closed_or_merged_without_fork?
.form-group.row
.col-sm-2.col-form-label.pt-sm-0
......
......@@ -3452,7 +3452,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
describe "#closed_without_fork?" do
describe "#closed_or_merged_without_fork?" do
let(:project) { create(:project) }
let(:forked_project) { fork_project(project) }
let(:user) { create(:user) }
......@@ -3466,14 +3466,33 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
it "returns false if the fork exist" do
expect(closed_merge_request.closed_without_fork?).to be_falsey
expect(closed_merge_request.closed_or_merged_without_fork?).to be_falsey
end
it "returns true if the fork does not exist" do
unlink_project.execute
closed_merge_request.reload
expect(closed_merge_request.closed_without_fork?).to be_truthy
expect(closed_merge_request.closed_or_merged_without_fork?).to be_truthy
end
end
context "when the merge request was merged" do
let(:merged_merge_request) do
create(:merged_merge_request,
source_project: forked_project,
target_project: project)
end
it "returns false if the fork exist" do
expect(merged_merge_request.closed_or_merged_without_fork?).to be_falsey
end
it "returns true if the fork does not exist" do
unlink_project.execute
merged_merge_request.reload
expect(merged_merge_request.closed_or_merged_without_fork?).to be_truthy
end
end
......@@ -3485,7 +3504,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
it "returns false" do
expect(open_merge_request.closed_without_fork?).to be_falsey
expect(open_merge_request.closed_or_merged_without_fork?).to be_falsey
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