@@ -110,7 +110,11 @@ class Issue < ActiveRecord::Base
110
110
before_validation :clear_disabled_fields
111
111
before_save :close_duplicates , :update_done_ratio_from_issue_status ,
112
112
:force_updated_on_change , :update_closed_on
113
- after_save { |issue | issue . send :after_project_change if !issue . saved_change_to_id? && issue . saved_change_to_project_id? }
113
+ after_save do |issue |
114
+ if !issue . saved_change_to_id? && issue . saved_change_to_project_id?
115
+ issue . send :after_project_change
116
+ end
117
+ end
114
118
after_save :reschedule_following_issues , :update_nested_set_attributes ,
115
119
:update_parent_attributes , :delete_selected_attachments , :create_journal
116
120
# Should be after_create but would be called before previous after_save callbacks
@@ -128,10 +132,13 @@ def self.visible_condition(user, options={})
128
132
'1=1'
129
133
when 'default'
130
134
user_ids = [ user . id ] + user . groups . pluck ( :id ) . compact
131
- "(#{ table_name } .is_private = #{ connection . quoted_false } OR #{ table_name } .author_id = #{ user . id } OR #{ table_name } .assigned_to_id IN (#{ user_ids . join ( ',' ) } ))"
135
+ "(#{ table_name } .is_private = #{ connection . quoted_false } " \
136
+ "OR #{ table_name } .author_id = #{ user . id } " \
137
+ "OR #{ table_name } .assigned_to_id IN (#{ user_ids . join ( ',' ) } ))"
132
138
when 'own'
133
139
user_ids = [ user . id ] + user . groups . pluck ( :id ) . compact
134
- "(#{ table_name } .author_id = #{ user . id } OR #{ table_name } .assigned_to_id IN (#{ user_ids . join ( ',' ) } ))"
140
+ "(#{ table_name } .author_id = #{ user . id } OR " \
141
+ "#{ table_name } .assigned_to_id IN (#{ user_ids . join ( ',' ) } ))"
135
142
else
136
143
'1=0'
137
144
end
@@ -273,8 +280,16 @@ def set_custom_field_default?(custom_value)
273
280
# Copies attributes from another issue, arg can be an id or an Issue
274
281
def copy_from ( arg , options = { } )
275
282
issue = arg . is_a? ( Issue ) ? arg : Issue . visible . find ( arg )
276
- self . attributes = issue . attributes . dup . except ( "id" , "root_id" , "parent_id" , "lft" , "rgt" , "created_on" , "updated_on" , "status_id" , "closed_on" )
277
- self . custom_field_values = issue . custom_field_values . inject ( { } ) { |h , v | h [ v . custom_field_id ] = v . value ; h }
283
+ self . attributes =
284
+ issue . attributes . dup . except (
285
+ "id" , "root_id" , "parent_id" , "lft" , "rgt" ,
286
+ "created_on" , "updated_on" , "status_id" , "closed_on"
287
+ )
288
+ self . custom_field_values =
289
+ issue . custom_field_values . inject ( { } ) do |h , v |
290
+ h [ v . custom_field_id ] = v . value
291
+ h
292
+ end
278
293
if options [ :keep_status ]
279
294
self . status = issue . status
280
295
end
@@ -662,15 +677,21 @@ def workflow_rule_by_attribute(user=nil)
662
677
return { } if roles . empty?
663
678
664
679
result = { }
665
- workflow_permissions = WorkflowPermission . where ( :tracker_id => tracker_id , :old_status_id => status_id , :role_id => roles . map ( &:id ) ) . to_a
680
+ workflow_permissions =
681
+ WorkflowPermission . where (
682
+ :tracker_id => tracker_id , :old_status_id => status_id ,
683
+ :role_id => roles . map ( &:id )
684
+ ) . to_a
666
685
if workflow_permissions . any?
667
686
workflow_rules = workflow_permissions . inject ( { } ) do |h , wp |
668
687
h [ wp . field_name ] ||= { }
669
688
h [ wp . field_name ] [ wp . role_id ] = wp . rule
670
689
h
671
690
end
672
691
fields_with_roles = { }
673
- IssueCustomField . where ( :visible => false ) . joins ( :roles ) . pluck ( :id , "role_id" ) . each do |field_id , role_id |
692
+ IssueCustomField . where ( :visible => false ) .
693
+ joins ( :roles ) . pluck ( :id , "role_id" ) .
694
+ each do |field_id , role_id |
674
695
fields_with_roles [ field_id ] ||= [ ]
675
696
fields_with_roles [ field_id ] << role_id
676
697
end
@@ -753,7 +774,12 @@ def validate_issue
753
774
errors . add :parent_issue_id , :invalid
754
775
elsif ( @parent_issue != parent ) && (
755
776
self . would_reschedule? ( @parent_issue ) ||
756
- @parent_issue . self_and_ancestors . any? { |a | a . relations_from . any? { |r | r . relation_type == IssueRelation ::TYPE_PRECEDES && r . issue_to . would_reschedule? ( self ) } }
777
+ @parent_issue . self_and_ancestors . any? do |a |
778
+ a . relations_from . any? do |r |
779
+ r . relation_type == IssueRelation ::TYPE_PRECEDES &&
780
+ r . issue_to . would_reschedule? ( self )
781
+ end
782
+ end
757
783
)
758
784
errors . add :parent_issue_id , :invalid
759
785
elsif !closed? && @parent_issue . closed?
@@ -1056,7 +1082,13 @@ def tracker_was
1056
1082
# Returns the previous assignee whenever we're before the save
1057
1083
# or in after_* callbacks
1058
1084
def previous_assignee
1059
- if previous_assigned_to_id = assigned_to_id_change_to_be_saved . nil? ? assigned_to_id_before_last_save : assigned_to_id_in_database
1085
+ previous_assigned_to_id =
1086
+ if assigned_to_id_change_to_be_saved . nil?
1087
+ assigned_to_id_before_last_save
1088
+ else
1089
+ assigned_to_id_in_database
1090
+ end
1091
+ if previous_assigned_to_id
1060
1092
Principal . find_by_id ( previous_assigned_to_id )
1061
1093
end
1062
1094
end
@@ -1137,9 +1169,15 @@ def last_notes
1137
1169
# Preloads relations for a collection of issues
1138
1170
def self . load_relations ( issues )
1139
1171
if issues . any?
1140
- relations = IssueRelation . where ( "issue_from_id IN (:ids) OR issue_to_id IN (:ids)" , :ids => issues . map ( &:id ) ) . all
1172
+ relations =
1173
+ IssueRelation . where (
1174
+ "issue_from_id IN (:ids) OR issue_to_id IN (:ids)" , :ids => issues . map ( &:id )
1175
+ ) . all
1141
1176
issues . each do |issue |
1142
- issue . instance_variable_set "@relations" , relations . select { |r | r . issue_from_id == issue . id || r . issue_to_id == issue . id }
1177
+ issue . instance_variable_set (
1178
+ "@relations" ,
1179
+ relations . select { |r | r . issue_from_id == issue . id || r . issue_to_id == issue . id }
1180
+ )
1143
1181
end
1144
1182
end
1145
1183
end
@@ -1247,7 +1285,10 @@ def blocks?(other)
1247
1285
all = [ self ]
1248
1286
last = [ self ]
1249
1287
while last . any?
1250
- current = last . map { |i | i . relations_from . where ( :relation_type => IssueRelation ::TYPE_BLOCKS ) . map ( &:issue_to ) } . flatten . uniq
1288
+ current =
1289
+ last . map do |i |
1290
+ i . relations_from . where ( :relation_type => IssueRelation ::TYPE_BLOCKS ) . map ( &:issue_to )
1291
+ end . flatten . uniq
1251
1292
current -= last
1252
1293
current -= all
1253
1294
return true if current . include? ( other )
@@ -1483,8 +1524,13 @@ def self.cross_project_scope(project, scope=nil)
1483
1524
Issue . joins ( :project ) . where ( "(#{ Project . table_name } .lft >= :lft AND #{ Project . table_name } .rgt <= :rgt)" ,
1484
1525
:lft => project . root . lft , :rgt => project . root . rgt )
1485
1526
when 'hierarchy'
1486
- 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)" ,
1487
- :lft => project . lft , :rgt => project . rgt )
1527
+ Issue . joins ( :project ) .
1528
+ where (
1529
+ "(#{ Project . table_name } .lft >= :lft AND " \
1530
+ "#{ Project . table_name } .rgt <= :rgt) OR " \
1531
+ "(#{ Project . table_name } .lft < :lft AND #{ Project . table_name } .rgt > :rgt)" ,
1532
+ :lft => project . lft , :rgt => project . rgt
1533
+ )
1488
1534
when 'descendants'
1489
1535
Issue . joins ( :project ) . where ( "(#{ Project . table_name } .lft >= :lft AND #{ Project . table_name } .rgt <= :rgt)" ,
1490
1536
:lft => project . lft , :rgt => project . rgt )
@@ -1612,7 +1658,10 @@ def user_tracker_permission?(user, permission)
1612
1658
true
1613
1659
else
1614
1660
roles = user . roles_for_project ( project ) . select { |r | r . has_permission? ( permission ) }
1615
- roles . any? { |r | r . permissions_all_trackers? ( permission ) || r . permissions_tracker_ids? ( permission , tracker_id ) }
1661
+ roles . any? do |r |
1662
+ r . permissions_all_trackers? ( permission ) ||
1663
+ r . permissions_tracker_ids? ( permission , tracker_id )
1664
+ end
1616
1665
end
1617
1666
end
1618
1667
@@ -1633,7 +1682,12 @@ def after_project_change
1633
1682
# Change project and keep project
1634
1683
child . send :project= , project , true
1635
1684
unless child . save
1636
- errors . add :base , l ( :error_move_of_child_not_possible , :child => "##{ child . id } " , :errors => child . errors . full_messages . join ( ", " ) )
1685
+ errors . add (
1686
+ :base ,
1687
+ l ( :error_move_of_child_not_possible ,
1688
+ :child => "##{ child . id } " ,
1689
+ :errors => child . errors . full_messages . join ( ", " ) )
1690
+ )
1637
1691
raise ActiveRecord ::Rollback
1638
1692
end
1639
1693
end
@@ -1645,13 +1699,22 @@ def after_project_change
1645
1699
def after_create_from_copy
1646
1700
return unless copy? && !@after_create_from_copy_handled
1647
1701
1648
- if ( @copied_from . project_id == project_id || Setting . cross_project_issue_relations? ) && @copy_options [ :link ] != false
1702
+ if ( @copied_from . project_id == project_id ||
1703
+ Setting . cross_project_issue_relations? ) &&
1704
+ @copy_options [ :link ] != false
1649
1705
if @current_journal
1650
1706
@copied_from . init_journal ( @current_journal . user )
1651
1707
end
1652
- relation = IssueRelation . new ( :issue_from => @copied_from , :issue_to => self , :relation_type => IssueRelation ::TYPE_COPIED_TO )
1708
+ relation =
1709
+ IssueRelation . new ( :issue_from => @copied_from , :issue_to => self ,
1710
+ :relation_type => IssueRelation ::TYPE_COPIED_TO )
1653
1711
unless relation . save
1654
- logger . error "Could not create relation while copying ##{ @copied_from . id } to ##{ id } due to validation errors: #{ relation . errors . full_messages . join ( ', ' ) } " if logger
1712
+ if logger
1713
+ logger . error (
1714
+ "Could not create relation while copying ##{ @copied_from . id } to ##{ id } " \
1715
+ "due to validation errors: #{ relation . errors . full_messages . join ( ', ' ) } "
1716
+ )
1717
+ end
1655
1718
end
1656
1719
end
1657
1720
@@ -1666,7 +1729,12 @@ def after_create_from_copy
1666
1729
1667
1730
# Do not copy subtasks that are not visible to avoid potential disclosure of private data
1668
1731
unless child . visible?
1669
- logger . error "Subtask ##{ child . id } was not copied during ##{ @copied_from . id } copy because it is not visible to the current user" if logger
1732
+ if logger
1733
+ logger . error (
1734
+ "Subtask ##{ child . id } was not copied during ##{ @copied_from . id } copy " \
1735
+ "because it is not visible to the current user"
1736
+ )
1737
+ end
1670
1738
next
1671
1739
end
1672
1740
copy = Issue . new . copy_from ( child , copy_options )
@@ -1676,10 +1744,21 @@ def after_create_from_copy
1676
1744
copy . author = author
1677
1745
copy . project = project
1678
1746
copy . parent_issue_id = copied_issue_ids [ child . parent_id ]
1679
- copy . fixed_version_id = nil unless child . fixed_version . present? && child . fixed_version . status == 'open'
1680
- copy . assigned_to = nil unless child . assigned_to_id . present? && child . assigned_to . status == User ::STATUS_ACTIVE
1747
+ unless child . fixed_version . present? && child . fixed_version . status == 'open'
1748
+ copy . fixed_version_id = nil
1749
+ end
1750
+ unless child . assigned_to_id . present? &&
1751
+ child . assigned_to . status == User ::STATUS_ACTIVE
1752
+ copy . assigned_to = nil
1753
+ end
1681
1754
unless copy . save
1682
- 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
1755
+ if logger
1756
+ logger . error (
1757
+ "Could not copy subtask ##{ child . id } " \
1758
+ "while copying ##{ @copied_from . id } to ##{ id } due to validation errors: " \
1759
+ "#{ copy . errors . full_messages . join ( ', ' ) } "
1760
+ )
1761
+ end
1683
1762
next
1684
1763
end
1685
1764
copied_issue_ids [ child . id ] = copy . id
@@ -1720,7 +1799,8 @@ def recalculate_attributes_for(issue_id)
1720
1799
if p . priority_derived?
1721
1800
# priority = highest priority of open children
1722
1801
# priority is left unchanged if all children are closed and there's no default priority defined
1723
- if priority_position = p . children . open . joins ( :priority ) . maximum ( "#{ IssuePriority . table_name } .position" )
1802
+ if priority_position =
1803
+ p . children . open . joins ( :priority ) . maximum ( "#{ IssuePriority . table_name } .position" )
1724
1804
p . priority = IssuePriority . find_by_position ( priority_position )
1725
1805
elsif default_priority = IssuePriority . default
1726
1806
p . priority = default_priority
@@ -1743,7 +1823,9 @@ def recalculate_attributes_for(issue_id)
1743
1823
if children . any?
1744
1824
child_with_total_estimated_hours = children . select { |c | c . total_estimated_hours . to_f > 0.0 }
1745
1825
if child_with_total_estimated_hours . any?
1746
- average = child_with_total_estimated_hours . sum ( &:total_estimated_hours ) . to_d / child_with_total_estimated_hours . count
1826
+ average =
1827
+ child_with_total_estimated_hours . sum ( &:total_estimated_hours ) . to_d /
1828
+ child_with_total_estimated_hours . count
1747
1829
else
1748
1830
average = 1.0 . to_d
1749
1831
end
0 commit comments