Mercurial > hg > soundsoftware-site
comparison app/models/.svn/text-base/issue_status.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | cca12e1c1fd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # redMine - project management software | |
2 # Copyright (C) 2006 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 class IssueStatus < ActiveRecord::Base | |
19 before_destroy :check_integrity | |
20 has_many :workflows, :foreign_key => "old_status_id", :dependent => :delete_all | |
21 acts_as_list | |
22 | |
23 validates_presence_of :name | |
24 validates_uniqueness_of :name | |
25 validates_length_of :name, :maximum => 30 | |
26 validates_format_of :name, :with => /^[\w\s\'\-]*$/i | |
27 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true | |
28 | |
29 def after_save | |
30 IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? | |
31 end | |
32 | |
33 # Returns the default status for new issues | |
34 def self.default | |
35 find(:first, :conditions =>["is_default=?", true]) | |
36 end | |
37 | |
38 # Update all the +Issues+ setting their done_ratio to the value of their +IssueStatus+ | |
39 def self.update_issue_done_ratios | |
40 if Issue.use_status_for_done_ratio? | |
41 IssueStatus.find(:all, :conditions => ["default_done_ratio >= 0"]).each do |status| | |
42 Issue.update_all(["done_ratio = ?", status.default_done_ratio], | |
43 ["status_id = ?", status.id]) | |
44 end | |
45 end | |
46 | |
47 return Issue.use_status_for_done_ratio? | |
48 end | |
49 | |
50 # Returns an array of all statuses the given role can switch to | |
51 # Uses association cache when called more than one time | |
52 def new_statuses_allowed_to(roles, tracker) | |
53 if roles && tracker | |
54 role_ids = roles.collect(&:id) | |
55 new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort | |
56 else | |
57 [] | |
58 end | |
59 end | |
60 | |
61 # Same thing as above but uses a database query | |
62 # More efficient than the previous method if called just once | |
63 def find_new_statuses_allowed_to(roles, tracker) | |
64 if roles && tracker | |
65 workflows.find(:all, | |
66 :include => :new_status, | |
67 :conditions => { :role_id => roles.collect(&:id), | |
68 :tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort | |
69 else | |
70 [] | |
71 end | |
72 end | |
73 | |
74 def new_status_allowed_to?(status, roles, tracker) | |
75 if status && roles && tracker | |
76 !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil? | |
77 else | |
78 false | |
79 end | |
80 end | |
81 | |
82 def <=>(status) | |
83 position <=> status.position | |
84 end | |
85 | |
86 def to_s; name end | |
87 | |
88 private | |
89 def check_integrity | |
90 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id]) | |
91 end | |
92 end |