annotate .svn/pristine/14/14fc658e5b9713c5a1ccf4d137bc5d9602c668ab.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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