Project

General

Profile

Patch #18419 » copy_news_with_project-r19693.patch

Go MAEDA, 2020-04-16 04:04

View differences:

app/models/project.rb
841 841
  def copy(project, options={})
842 842
    project = project.is_a?(Project) ? project : Project.find(project)
843 843

  
844
    to_be_copied = %w(members wiki versions issue_categories issues queries boards documents)
844
    to_be_copied = %w(members wiki versions issue_categories issues queries boards documents news)
845 845
    to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil?
846 846

  
847 847
    Project.transaction do
......
1161 1161
    end
1162 1162
  end
1163 1163

  
1164
  # Copies news from +project+
1165
  def copy_news(project)
1166
    project.news.each do |news|
1167
      new_news = News.new
1168
      new_news.attributes = news.attributes.dup.except("id", "project_id", "created_on", "updated_on")
1169
      self.news << new_news
1170
    end
1171
  end
1172

  
1164 1173
  def allowed_permissions
1165 1174
    @allowed_permissions ||= begin
1166 1175
      module_names = enabled_modules.loaded? ? enabled_modules.map(&:name) : enabled_modules.pluck(:name)
app/views/projects/copy.html.erb
12 12
  <label class="block"><%= check_box_tag 'only[]', 'documents', true, :id => nil %> <%= l(:label_document_plural) %> (<%= @source_project.documents.count %>)</label>
13 13
  <label class="block"><%= check_box_tag 'only[]', 'boards', true, :id => nil %> <%= l(:label_board_plural) %> (<%= @source_project.boards.count %>)</label>
14 14
  <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>
15
  <label class="block"><%= check_box_tag 'only[]', 'news', true, :id => nil %> <%= l(:label_news_plural) %> (<%= @source_project.news.nil? ? 0 : @source_project.news.count %>)</label>
15 16
  <%= call_hook :view_projects_copy_only_items, project: @source_project, f: f  %>
16 17
  <%= hidden_field_tag 'only[]', '' %>
17 18
  <br />
test/unit/project_copy_test.rb
393 393
    assert_equal "testfile.txt", copied_document.attachments.first.filename
394 394
  end
395 395

  
396
  test "#copy should copy news" do
397
    assert @project.copy(@source_project)
398

  
399
    assert_equal 1, @project.news.size
400
    @project.news.each do |news|
401
      assert !@source_project.news.include?(news)
402
    end
403
  end
404

  
396 405
  test "#copy should change the new issues to use the copied issue categories" do
397 406
    issue = Issue.find(4)
398 407
    issue.update_attribute(:category_id, 3)
(2-2/2)