summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>2020-12-17 13:11:05 +0000
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>2020-12-17 13:11:05 +0000
commitca099daae2176c27464dfb697c0d0e800d1b565e (patch)
treea97ed28d1160843708f8d2c0d3fba40a1abb966a
parentc3054233ab2d38b13cac4b2f7de061769c62cbc6 (diff)
downloadredmine-ca099daae2176c27464dfb697c0d0e800d1b565e.tar.gz
redmine-ca099daae2176c27464dfb697c0d0e800d1b565e.zip
shorten long line of app/models/issue.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@20663 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue.rb132
1 files changed, 107 insertions, 25 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 6132f71e6..8ba261bb1 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -110,7 +110,11 @@ class Issue < ActiveRecord::Base
before_validation :clear_disabled_fields
before_save :close_duplicates, :update_done_ratio_from_issue_status,
:force_updated_on_change, :update_closed_on
- after_save {|issue| issue.send :after_project_change if !issue.saved_change_to_id? && issue.saved_change_to_project_id?}
+ after_save do |issue|
+ if !issue.saved_change_to_id? && issue.saved_change_to_project_id?
+ issue.send :after_project_change
+ end
+ end
after_save :reschedule_following_issues, :update_nested_set_attributes,
:update_parent_attributes, :delete_selected_attachments, :create_journal
# Should be after_create but would be called before previous after_save callbacks
@@ -128,10 +132,13 @@ class Issue < ActiveRecord::Base
'1=1'
when 'default'
user_ids = [user.id] + user.groups.pluck(:id).compact
- "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
+ "(#{table_name}.is_private = #{connection.quoted_false} " \
+ "OR #{table_name}.author_id = #{user.id} " \
+ "OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
when 'own'
user_ids = [user.id] + user.groups.pluck(:id).compact
- "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
+ "(#{table_name}.author_id = #{user.id} OR " \
+ "#{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
else
'1=0'
end
@@ -273,8 +280,16 @@ class Issue < ActiveRecord::Base
# Copies attributes from another issue, arg can be an id or an Issue
def copy_from(arg, options={})
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
- self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on", "status_id", "closed_on")
- self.custom_field_values = issue.custom_field_values.inject({}) {|h, v| h[v.custom_field_id] = v.value; h}
+ self.attributes =
+ issue.attributes.dup.except(
+ "id", "root_id", "parent_id", "lft", "rgt",
+ "created_on", "updated_on", "status_id", "closed_on"
+ )
+ self.custom_field_values =
+ issue.custom_field_values.inject({}) do |h, v|
+ h[v.custom_field_id] = v.value
+ h
+ end
if options[:keep_status]
self.status = issue.status
end
@@ -662,7 +677,11 @@ class Issue < ActiveRecord::Base
return {} if roles.empty?
result = {}
- workflow_permissions = WorkflowPermission.where(:tracker_id => tracker_id, :old_status_id => status_id, :role_id => roles.map(&:id)).to_a
+ workflow_permissions =
+ WorkflowPermission.where(
+ :tracker_id => tracker_id, :old_status_id => status_id,
+ :role_id => roles.map(&:id)
+ ).to_a
if workflow_permissions.any?
workflow_rules = workflow_permissions.inject({}) do |h, wp|
h[wp.field_name] ||= {}
@@ -670,7 +689,9 @@ class Issue < ActiveRecord::Base
h
end
fields_with_roles = {}
- IssueCustomField.where(:visible => false).joins(:roles).pluck(:id, "role_id").each do |field_id, role_id|
+ IssueCustomField.where(:visible => false).
+ joins(:roles).pluck(:id, "role_id").
+ each do |field_id, role_id|
fields_with_roles[field_id] ||= []
fields_with_roles[field_id] << role_id
end
@@ -753,7 +774,12 @@ class Issue < ActiveRecord::Base
errors.add :parent_issue_id, :invalid
elsif (@parent_issue != parent) && (
self.would_reschedule?(@parent_issue) ||
- @parent_issue.self_and_ancestors.any? {|a| a.relations_from.any? {|r| r.relation_type == IssueRelation::TYPE_PRECEDES && r.issue_to.would_reschedule?(self)}}
+ @parent_issue.self_and_ancestors.any? do |a|
+ a.relations_from.any? do |r|
+ r.relation_type == IssueRelation::TYPE_PRECEDES &&
+ r.issue_to.would_reschedule?(self)
+ end
+ end
)
errors.add :parent_issue_id, :invalid
elsif !closed? && @parent_issue.closed?
@@ -1056,7 +1082,13 @@ class Issue < ActiveRecord::Base
# Returns the previous assignee whenever we're before the save
# or in after_* callbacks
def previous_assignee
- if previous_assigned_to_id = assigned_to_id_change_to_be_saved.nil? ? assigned_to_id_before_last_save : assigned_to_id_in_database
+ previous_assigned_to_id =
+ if assigned_to_id_change_to_be_saved.nil?
+ assigned_to_id_before_last_save
+ else
+ assigned_to_id_in_database
+ end
+ if previous_assigned_to_id
Principal.find_by_id(previous_assigned_to_id)
end
end
@@ -1137,9 +1169,15 @@ class Issue < ActiveRecord::Base
# Preloads relations for a collection of issues
def self.load_relations(issues)
if issues.any?
- relations = IssueRelation.where("issue_from_id IN (:ids) OR issue_to_id IN (:ids)", :ids => issues.map(&:id)).all
+ relations =
+ IssueRelation.where(
+ "issue_from_id IN (:ids) OR issue_to_id IN (:ids)", :ids => issues.map(&:id)
+ ).all
issues.each do |issue|
- issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
+ issue.instance_variable_set(
+ "@relations",
+ relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
+ )
end
end
end
@@ -1247,7 +1285,10 @@ class Issue < ActiveRecord::Base
all = [self]
last = [self]
while last.any?
- current = last.map {|i| i.relations_from.where(:relation_type => IssueRelation::TYPE_BLOCKS).map(&:issue_to)}.flatten.uniq
+ current =
+ last.map do |i|
+ i.relations_from.where(:relation_type => IssueRelation::TYPE_BLOCKS).map(&:issue_to)
+ end.flatten.uniq
current -= last
current -= all
return true if current.include?(other)
@@ -1483,8 +1524,13 @@ class Issue < ActiveRecord::Base
Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)",
:lft => project.root.lft, :rgt => project.root.rgt)
when 'hierarchy'
- Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt) OR (#{Project.table_name}.lft < :lft AND #{Project.table_name}.rgt > :rgt)",
- :lft => project.lft, :rgt => project.rgt)
+ Issue.joins(:project).
+ where(
+ "(#{Project.table_name}.lft >= :lft AND " \
+ "#{Project.table_name}.rgt <= :rgt) OR " \
+ "(#{Project.table_name}.lft < :lft AND #{Project.table_name}.rgt > :rgt)",
+ :lft => project.lft, :rgt => project.rgt
+ )
when 'descendants'
Issue.joins(:project).where("(#{Project.table_name}.lft >= :lft AND #{Project.table_name}.rgt <= :rgt)",
:lft => project.lft, :rgt => project.rgt)
@@ -1612,7 +1658,10 @@ class Issue < ActiveRecord::Base
true
else
roles = user.roles_for_project(project).select {|r| r.has_permission?(permission)}
- roles.any? {|r| r.permissions_all_trackers?(permission) || r.permissions_tracker_ids?(permission, tracker_id)}
+ roles.any? do |r|
+ r.permissions_all_trackers?(permission) ||
+ r.permissions_tracker_ids?(permission, tracker_id)
+ end
end
end
@@ -1633,7 +1682,12 @@ class Issue < ActiveRecord::Base
# Change project and keep project
child.send :project=, project, true
unless child.save
- errors.add :base, l(:error_move_of_child_not_possible, :child => "##{child.id}", :errors => child.errors.full_messages.join(", "))
+ errors.add(
+ :base,
+ l(:error_move_of_child_not_possible,
+ :child => "##{child.id}",
+ :errors => child.errors.full_messages.join(", "))
+ )
raise ActiveRecord::Rollback
end
end
@@ -1645,13 +1699,22 @@ class Issue < ActiveRecord::Base
def after_create_from_copy
return unless copy? && !@after_create_from_copy_handled
- if (@copied_from.project_id == project_id || Setting.cross_project_issue_relations?) && @copy_options[:link] != false
+ if (@copied_from.project_id == project_id ||
+ Setting.cross_project_issue_relations?) &&
+ @copy_options[:link] != false
if @current_journal
@copied_from.init_journal(@current_journal.user)
end
- relation = IssueRelation.new(:issue_from => @copied_from, :issue_to => self, :relation_type => IssueRelation::TYPE_COPIED_TO)
+ relation =
+ IssueRelation.new(:issue_from => @copied_from, :issue_to => self,
+ :relation_type => IssueRelation::TYPE_COPIED_TO)
unless relation.save
- logger.error "Could not create relation while copying ##{@copied_from.id} to ##{id} due to validation errors: #{relation.errors.full_messages.join(', ')}" if logger
+ if logger
+ logger.error(
+ "Could not create relation while copying ##{@copied_from.id} to ##{id} " \
+ "due to validation errors: #{relation.errors.full_messages.join(', ')}"
+ )
+ end
end
end
@@ -1666,7 +1729,12 @@ class Issue < ActiveRecord::Base
# Do not copy subtasks that are not visible to avoid potential disclosure of private data
unless child.visible?
- logger.error "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy because it is not visible to the current user" if logger
+ if logger
+ logger.error(
+ "Subtask ##{child.id} was not copied during ##{@copied_from.id} copy " \
+ "because it is not visible to the current user"
+ )
+ end
next
end
copy = Issue.new.copy_from(child, copy_options)
@@ -1676,10 +1744,21 @@ class Issue < ActiveRecord::Base
copy.author = author
copy.project = project
copy.parent_issue_id = copied_issue_ids[child.parent_id]
- copy.fixed_version_id = nil unless child.fixed_version.present? && child.fixed_version.status == 'open'
- copy.assigned_to = nil unless child.assigned_to_id.present? && child.assigned_to.status == User::STATUS_ACTIVE
+ unless child.fixed_version.present? && child.fixed_version.status == 'open'
+ copy.fixed_version_id = nil
+ end
+ unless child.assigned_to_id.present? &&
+ child.assigned_to.status == User::STATUS_ACTIVE
+ copy.assigned_to = nil
+ end
unless copy.save
- logger.error "Could not copy subtask ##{child.id} while copying ##{@copied_from.id} to ##{id} due to validation errors: #{copy.errors.full_messages.join(', ')}" if logger
+ if logger
+ logger.error(
+ "Could not copy subtask ##{child.id} " \
+ "while copying ##{@copied_from.id} to ##{id} due to validation errors: " \
+ "#{copy.errors.full_messages.join(', ')}"
+ )
+ end
next
end
copied_issue_ids[child.id] = copy.id
@@ -1720,7 +1799,8 @@ class Issue < ActiveRecord::Base
if p.priority_derived?
# priority = highest priority of open children
# priority is left unchanged if all children are closed and there's no default priority defined
- if priority_position = p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position")
+ if priority_position =
+ p.children.open.joins(:priority).maximum("#{IssuePriority.table_name}.position")
p.priority = IssuePriority.find_by_position(priority_position)
elsif default_priority = IssuePriority.default
p.priority = default_priority
@@ -1743,7 +1823,9 @@ class Issue < ActiveRecord::Base
if children.any?
child_with_total_estimated_hours = children.select {|c| c.total_estimated_hours.to_f > 0.0}
if child_with_total_estimated_hours.any?
- average = child_with_total_estimated_hours.sum(&:total_estimated_hours).to_d / child_with_total_estimated_hours.count
+ average =
+ child_with_total_estimated_hours.sum(&:total_estimated_hours).to_d /
+ child_with_total_estimated_hours.count
else
average = 1.0.to_d
end