Commit 1dd279d8 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use helper to create list of projects issue can be moved to

This also adds confirmation message if issue move has been requested.
parent 41455893
class @IssuableForm class @IssuableForm
ISSUE_MOVE_CONFIRM_MSG = 'Are you sure you want to move this issue to another project?'
constructor: (@form) -> constructor: (@form) ->
GitLab.GfmAutoComplete.setup() GitLab.GfmAutoComplete.setup()
new UsersSelect() new UsersSelect()
...@@ -6,12 +8,13 @@ class @IssuableForm ...@@ -6,12 +8,13 @@ class @IssuableForm
@titleField = @form.find("input[name*='[title]']") @titleField = @form.find("input[name*='[title]']")
@descriptionField = @form.find("textarea[name*='[description]']") @descriptionField = @form.find("textarea[name*='[description]']")
@issueMoveField = @form.find("#move_to_project_id")
return unless @titleField.length && @descriptionField.length return unless @titleField.length && @descriptionField.length
@initAutosave() @initAutosave()
@form.on "submit", @resetAutosave @form.on "submit", @handleSubmit
@form.on "click", ".btn-cancel", @resetAutosave @form.on "click", ".btn-cancel", @resetAutosave
initAutosave: -> initAutosave: ->
...@@ -27,6 +30,12 @@ class @IssuableForm ...@@ -27,6 +30,12 @@ class @IssuableForm
"description" "description"
] ]
handleSubmit: (e) =>
@resetAutosave
if (parseInt(@issueMoveField?.val()) ? 0) > 0
e.preventDefault() unless confirm(ISSUE_MOVE_CONFIRM_MSG)
resetAutosave: => resetAutosave: =>
@titleField.data("autosave").reset() @titleField.data("autosave").reset()
@descriptionField.data("autosave").reset() @descriptionField.data("autosave").reset()
...@@ -57,6 +57,17 @@ module IssuesHelper ...@@ -57,6 +57,17 @@ module IssuesHelper
options_from_collection_for_select(milestones, 'id', 'title', object.milestone_id) options_from_collection_for_select(milestones, 'id', 'title', object.milestone_id)
end end
def project_options(issuable, current_user, ability: :read_project)
projects = current_user.authorized_projects
projects = projects.select do |project|
current_user.can?(ability, project) && project != issuable.project
end
projects.unshift(OpenStruct.new(id: 0, name_with_namespace: 'No project'))
options_from_collection_for_select(projects, :id, :name_with_namespace, 0)
end
def status_box_class(item) def status_box_class(item)
if item.respond_to?(:expired?) && item.expired? if item.respond_to?(:expired?) && item.expired?
'status-box-expired' 'status-box-expired'
......
...@@ -72,9 +72,9 @@ ...@@ -72,9 +72,9 @@
.form-group .form-group
= f.label :move_to_project_id, 'Move', class: 'control-label' = f.label :move_to_project_id, 'Move', class: 'control-label'
.col-sm-10 .col-sm-10
= project_select_tag(:move_to_project_id, placeholder: 'Select project', - projects = project_options(issuable, current_user, ability: :admin_issue)
class: 'custom-form-control', data: { 'select-id' => 'id', = select_tag(:move_to_project_id, projects, include_blank: true,
'access-level' => Gitlab::Access::REPORTER, 'without-id' => issuable.project.id }) class: 'select2', data: { placeholder: 'Select project' })
- if issuable.is_a?(MergeRequest) - if issuable.is_a?(MergeRequest)
%hr %hr
......
...@@ -162,6 +162,18 @@ describe Issues::MoveService, services: true do ...@@ -162,6 +162,18 @@ describe Issues::MoveService, services: true do
end end
end end
context 'moving to same project' do
let(:new_project) { old_project }
include_context 'issue move requested'
include_context 'user can move issue'
it 'raises error' do
expect { move_service }
.to raise_error(StandardError, /Cannot move issue/)
end
end
context 'issue move not requested' do context 'issue move not requested' do
let(:new_project_id) { nil } let(:new_project_id) { nil }
...@@ -179,7 +191,6 @@ describe Issues::MoveService, services: true do ...@@ -179,7 +191,6 @@ describe Issues::MoveService, services: true do
end end
end end
describe 'move permissions' do describe 'move permissions' do
include_context 'issue move requested' include_context 'issue move requested'
......
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