Mercurial > hg > soundsoftware-site
comparison app/models/issue_status.rb @ 514:7eba09d624db live
Merge
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:50:53 +0100 |
parents | 0c939c159af4 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
512:b9aebdd7dd40 | 514:7eba09d624db |
---|---|
23 before_destroy :delete_workflows | 23 before_destroy :delete_workflows |
24 | 24 |
25 validates_presence_of :name | 25 validates_presence_of :name |
26 validates_uniqueness_of :name | 26 validates_uniqueness_of :name |
27 validates_length_of :name, :maximum => 30 | 27 validates_length_of :name, :maximum => 30 |
28 validates_format_of :name, :with => /^[\w\s\'\-]*$/i | |
29 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true | 28 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true |
29 | |
30 named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
30 | 31 |
31 def after_save | 32 def after_save |
32 IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? | 33 IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? |
33 end | 34 end |
34 | 35 |
49 return Issue.use_status_for_done_ratio? | 50 return Issue.use_status_for_done_ratio? |
50 end | 51 end |
51 | 52 |
52 # Returns an array of all statuses the given role can switch to | 53 # Returns an array of all statuses the given role can switch to |
53 # Uses association cache when called more than one time | 54 # Uses association cache when called more than one time |
54 def new_statuses_allowed_to(roles, tracker) | 55 def new_statuses_allowed_to(roles, tracker, author=false, assignee=false) |
55 if roles && tracker | 56 if roles && tracker |
56 role_ids = roles.collect(&:id) | 57 role_ids = roles.collect(&:id) |
57 new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort | 58 transitions = workflows.select do |w| |
59 role_ids.include?(w.role_id) && | |
60 w.tracker_id == tracker.id && | |
61 (author || !w.author) && | |
62 (assignee || !w.assignee) | |
63 end | |
64 transitions.collect{|w| w.new_status}.compact.sort | |
58 else | 65 else |
59 [] | 66 [] |
60 end | 67 end |
61 end | 68 end |
62 | 69 |
63 # Same thing as above but uses a database query | 70 # Same thing as above but uses a database query |
64 # More efficient than the previous method if called just once | 71 # More efficient than the previous method if called just once |
65 def find_new_statuses_allowed_to(roles, tracker) | 72 def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) |
66 if roles && tracker | 73 if roles && tracker |
74 conditions = {:role_id => roles.collect(&:id), :tracker_id => tracker.id} | |
75 conditions[:author] = false unless author | |
76 conditions[:assignee] = false unless assignee | |
77 | |
67 workflows.find(:all, | 78 workflows.find(:all, |
68 :include => :new_status, | 79 :include => :new_status, |
69 :conditions => { :role_id => roles.collect(&:id), | 80 :conditions => conditions).collect{|w| w.new_status}.compact.sort |
70 :tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort | |
71 else | 81 else |
72 [] | 82 [] |
73 end | |
74 end | |
75 | |
76 def new_status_allowed_to?(status, roles, tracker) | |
77 if status && roles && tracker | |
78 !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil? | |
79 else | |
80 false | |
81 end | 83 end |
82 end | 84 end |
83 | 85 |
84 def <=>(status) | 86 def <=>(status) |
85 position <=> status.position | 87 position <=> status.position |