Skip to content
Snippets Groups Projects
Commit 1dd279d8 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

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
No related branches found
No related tags found
No related merge requests found
class @IssuableForm
ISSUE_MOVE_CONFIRM_MSG = 'Are you sure you want to move this issue to another project?'
constructor: (@form) ->
GitLab.GfmAutoComplete.setup()
new UsersSelect()
Loading
Loading
@@ -6,12 +8,13 @@ class @IssuableForm
 
@titleField = @form.find("input[name*='[title]']")
@descriptionField = @form.find("textarea[name*='[description]']")
@issueMoveField = @form.find("#move_to_project_id")
 
return unless @titleField.length && @descriptionField.length
 
@initAutosave()
 
@form.on "submit", @resetAutosave
@form.on "submit", @handleSubmit
@form.on "click", ".btn-cancel", @resetAutosave
 
initAutosave: ->
Loading
Loading
@@ -27,6 +30,12 @@ class @IssuableForm
"description"
]
 
handleSubmit: (e) =>
@resetAutosave
if (parseInt(@issueMoveField?.val()) ? 0) > 0
e.preventDefault() unless confirm(ISSUE_MOVE_CONFIRM_MSG)
resetAutosave: =>
@titleField.data("autosave").reset()
@descriptionField.data("autosave").reset()
Loading
Loading
@@ -57,6 +57,17 @@ module IssuesHelper
options_from_collection_for_select(milestones, 'id', 'title', object.milestone_id)
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)
if item.respond_to?(:expired?) && item.expired?
'status-box-expired'
Loading
Loading
Loading
Loading
@@ -72,9 +72,9 @@
.form-group
= f.label :move_to_project_id, 'Move', class: 'control-label'
.col-sm-10
= project_select_tag(:move_to_project_id, placeholder: 'Select project',
class: 'custom-form-control', data: { 'select-id' => 'id',
'access-level' => Gitlab::Access::REPORTER, 'without-id' => issuable.project.id })
- projects = project_options(issuable, current_user, ability: :admin_issue)
= select_tag(:move_to_project_id, projects, include_blank: true,
class: 'select2', data: { placeholder: 'Select project' })
 
- if issuable.is_a?(MergeRequest)
%hr
Loading
Loading
Loading
Loading
@@ -28,7 +28,7 @@ describe Issues::MoveService, services: true do
new_project.team << [user, :reporter]
end
end
context 'issue movable' do
include_context 'issue move requested'
include_context 'user can move issue'
Loading
Loading
@@ -162,6 +162,18 @@ describe Issues::MoveService, services: true do
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
let(:new_project_id) { nil }
 
Loading
Loading
@@ -179,7 +191,6 @@ describe Issues::MoveService, services: true do
end
end
 
describe 'move permissions' do
include_context 'issue move requested'
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment