Mercurial > hg > soundsoftware-site
diff app/models/issue_status.rb @ 511:107d36338b70 live
Merge from branch "cannam"
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:43:07 +0100 |
parents | 0c939c159af4 |
children | cbb26bc654de |
line wrap: on
line diff
--- a/app/models/issue_status.rb Thu Jun 09 16:51:06 2011 +0100 +++ b/app/models/issue_status.rb Thu Jul 14 10:43:07 2011 +0100 @@ -25,8 +25,9 @@ validates_presence_of :name validates_uniqueness_of :name validates_length_of :name, :maximum => 30 - validates_format_of :name, :with => /^[\w\s\'\-]*$/i validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true + + named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} def after_save IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? @@ -51,10 +52,16 @@ # Returns an array of all statuses the given role can switch to # Uses association cache when called more than one time - def new_statuses_allowed_to(roles, tracker) + def new_statuses_allowed_to(roles, tracker, author=false, assignee=false) if roles && tracker role_ids = roles.collect(&:id) - new_statuses = workflows.select {|w| role_ids.include?(w.role_id) && w.tracker_id == tracker.id}.collect{|w| w.new_status}.compact.sort + transitions = workflows.select do |w| + role_ids.include?(w.role_id) && + w.tracker_id == tracker.id && + (author || !w.author) && + (assignee || !w.assignee) + end + transitions.collect{|w| w.new_status}.compact.sort else [] end @@ -62,24 +69,19 @@ # Same thing as above but uses a database query # More efficient than the previous method if called just once - def find_new_statuses_allowed_to(roles, tracker) + def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) if roles && tracker + conditions = {:role_id => roles.collect(&:id), :tracker_id => tracker.id} + conditions[:author] = false unless author + conditions[:assignee] = false unless assignee + workflows.find(:all, :include => :new_status, - :conditions => { :role_id => roles.collect(&:id), - :tracker_id => tracker.id}).collect{ |w| w.new_status }.compact.sort + :conditions => conditions).collect{|w| w.new_status}.compact.sort else [] end end - - def new_status_allowed_to?(status, roles, tracker) - if status && roles && tracker - !workflows.find(:first, :conditions => {:new_status_id => status.id, :role_id => roles.collect(&:id), :tracker_id => tracker.id}).nil? - else - false - end - end def <=>(status) position <=> status.position