Add minor improvements in code related to issue move
This commit is contained in:
parent
1dd279d833
commit
5e3c9475a9
7 changed files with 50 additions and 38 deletions
|
@ -30,11 +30,11 @@ class @IssuableForm
|
||||||
"description"
|
"description"
|
||||||
]
|
]
|
||||||
|
|
||||||
handleSubmit: (e) =>
|
handleSubmit: =>
|
||||||
@resetAutosave
|
|
||||||
|
|
||||||
if (parseInt(@issueMoveField?.val()) ? 0) > 0
|
if (parseInt(@issueMoveField?.val()) ? 0) > 0
|
||||||
e.preventDefault() unless confirm(ISSUE_MOVE_CONFIRM_MSG)
|
return false unless confirm(ISSUE_MOVE_CONFIRM_MSG)
|
||||||
|
|
||||||
|
@resetAutosave()
|
||||||
|
|
||||||
resetAutosave: =>
|
resetAutosave: =>
|
||||||
@titleField.data("autosave").reset()
|
@titleField.data("autosave").reset()
|
||||||
|
|
|
@ -60,12 +60,14 @@ module IssuesHelper
|
||||||
def project_options(issuable, current_user, ability: :read_project)
|
def project_options(issuable, current_user, ability: :read_project)
|
||||||
projects = current_user.authorized_projects
|
projects = current_user.authorized_projects
|
||||||
projects = projects.select do |project|
|
projects = projects.select do |project|
|
||||||
current_user.can?(ability, project) && project != issuable.project
|
current_user.can?(ability, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
projects.unshift(OpenStruct.new(id: 0, name_with_namespace: 'No project'))
|
no_project = OpenStruct.new(id: 0, name_with_namespace: 'No project')
|
||||||
|
projects.unshift(no_project)
|
||||||
|
projects.delete(issuable.project)
|
||||||
|
|
||||||
options_from_collection_for_select(projects, :id, :name_with_namespace, 0)
|
options_from_collection_for_select(projects, :id, :name_with_namespace)
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_box_class(item)
|
def status_box_class(item)
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Issues
|
||||||
@issue_new = nil
|
@issue_new = nil
|
||||||
@project_old = @project
|
@project_old = @project
|
||||||
|
|
||||||
if new_project_id
|
if new_project_id.to_i > 0
|
||||||
@project_new = Project.find(new_project_id)
|
@project_new = Project.find(new_project_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ module Issues
|
||||||
def execute
|
def execute
|
||||||
return unless move?
|
return unless move?
|
||||||
|
|
||||||
# Using trasaction because of a high resources footprint
|
# Using transaction because of a high resources footprint
|
||||||
# on rewriting notes (unfolding references)
|
# on rewriting notes (unfolding references)
|
||||||
#
|
#
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
@ -54,10 +54,11 @@ module Issues
|
||||||
def create_new_issue
|
def create_new_issue
|
||||||
new_params = { id: nil, iid: nil, milestone: nil, label_ids: [],
|
new_params = { id: nil, iid: nil, milestone: nil, label_ids: [],
|
||||||
project: @project_new, author: @issue_old.author,
|
project: @project_new, author: @issue_old.author,
|
||||||
description: rewrite_references(@issue_old) }
|
description: unfold_references(@issue_old.description) }
|
||||||
|
|
||||||
|
new_params = @issue_old.serializable_hash.merge(new_params)
|
||||||
create_service = CreateService.new(@project_new, @current_user,
|
create_service = CreateService.new(@project_new, @current_user,
|
||||||
params.merge(new_params))
|
new_params)
|
||||||
|
|
||||||
@issue_new = create_service.execute(set_author: false)
|
@issue_new = create_service.execute(set_author: false)
|
||||||
end
|
end
|
||||||
|
@ -66,7 +67,7 @@ module Issues
|
||||||
@issue_old.notes.find_each do |note|
|
@issue_old.notes.find_each do |note|
|
||||||
new_note = note.dup
|
new_note = note.dup
|
||||||
new_params = { project: @project_new, noteable: @issue_new,
|
new_params = { project: @project_new, noteable: @issue_new,
|
||||||
note: rewrite_references(new_note) }
|
note: unfold_references(new_note.note) }
|
||||||
|
|
||||||
new_note.update(new_params)
|
new_note.update(new_params)
|
||||||
end
|
end
|
||||||
|
@ -78,30 +79,20 @@ module Issues
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_moved_from_note
|
def add_moved_from_note
|
||||||
SystemNoteService.noteable_moved(:from, @issue_new, @project_new,
|
SystemNoteService.noteable_moved(@issue_new, @project_new,
|
||||||
@issue_old, @current_user)
|
@issue_old, @current_user, direction: :from)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_moved_to_note
|
def add_moved_to_note
|
||||||
SystemNoteService.noteable_moved(:to, @issue_old, @project_old,
|
SystemNoteService.noteable_moved(@issue_old, @project_old,
|
||||||
@issue_new, @current_user)
|
@issue_new, @current_user, direction: :to)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite_references(noteable)
|
def unfold_references(content)
|
||||||
content = noteable_content(noteable).dup
|
|
||||||
unfolder = Gitlab::Gfm::ReferenceUnfolder.new(content, @project_old)
|
unfolder = Gitlab::Gfm::ReferenceUnfolder.new(content, @project_old)
|
||||||
unfolder.unfold(@project_new)
|
unfolder.unfold(@project_new)
|
||||||
end
|
end
|
||||||
|
|
||||||
def noteable_content(noteable)
|
|
||||||
case noteable
|
|
||||||
when Issue then noteable.description
|
|
||||||
when Note then noteable.note
|
|
||||||
else
|
|
||||||
raise 'Unexpected noteable while moving an issue!'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def notify_participants
|
def notify_participants
|
||||||
notification_service.issue_moved(@issue_old, @issue_new, @current_user)
|
notification_service.issue_moved(@issue_old, @issue_new, @current_user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
# Used for creating system notes (e.g., when a user references a merge request
|
# Used for creating system notes (e.g., when a user references a merge request
|
||||||
# from an issue, an issue's assignee changes, an issue is closed, etc.)
|
# from an issue, an issue's assignee changes, an issue is closed, etc.)
|
||||||
class SystemNoteService
|
class SystemNoteService
|
||||||
extend GitlabMarkdownHelper
|
|
||||||
# Called when commits are added to a Merge Request
|
# Called when commits are added to a Merge Request
|
||||||
#
|
#
|
||||||
# noteable - Noteable object
|
# noteable - Noteable object
|
||||||
|
@ -398,16 +397,15 @@ class SystemNoteService
|
||||||
#
|
#
|
||||||
# Example Note text:
|
# Example Note text:
|
||||||
#
|
#
|
||||||
# "Moved to project_new/#11"
|
# "Moved to some_namespace/project_new#11"
|
||||||
#
|
#
|
||||||
# Returns the created Note object
|
# Returns the created Note object
|
||||||
def self.noteable_moved(direction, noteable, project, noteable_ref, author)
|
def self.noteable_moved(noteable, project, noteable_ref, author, direction:)
|
||||||
unless [:to, :from].include?(direction)
|
unless [:to, :from].include?(direction)
|
||||||
raise StandardError, "Invalid direction `#{direction}`"
|
raise ArgumentError, "Invalid direction `#{direction}`"
|
||||||
end
|
end
|
||||||
|
|
||||||
cross_reference = cross_project_reference(noteable_ref.project, noteable_ref)
|
cross_reference = noteable_ref.to_reference(project)
|
||||||
|
|
||||||
body = "Moved #{direction} #{cross_reference}"
|
body = "Moved #{direction} #{cross_reference}"
|
||||||
create_note(noteable: noteable, project: project, author: author, note: body)
|
create_note(noteable: noteable, project: project, author: author, note: body)
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
- if issuable.is_a?(Issue) && can?(current_user, :admin_issue, issuable.project)
|
- if issuable.is_a?(Issue) && can?(current_user, :admin_issue, issuable.project)
|
||||||
%hr
|
%hr
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :move_to_project_id, 'Move', class: 'control-label'
|
= label_tag :move_to_project_id, 'Move', class: 'control-label'
|
||||||
.col-sm-10
|
.col-sm-10
|
||||||
- projects = project_options(issuable, current_user, ability: :admin_issue)
|
- projects = project_options(issuable, current_user, ability: :admin_issue)
|
||||||
= select_tag(:move_to_project_id, projects, include_blank: true,
|
= select_tag(:move_to_project_id, projects, include_blank: true,
|
||||||
|
|
|
@ -1,8 +1,30 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
module Gfm
|
module Gfm
|
||||||
##
|
##
|
||||||
# Class than unfolds local references in text.
|
# Class that unfolds local references in text.
|
||||||
#
|
#
|
||||||
|
# The initializer takes text in Markdown and project this text is valid
|
||||||
|
# in context of.
|
||||||
|
#
|
||||||
|
# `unfold` method tries to find all local references and unfold each of
|
||||||
|
# those local references to cross reference format.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
#
|
||||||
|
# 'Hello, this issue is related to #123 and
|
||||||
|
# other issues labeled with ~"label"', will be converted to:
|
||||||
|
#
|
||||||
|
# 'Hello, this issue is related to gitlab-org/gitlab-ce#123 and
|
||||||
|
# other issue labeled with gitlab-org/gitlab-ce~"label"'.
|
||||||
|
#
|
||||||
|
# It does respect markdown lexical rules, so text in code block will not be
|
||||||
|
# replaced, see another example:
|
||||||
|
#
|
||||||
|
# 'Merge request for issue #1234, see also link:
|
||||||
|
# http://gitlab.com/some/link/#1234, and code `puts #1234`' =>
|
||||||
|
#
|
||||||
|
# 'Merge request for issue gitlab-org/gitlab-ce#1234, se also link:
|
||||||
|
# http://gitlab.com/some/link/#1234, and code `puts #1234`'
|
||||||
#
|
#
|
||||||
class ReferenceUnfolder
|
class ReferenceUnfolder
|
||||||
def initialize(text, project)
|
def initialize(text, project)
|
||||||
|
@ -66,8 +88,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def markdown(text)
|
def markdown(text)
|
||||||
helper = Class.new.extend(GitlabMarkdownHelper)
|
Banzai.render(text, project: @project, no_original_data: true)
|
||||||
helper.markdown(text, project: @project, no_original_data: true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -446,7 +446,7 @@ describe SystemNoteService, services: true do
|
||||||
let(:new_noteable) { create(:issue, project: new_project) }
|
let(:new_noteable) { create(:issue, project: new_project) }
|
||||||
|
|
||||||
subject do
|
subject do
|
||||||
described_class.noteable_moved(direction, noteable, project, new_noteable, author)
|
described_class.noteable_moved(noteable, project, new_noteable, author, direction: direction)
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'cross project mentionable' do
|
shared_examples 'cross project mentionable' do
|
||||||
|
|
Loading…
Reference in a new issue