Defect #38023
Model hook: model_project_copy_before_save misses options[:only]
Status: | New | Start date: | ||
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | Projects | |||
Target version: | - | |||
Resolution: | Affected version: | 5.0.3 |
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.