annotate app/controllers/issue_moves_controller.rb @ 1478:5ca1f4a47171 bibplugin_db_migrations

Close obsolete branch bibplugin_db_migrations
author Chris Cannam
date Fri, 30 Nov 2012 14:40:50 +0000
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@14 18 class IssueMovesController < ApplicationController
Chris@909 19 menu_item :issues
Chris@909 20
Chris@14 21 default_search_scope :issues
chris@37 22 before_filter :find_issues, :check_project_uniqueness
Chris@14 23 before_filter :authorize
Chris@441 24
Chris@14 25 def new
Chris@14 26 prepare_for_issue_move
Chris@14 27 render :layout => false if request.xhr?
Chris@14 28 end
Chris@14 29
Chris@14 30 def create
Chris@14 31 prepare_for_issue_move
Chris@14 32
Chris@14 33 if request.post?
Chris@14 34 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
Chris@14 35 unsaved_issue_ids = []
Chris@14 36 moved_issues = []
Chris@14 37 @issues.each do |issue|
Chris@14 38 issue.reload
Chris@14 39 issue.init_journal(User.current)
chris@37 40 issue.current_journal.notes = @notes if @notes.present?
Chris@14 41 call_hook(:controller_issues_move_before_save, { :params => params, :issue => issue, :target_project => @target_project, :copy => !!@copy })
Chris@14 42 if r = issue.move_to_project(@target_project, new_tracker, {:copy => @copy, :attributes => extract_changed_attributes_for_move(params)})
Chris@14 43 moved_issues << r
Chris@14 44 else
Chris@14 45 unsaved_issue_ids << issue.id
Chris@14 46 end
Chris@14 47 end
Chris@14 48 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
Chris@14 49
Chris@14 50 if params[:follow]
Chris@14 51 if @issues.size == 1 && moved_issues.size == 1
Chris@14 52 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
Chris@14 53 else
Chris@14 54 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
Chris@14 55 end
Chris@14 56 else
Chris@14 57 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
Chris@14 58 end
Chris@14 59 return
Chris@14 60 end
Chris@14 61 end
Chris@14 62
Chris@14 63 private
Chris@14 64
Chris@14 65 def prepare_for_issue_move
Chris@14 66 @issues.sort!
Chris@14 67 @copy = params[:copy_options] && params[:copy_options][:copy]
Chris@14 68 @allowed_projects = Issue.allowed_target_projects_on_move
Chris@14 69 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
Chris@441 70 @target_project ||= @project
Chris@14 71 @trackers = @target_project.trackers
Chris@14 72 @available_statuses = Workflow.available_statuses(@project)
chris@37 73 @notes = params[:notes]
chris@37 74 @notes ||= ''
Chris@14 75 end
Chris@14 76
Chris@14 77 def extract_changed_attributes_for_move(params)
Chris@14 78 changed_attributes = {}
chris@37 79 [:assigned_to_id, :status_id, :start_date, :due_date, :priority_id].each do |valid_attribute|
Chris@14 80 unless params[valid_attribute].blank?
Chris@14 81 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
Chris@14 82 end
Chris@14 83 end
Chris@14 84 changed_attributes
Chris@14 85 end
Chris@14 86
Chris@14 87 end