Patch by Holger Just. git-svn-id: http://svn.redmine.org/redmine/trunk@17314 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/4.0.0
@@ -821,7 +821,7 @@ class Project < ActiveRecord::Base | |||
def copy(project, options={}) | |||
project = project.is_a?(Project) ? project : Project.find(project) | |||
to_be_copied = %w(members wiki versions issue_categories issues queries boards) | |||
to_be_copied = %w(members wiki versions issue_categories issues queries boards documents) | |||
to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil? | |||
Project.transaction do | |||
@@ -1102,6 +1102,21 @@ class Project < ActiveRecord::Base | |||
end | |||
end | |||
# Copies documents from +project+ | |||
def copy_documents(project) | |||
project.documents.each do |document| | |||
new_document = Document.new | |||
new_document.attributes = document.attributes.dup.except("id", "project_id") | |||
new_document.project = self | |||
new_document.attachments = document.attachments.map do |attachement| | |||
attachement.copy(:container => new_document) | |||
end | |||
self.documents << new_document | |||
end | |||
end | |||
def allowed_permissions | |||
@allowed_permissions ||= begin | |||
module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name) |
@@ -9,6 +9,7 @@ | |||
<label class="block"><%= check_box_tag 'only[]', 'issue_categories', true, :id => nil %> <%= l(:label_issue_category_plural) %> (<%= @source_project.issue_categories.count %>)</label> | |||
<label class="block"><%= check_box_tag 'only[]', 'issues', true, :id => nil %> <%= l(:label_issue_plural) %> (<%= @source_project.issues.count %>)</label> | |||
<label class="block"><%= check_box_tag 'only[]', 'queries', true, :id => nil %> <%= l(:label_query_plural) %> (<%= @source_project.queries.count %>)</label> | |||
<label class="block"><%= check_box_tag 'only[]', 'documents', true, :id => nil %> <%= l(:label_document_plural) %> (<%= @source_project.documents.count %>)</label> | |||
<label class="block"><%= check_box_tag 'only[]', 'boards', true, :id => nil %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label> | |||
<label class="block"><%= check_box_tag 'only[]', 'wiki', true, :id => nil %> <%= l(:label_wiki_page_plural) %> (<%= @source_project.wiki.nil? ? 0 : @source_project.wiki.pages.count %>)</label> | |||
<%= hidden_field_tag 'only[]', '' %> |
@@ -227,6 +227,14 @@ module ObjectHelpers | |||
query | |||
end | |||
def Document.generate!(attributes={}) | |||
document = new(attributes) | |||
document.title = "Generated document" if document.title.blank? | |||
document.category ||= DocumentCategory.find(1) | |||
document.save! | |||
document | |||
end | |||
def generate_import(fixture_name='import_issues.csv') | |||
import = IssueImport.new | |||
import.user_id = 2 |
@@ -341,6 +341,28 @@ class ProjectCopyTest < ActiveSupport::TestCase | |||
end | |||
end | |||
test "#copy should copy documents" do | |||
source_project = Project.find(1) | |||
assert @project.copy(source_project) | |||
assert_equal 2, @project.documents.size | |||
@project.documents.each do |document| | |||
assert !source_project.documents.include?(document) | |||
end | |||
end | |||
test "#copy should copy document attachments" do | |||
document = Document.generate!(:title => "copy with attachment", :category_id => 1, :project_id => @source_project.id) | |||
Attachment.create!(:container => document, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1) | |||
@source_project.documents << document | |||
assert @project.copy(@source_project) | |||
copied_document = @project.documents.where(:title => "copy with attachment").first | |||
assert_not_nil copied_document | |||
assert_equal 1, copied_document.attachments.count, "Attachment not copied" | |||
assert_equal "testfile.txt", copied_document.attachments.first.filename | |||
end | |||
test "#copy should change the new issues to use the copied issue categories" do | |||
issue = Issue.find(4) | |||
issue.update_attribute(:category_id, 3) |