Refactor: Extract Issue#bulk_edit from the IssuesController
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3475 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
89cf2d256d
commit
f838904a7e
|
@ -267,22 +267,22 @@ class IssuesController < ApplicationController
|
|||
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
|
||||
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id])
|
||||
custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
|
||||
|
||||
# Need to merge in the records found above for Issue#bulk_edit.
|
||||
# Assuming this is done so the associations are only looked up once.
|
||||
merged_params = params.merge({
|
||||
:tracker => tracker,
|
||||
:status => status,
|
||||
:priority => priority,
|
||||
:assigned_to => assigned_to,
|
||||
:category => category,
|
||||
:fixed_version => fixed_version,
|
||||
:custom_field_values => custom_field_values
|
||||
})
|
||||
|
||||
unsaved_issue_ids = []
|
||||
@issues.each do |issue|
|
||||
journal = issue.init_journal(User.current, params[:notes])
|
||||
issue.tracker = tracker if tracker
|
||||
issue.priority = priority if priority
|
||||
issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
|
||||
issue.category = category if category || params[:category_id] == 'none'
|
||||
issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
|
||||
issue.start_date = params[:start_date] unless params[:start_date].blank?
|
||||
issue.due_date = params[:due_date] unless params[:due_date].blank?
|
||||
issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
|
||||
issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
|
||||
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
|
||||
# Don't save any change to the issue if the user is not authorized to apply the requested status
|
||||
unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
|
||||
unless issue.bulk_edit(merged_params)
|
||||
# Keep unsaved issue ids to display them in flash error
|
||||
unsaved_issue_ids << issue.id
|
||||
end
|
||||
|
|
|
@ -136,6 +136,24 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
return issue
|
||||
end
|
||||
|
||||
def bulk_edit(params)
|
||||
journal = init_journal(User.current, params[:notes])
|
||||
self.tracker = params[:tracker] if params[:tracker]
|
||||
self.priority = params[:priority] if params[:priority]
|
||||
self.assigned_to = params[:assigned_to] if params[:assigned_to] || params[:assigned_to_id] == 'none'
|
||||
self.category = params[:category] if params[:category] || params[:category_id] == 'none'
|
||||
self.fixed_version = params[:fixed_version] if params[:fixed_version] || params[:fixed_version_id] == 'none'
|
||||
self.start_date = params[:start_date] unless params[:start_date].blank?
|
||||
self.due_date = params[:due_date] unless params[:due_date].blank?
|
||||
self.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
|
||||
self.custom_field_values = params[:custom_field_values] if params[:custom_field_values] && !params[:custom_field_values].empty?
|
||||
# TODO: Edit hook name
|
||||
Redmine::Hook.call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => self })
|
||||
|
||||
# Don't save any change to the issue if the user is not authorized to apply the requested status
|
||||
return (params[:status].nil? || (new_statuses_allowed_to(User.current).include?(params[:status]) && self.status = params[:status])) && save
|
||||
end
|
||||
|
||||
def priority_id=(pid)
|
||||
self.priority = nil
|
||||
|
|
Loading…
Reference in New Issue