annotate .svn/pristine/a4/a4c45a7af3a5e670c765d740cec096dac5d5314d.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 class IssueStatus < ActiveRecord::Base
Chris@1296 19 before_destroy :check_integrity
Chris@1296 20 has_many :workflows, :class_name => 'WorkflowTransition', :foreign_key => "old_status_id"
Chris@1296 21 acts_as_list
Chris@1296 22
Chris@1296 23 before_destroy :delete_workflow_rules
Chris@1296 24 after_save :update_default
Chris@1296 25
Chris@1296 26 validates_presence_of :name
Chris@1296 27 validates_uniqueness_of :name
Chris@1296 28 validates_length_of :name, :maximum => 30
Chris@1296 29 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
Chris@1296 30
Chris@1296 31 scope :sorted, order("#{table_name}.position ASC")
Chris@1296 32 scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
Chris@1296 33
Chris@1296 34 def update_default
Chris@1296 35 IssueStatus.update_all({:is_default => false}, ['id <> ?', id]) if self.is_default?
Chris@1296 36 end
Chris@1296 37
Chris@1296 38 # Returns the default status for new issues
Chris@1296 39 def self.default
Chris@1296 40 where(:is_default => true).first
Chris@1296 41 end
Chris@1296 42
Chris@1296 43 # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+
Chris@1296 44 def self.update_issue_done_ratios
Chris@1296 45 if Issue.use_status_for_done_ratio?
Chris@1296 46 IssueStatus.where("default_done_ratio >= 0").all.each do |status|
Chris@1296 47 Issue.update_all({:done_ratio => status.default_done_ratio}, {:status_id => status.id})
Chris@1296 48 end
Chris@1296 49 end
Chris@1296 50
Chris@1296 51 return Issue.use_status_for_done_ratio?
Chris@1296 52 end
Chris@1296 53
Chris@1296 54 # Returns an array of all statuses the given role can switch to
Chris@1296 55 # Uses association cache when called more than one time
Chris@1296 56 def new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
Chris@1296 57 if roles && tracker
Chris@1296 58 role_ids = roles.collect(&:id)
Chris@1296 59 transitions = workflows.select do |w|
Chris@1296 60 role_ids.include?(w.role_id) &&
Chris@1296 61 w.tracker_id == tracker.id &&
Chris@1296 62 ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee))
Chris@1296 63 end
Chris@1296 64 transitions.map(&:new_status).compact.sort
Chris@1296 65 else
Chris@1296 66 []
Chris@1296 67 end
Chris@1296 68 end
Chris@1296 69
Chris@1296 70 # Same thing as above but uses a database query
Chris@1296 71 # More efficient than the previous method if called just once
Chris@1296 72 def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false)
Chris@1296 73 if roles.present? && tracker
Chris@1296 74 conditions = "(author = :false AND assignee = :false)"
Chris@1296 75 conditions << " OR author = :true" if author
Chris@1296 76 conditions << " OR assignee = :true" if assignee
Chris@1296 77
Chris@1296 78 workflows.
Chris@1296 79 includes(:new_status).
Chris@1296 80 where(["role_id IN (:role_ids) AND tracker_id = :tracker_id AND (#{conditions})",
Chris@1296 81 {:role_ids => roles.collect(&:id), :tracker_id => tracker.id, :true => true, :false => false}
Chris@1296 82 ]).all.
Chris@1296 83 map(&:new_status).compact.sort
Chris@1296 84 else
Chris@1296 85 []
Chris@1296 86 end
Chris@1296 87 end
Chris@1296 88
Chris@1296 89 def <=>(status)
Chris@1296 90 position <=> status.position
Chris@1296 91 end
Chris@1296 92
Chris@1296 93 def to_s; name end
Chris@1296 94
Chris@1296 95 private
Chris@1296 96
Chris@1296 97 def check_integrity
Chris@1296 98 raise "Can't delete status" if Issue.where(:status_id => id).any?
Chris@1296 99 end
Chris@1296 100
Chris@1296 101 # Deletes associated workflows
Chris@1296 102 def delete_workflow_rules
Chris@1296 103 WorkflowRule.delete_all(["old_status_id = :id OR new_status_id = :id", {:id => id}])
Chris@1296 104 end
Chris@1296 105 end