Project

General

Profile

Actions

Defect #38023

open

Model hook: model_project_copy_before_save misses options[:only]

Added by Liane Hampe over 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Projects
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

The model hook is implemented in Project#copy:

  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 documents)
    to_be_copied = to_be_copied & Array.wrap(options[:only]) unless options[:only].nil?
    Project.transaction do
      if save
        reload
        self.attachments = project.attachments.map do |attachment|
          attachment.copy(:container => self)
        end
        to_be_copied.each do |name|
          send "copy_#{name}", project
        end

        Redmine::Hook.call_hook(:model_project_copy_before_save,
                                :source_project => project,
                                :destination_project => self) <--- No options[:only] containing modules selected to be copied!!!!
        save
      else
        false
      end
    end
  end

This is my proposal for the hook above:

def copy(project, options={})
  project = project.is_a?(Project) ? project : Project.find(project)
  selection = options[:only]
  to_be_copied = %w[members wiki versions issue_categories issues queries boards documents]
  to_be_copied = to_be_copied & Array.wrap(selection) if selection

   Project.transaction do
     if save
       reload

        self.attachments = project.attachments.map do |attachment|
          attachment.copy(container: self)
        end

        to_be_copied.each do |name|
          send "copy_#{name}", project
        end

        Redmine::Hook.call_hook(:model_project_copy_before_save,
                                 source_project: project,
                                 destination_project: self,
                                 selection: selection)
        save
      else
        false
    end
  end
end

It affects all (latest) Redmine Versions.

No data to display

Actions

Also available in: Atom PDF