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