summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-03-23 09:39:37 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-03-23 09:41:39 +0100
commit915bfedfa75947d42d0a92e0c00494d43d676b43 (patch)
treeb203ccbcbe5d63ead6eaf19ca7e596d39632e41b
parentd967b122a9dc32ac6fda2f89327463656650020b (diff)
downloadgitlab-ce-move-issue-section-should-not-be-displayed-in-the-new-issue-form-14489.tar.gz
Do not allow to move issue if it has not been persistedmove-issue-section-should-not-be-displayed-in-the-new-issue-form-14489
-rw-r--r--CHANGELOG2
-rw-r--r--app/models/issue.rb3
-rw-r--r--app/services/issues/move_service.rb2
-rw-r--r--app/views/shared/issuable/_form.html.haml2
-rw-r--r--spec/models/issue_spec.rb5
-rw-r--r--spec/services/issues/move_service_spec.rb6
6 files changed, 17 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 00822465e3a..1cc8f377a6a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,7 +4,7 @@ v 8.7.0 (unreleased)
- Make HTTP(s) label consistent on clone bar (Stan Hu)
v 8.6.1 (unreleased)
-
+ - Do not allow to move issue if it has not been persisted
v 8.6.0
- Add ability to move issue to another project
diff --git a/app/models/issue.rb b/app/models/issue.rb
index f32db59ac9f..ed960cb39f4 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -146,7 +146,8 @@ class Issue < ActiveRecord::Base
return false unless user.can?(:admin_issue, to_project)
end
- !moved? && user.can?(:admin_issue, self.project)
+ !moved? && persisted? &&
+ user.can?(:admin_issue, self.project)
end
def to_branch_name
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb
index 3cfbafe1576..468f8acdf64 100644
--- a/app/services/issues/move_service.rb
+++ b/app/services/issues/move_service.rb
@@ -78,6 +78,8 @@ module Issues
end
def unfold_references(content)
+ return unless content
+
rewriter = Gitlab::Gfm::ReferenceRewriter.new(content, @old_project,
@current_user)
rewriter.rewrite(@new_project)
diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml
index 1ad2c09e13c..b01a36265f9 100644
--- a/app/views/shared/issuable/_form.html.haml
+++ b/app/views/shared/issuable/_form.html.haml
@@ -85,7 +85,7 @@
- if can? current_user, :admin_label, issuable.project
= link_to 'Create new label', new_namespace_project_label_path(issuable.project.namespace, issuable.project), target: :blank
-- if issuable.can_move?(current_user) && issuable.persisted?
+- if issuable.can_move?(current_user)
%hr
.form-group
= label_tag :move_to_project_id, 'Move', class: 'control-label'
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 3c34b1d397f..15052aaca28 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -152,6 +152,11 @@ describe Issue, models: true do
it { is_expected.to eq true }
+ context 'issue not persisted' do
+ let(:issue) { build(:issue, project: project) }
+ it { is_expected.to eq false }
+ end
+
context 'checking destination project also' do
subject { issue.can_move?(user, to_project) }
let(:to_project) { create(:project) }
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index 14cc20e529a..ade3b7850f1 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -208,6 +208,12 @@ describe Issues::MoveService, services: true do
it { expect { move }.to raise_error(StandardError, /permissions/) }
end
+
+ context 'issue is not persisted' do
+ include_context 'user can move issue'
+ let(:old_issue) { build(:issue, project: old_project, author: author) }
+ it { expect { move }.to raise_error(StandardError, /permissions/) }
+ end
end
end
end