diff --git a/app/controllers/work_packages/moves_controller.rb b/app/controllers/work_packages/moves_controller.rb index 78e460b48c..560c226176 100644 --- a/app/controllers/work_packages/moves_controller.rb +++ b/app/controllers/work_packages/moves_controller.rb @@ -23,33 +23,31 @@ class WorkPackages::MovesController < ApplicationController def create prepare_for_work_package_move - if request.post? - new_type = params[:new_type_id].blank? ? nil : @target_project.types.find_by_id(params[:new_type_id]) - unsaved_work_package_ids = [] - moved_work_packages = [] - @work_packages.each do |work_package| - work_package.reload - work_package.init_journal(User.current, @notes || "") - call_hook(:controller_work_packages_move_before_save, { :params => params, :work_package => work_package, :target_project => @target_project, :copy => !!@copy }) - if r = work_package.move_to_project(@target_project, new_type, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) - moved_work_packages << r - else - unsaved_work_package_ids << work_package.id - end + new_type = params[:new_type_id].blank? ? nil : @target_project.types.find_by_id(params[:new_type_id]) + unsaved_work_package_ids = [] + moved_work_packages = [] + @work_packages.each do |work_package| + work_package.reload + work_package.init_journal(User.current, @notes || "") + call_hook(:controller_work_packages_move_before_save, { :params => params, :work_package => work_package, :target_project => @target_project, :copy => !!@copy }) + if r = work_package.move_to_project(@target_project, new_type, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)}) + moved_work_packages << r + else + unsaved_work_package_ids << work_package.id end - set_flash_from_bulk_work_package_save(@work_packages, unsaved_work_package_ids) + end + set_flash_from_bulk_work_package_save(@work_packages, unsaved_work_package_ids) - if params[:follow] - if @work_packages.size == 1 && moved_work_packages.size == 1 - redirect_to work_package_path(moved_work_packages.first) - else - redirect_to project_issues_path(@target_project || @project) - end + if params[:follow] + if @work_packages.size == 1 && moved_work_packages.size == 1 + redirect_to work_package_path(moved_work_packages.first) else - redirect_to project_issues_path(@project) + redirect_to project_issues_path(@target_project || @project) end - return + else + redirect_to project_issues_path(@project) end + return end def set_flash_from_bulk_work_package_save(work_packages, unsaved_work_package_ids) @@ -71,7 +69,8 @@ class WorkPackages::MovesController < ApplicationController # Filter for bulk work package operations def find_work_packages - @work_packages = WorkPackage.find_all_by_id(params[:work_package_id] || params[:ids]) + @work_packages = WorkPackage.includes(:project) + .find_all_by_id(params[:work_package_id] || params[:ids]) raise ActiveRecord::RecordNotFound if @work_packages.empty? @projects = @work_packages.collect(&:project).compact.uniq @project = @projects.first if @projects.size == 1 diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb index 3e3bf45325..ecb10ae643 100644 --- a/app/controllers/work_packages_controller.rb +++ b/app/controllers/work_packages_controller.rb @@ -41,7 +41,6 @@ class WorkPackagesController < ApplicationController before_filter :authorize, :assign_planning_elements before_filter :apply_at_timestamp, :only => [:show] - before_filter :build_new_work_package_from_params, :only => [:new] helper :timelines helper :timelines_journals @@ -309,42 +308,4 @@ class WorkPackagesController < ApplicationController render_errors(:at => 'unknown format') end - private - - def build_new_work_package_from_params - if params[:id].blank? - @work_package = WorkPackage.new - @work_package.copy_from(params[:copy_from]) if params[:copy_from] - else - @work_package = @project.work_packages.visible.find(params[:id]) - end - - @work_package.project = @project - # Type must be set before custom field values - @work_package.type ||= @project.types.find((params[:issue] && params[:issue][:type_id]) || params[:type_id] || :first) - - #if @work_package.type.nil? - # render_error l(:error_no_type_in_project) - # return false - #end - - @work_package.start_date ||= User.current.today if Setting.issue_startdate_is_adddate? - - if params[:issue].is_a?(Hash) - @work_package.safe_attributes = params[:issue] - @work_package.priority_id = params[:issue][:priority_id] unless params[:issue][:priority_id].nil? - if User.current.allowed_to?(:add_work_package_watchers, @project) && @issue.new_record? - @work_package.watcher_user_ids = params[:issue]['watcher_user_ids'] - end - end - - # Copy watchers if we're copying a work package - if params[:copy_from] && User.current.allowed_to?(:add_work_package_watchers, @project) - @work_package.watcher_user_ids = WorkPackage.visible.find(params[:copy_from]).watcher_user_ids - end - - @work_package.author = User.current - @priorities = IssuePriority.all - @allowed_statuses = @work_package.new_statuses_allowed_to(User.current, true) - end end