Mercurial > hg > soundsoftware-site
diff app/models/issue.rb @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | e248c7af89ec |
children | fb9a13467253 |
line wrap: on
line diff
--- a/app/models/issue.rb Tue Sep 09 09:28:31 2014 +0100 +++ b/app/models/issue.rb Tue Sep 09 09:29:00 2014 +0100 @@ -38,7 +38,7 @@ }, :readonly => true - has_many :time_entries, :dependent => :delete_all + has_many :time_entries, :dependent => :destroy has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all @@ -200,7 +200,7 @@ # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields def available_custom_fields - (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : [] + (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields) : [] end def visible_custom_field_values(user=nil) @@ -483,6 +483,11 @@ end end + # Returns the custom fields that can be edited by the given user + def editable_custom_fields(user=nil) + editable_custom_field_values(user).map(&:custom_field).uniq + end + # Returns the names of attributes that are read-only for user or the current user # For users with multiple roles, the read-only fields are the intersection of # read-only fields of each role @@ -839,8 +844,10 @@ # spent_hours => 0.0 # spent_hours => 50.2 def total_spent_hours - @total_spent_hours ||= self_and_descendants.sum("#{TimeEntry.table_name}.hours", - :joins => "LEFT JOIN #{TimeEntry.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id").to_f || 0.0 + @total_spent_hours ||= + self_and_descendants. + joins("LEFT JOIN #{TimeEntry.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"). + sum("#{TimeEntry.table_name}.hours").to_f || 0.0 end def relations @@ -1222,7 +1229,7 @@ def after_project_change # Update project_id on related time entries - TimeEntry.update_all(["project_id = ?", project_id], {:issue_id => id}) + TimeEntry.where({:issue_id => id}).update_all(["project_id = ?", project_id]) # Delete issue relations unless Setting.cross_project_issue_relations? @@ -1286,7 +1293,8 @@ # issue was just created self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id) set_default_left_and_right - Issue.update_all(["root_id = ?, lft = ?, rgt = ?", root_id, lft, rgt], ["id = ?", id]) + Issue.where(["id = ?", id]). + update_all(["root_id = ?, lft = ?, rgt = ?", root_id, lft, rgt]) if @parent_issue move_to_child_of(@parent_issue) end @@ -1312,8 +1320,8 @@ self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id ) target_maxright = nested_set_scope.maximum(right_column_name) || 0 offset = target_maxright + 1 - lft - Issue.update_all(["root_id = ?, lft = lft + ?, rgt = rgt + ?", root_id, offset, offset], - ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt]) + Issue.where(["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt]). + update_all(["root_id = ?, lft = lft + ?, rgt = rgt + ?", root_id, offset, offset]) self[left_column_name] = lft + offset self[right_column_name] = rgt + offset if @parent_issue @@ -1337,7 +1345,7 @@ def recalculate_attributes_for(issue_id) if issue_id && p = Issue.find_by_id(issue_id) # priority = highest priority of children - if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority) + if priority_position = p.children.joins(:priority).maximum("#{IssuePriority.table_name}.position") p.priority = IssuePriority.find_by_position(priority_position) end @@ -1356,8 +1364,9 @@ if average == 0 average = 1 end - done = p.leaves.sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + - "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f + done = p.leaves.joins(:status). + sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + + "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f progress = done / (average * leaves_count) p.done_ratio = progress.round end