Project

General

Profile

Patch #18059 » change_activity_for_journal.diff

Marcin Świątkiewicz, 2014-10-10 13:57

View differences:

app/models/journal.rb
25 25
  has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
26 26
  attr_accessor :indice
27 27

  
28
  acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
29
                :description => :notes,
30
                :author => :user,
31
                :group => :issue,
32
                :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
33
                :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
34

  
35
  acts_as_activity_provider :type => 'issues',
36
                            :author_key => :user_id,
37
                            :find_options => {:include => [{:issue => :project}, :details, :user],
38
                                              :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
39
                                                             " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
40

  
41
  before_create :split_private_notes
28
  acts_as_event :title => :event_title,#Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
29
    :description => :notes,
30
    :author => :user,
31
    :group => :issue,
32
    :type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
33
    :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
34

  
35
    acts_as_activity_provider :type => 'issues',
36
    :author_key => :user_id,
37
    :find_options => {:include => [{:issue => :project}, :details, :user],
38
                      :conditions => @conditions}
39

  
40

  
41
    before_create :split_private_notes
42 42
  after_create :send_notification
43 43

  
44 44
  scope :visible, lambda {|*args|
45 45
    user = args.shift || User.current
46 46

  
47 47
    includes(:issue => :project).
48
      where(Issue.visible_condition(user, *args)).
49
      where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
48
    where(Issue.visible_condition(user, *args)).
49
    where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
50 50
  }
51 51

  
52
  def event_title
53
    data_for_assigned if new_status.blank? && !new_assigned.blank?
54
    data_for_status  if !new_status.blank? && new_assigned.blank?
55
    data_for_assigned_and_status if !new_assigned.blank? && !new_assigned.blank?
56
    @title = "" if @title.blank? # truncate
57
    @title
58
  end
59

  
60
  def data_for_assigned
61
    assigned = ((a = new_assigned) ? " #{a}" : nil)
62
    query_for_assigned
63
    @title =  "##{issue.id} - now assigned to : (#{assigned})"
64
  end
65

  
66
  def data_for_status
67
    status = ((s = new_status) ? " (#{s})" : nil)
68
    query_for_status
69
    @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}"
70
  end
71

  
72
  def data_for_assigned_and_status
73
    assigned = ((a = new_assigned) ? " #{a}" : nil)
74
    status = ((s = new_status) ? " (#{s})" : nil)
75
    query_for_assigned_and_status
76
    @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}. Now assigned to:(#{assigned})"
77
  end
78

  
79
  def query_for_assigned_and_status
80
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
81
      " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')" +
82
      " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
83
  end
84

  
85
  def query_for_assigned
86
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
87
      " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
88
  end
89

  
90
  def query_for_status
91
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
92
      " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"
93
  end
94

  
52 95
  def save(*args)
53 96
    # Do not save an empty journal
54 97
    (details.empty? && notes.blank?) ? false : super
......
92 135
    s ? IssueStatus.find_by_id(s.to_i) : nil
93 136
  end
94 137

  
138
  def new_assigned
139
    a = new_value_for('assigned_to_id')
140
    a ? User.find(a.to_i) : nil
141
  end
142

  
95 143
  def new_value_for(prop)
96 144
    detail_for_attribute(prop).try(:value)
97 145
  end
......
188 236

  
189 237
  def send_notification
190 238
    if notify? && (Setting.notified_events.include?('issue_updated') ||
191
        (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
192
        (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
193
        (Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
194
        (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
195
      )
239
                   (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
240
                   (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
241
                   (Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
242
                   (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
243
                   )
196 244
      Mailer.deliver_issue_edit(self)
197 245
    end
198 246
  end
(4-4/6)