##// END OF EJS Templates
The ability to change the issue status to the same status is no longer forced....
Jean-Philippe Lang -
r467:feb973b97052
parent child
Show More
@@ -1,60 +1,58
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssueStatus < ActiveRecord::Base
19 19 before_destroy :check_integrity
20 20 has_many :workflows, :foreign_key => "old_status_id"
21 21 acts_as_list
22 22
23 23 validates_presence_of :name
24 24 validates_uniqueness_of :name
25 25 validates_format_of :name, :with => /^[\w\s\'\-]*$/i
26 26 validates_length_of :html_color, :is => 6
27 27 validates_format_of :html_color, :with => /^[a-f0-9]*$/i
28 28
29 29 def before_save
30 30 IssueStatus.update_all "is_default=#{connection.quoted_false}" if self.is_default?
31 31 end
32 32
33 33 # Returns the default status for new issues
34 34 def self.default
35 35 find(:first, :conditions =>["is_default=?", true])
36 36 end
37 37
38 38 # Returns an array of all statuses the given role can switch to
39 39 # Uses association cache when called more than one time
40 40 def new_statuses_allowed_to(role, tracker)
41 new_statuses = [self]
42 new_statuses += workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
41 new_statuses = workflows.select {|w| w.role_id == role.id && w.tracker_id == tracker.id}.collect{|w| w.new_status} if role && tracker
43 42 new_statuses.sort{|x, y| x.position <=> y.position }
44 43 end
45 44
46 45 # Same thing as above but uses a database query
47 46 # More efficient than the previous method if called just once
48 47 def find_new_statuses_allowed_to(role, tracker)
49 new_statuses = [self]
50 new_statuses += workflows.find(:all,
48 new_statuses = workflows.find(:all,
51 49 :include => :new_status,
52 50 :conditions => ["role_id=? and tracker_id=?", role.id, tracker.id]).collect{ |w| w.new_status } if role && tracker
53 51 new_statuses.sort{|x, y| x.position <=> y.position }
54 52 end
55 53
56 54 private
57 55 def check_integrity
58 56 raise "Can't delete status" if Issue.find(:first, :conditions => ["status_id=?", self.id])
59 57 end
60 58 end
General Comments 0
You need to be logged in to leave comments. Login now