def build_new_issue_from_params
if params[:id].blank?
@issue = Issue.new
- begin
- @issue.copy_from(params[:copy_from]) if params[:copy_from]
- rescue ActiveRecord::RecordNotFound
- render_404
- return
+ if params[:copy_from]
+ begin
+ @copy_from = Issue.visible.find(params[:copy_from])
+ @copy_attachments = params[:copy_attachments].present? || request.get?
+ @issue.copy_from(@copy_from, :attachments => @copy_attachments)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ return
+ end
end
@issue.project = @project
else
end
# Copies attributes from another issue, arg can be an id or an Issue
- def copy_from(arg)
+ def copy_from(arg, options={})
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
self.status = issue.status
self.author = User.current
- self.attachments = issue.attachments.map do |attachement|
- attachement.copy(:container => self)
+ unless options[:attachments] == false
+ self.attachments = issue.attachments.map do |attachement|
+ attachement.copy(:container => self)
+ end
end
@copied_from = issue
self
<%= render :partial => 'issues/form', :locals => {:f => f} %>
</div>
+ <% if @copy_from && @copy_from.attachments.any? %>
+ <p>
+ <label for="copy_attachments"><%= l(:label_copy_attachments) %></label>
+ <%= check_box_tag 'copy_attachments', '1', @copy_attachments %>
+ </p>
+ <% end %>
+
<p id="attachments_form"><%= label_tag('attachments[1][file]', l(:label_attachment_plural))%><%= render :partial => 'attachments/form' %></p>
<% if @issue.safe_attribute? 'watcher_user_ids' -%>
other: "%{count} قضايا"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
description_date_range_interval: Изберете диапазон чрез задаване на начална и крайна дати
description_date_from: Въведете начална дата
description_date_to: Въведете крайна дата
+ label_copy_attachments: Copy attachments
other: "%{count} aktivnosti"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} assumptes"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Úkoly"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} sager"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} tickets"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Θέματα"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} issues"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
label_parent_revision: Parent
label_child_revision: Child
label_export_options: "%{export_format} export options"
+ label_copy_attachments: Copy attachments
button_login: Login
button_submit: Submit
other: "%{count} peticiones"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} zereginak"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} پیامد"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} tapahtumat"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
label_issues_visibility_public: Toutes les demandes non privées
label_issues_visibility_own: Demandes créées par ou assignées à l'utilisateur
label_export_options: Options d'exportation %{export_format}
+ label_copy_attachments: Copier les fichiers
button_login: Connexion
button_submit: Soumettre
other: "%{count} peticións"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} נושאים"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} predmeti"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} feladatok"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} masalah"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} segnalazioni"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} チケット"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} 일감"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} darbai"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} uzdevumi"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Задачи"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Асуудлууд"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} issues"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} saker"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} zagadnienia"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} tarefas"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} tarefas"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} tichete"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Задачи"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Úlohy"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} zahtevki"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} problemi"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Проблеми"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Ärenden"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} ปัญหา"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} İşler"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} Питання"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} vấn đề"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} 問題清單"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
other: "%{count} 问题"
label_repository_new: New repository
field_repository_is_default: Main repository
+ label_copy_attachments: Copy attachments
assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
end
+ def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
+ @request.session[:user_id] = 2
+ issue = Issue.find(3)
+ assert issue.attachments.count > 0
+ get :new, :project_id => 1, :copy_from => 3
+
+ assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
+ end
+
+ def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
+ @request.session[:user_id] = 2
+ issue = Issue.find(3)
+ issue.attachments.delete_all
+ get :new, :project_id => 1, :copy_from => 3
+
+ assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
+ end
+
def test_new_as_copy_with_invalid_issue_should_respond_with_404
@request.session[:user_id] = 2
get :new, :project_id => 1, :copy_from => 99999
assert_difference 'Attachment.count', count do
assert_no_difference 'Journal.count' do
post :create, :project_id => 1, :copy_from => 3,
- :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
+ :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
+ :copy_attachments => '1'
end
end
end
assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
end
+ def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
+ @request.session[:user_id] = 2
+ issue = Issue.find(3)
+ count = issue.attachments.count
+ assert count > 0
+
+ assert_difference 'Issue.count' do
+ assert_no_difference 'Attachment.count' do
+ assert_no_difference 'Journal.count' do
+ post :create, :project_id => 1, :copy_from => 3,
+ :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
+ end
+ end
+ end
+ copy = Issue.first(:order => 'id DESC')
+ assert_equal 0, copy.attachments.count
+ end
+
def test_create_as_copy_with_attachments_should_add_new_files
@request.session[:user_id] = 2
issue = Issue.find(3)
assert_no_difference 'Journal.count' do
post :create, :project_id => 1, :copy_from => 3,
:issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
+ :copy_attachments => '1',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
end
end