Patch #18059 » change_activity_for_journal.diff
| app/models/journal.rb | ||
|---|---|---|
|
has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
|
||
|
attr_accessor :indice
|
||
|
acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
|
||
|
:description => :notes,
|
||
|
:author => :user,
|
||
|
:group => :issue,
|
||
|
:type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
|
||
|
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
|
||
|
acts_as_activity_provider :type => 'issues',
|
||
|
:author_key => :user_id,
|
||
|
:find_options => {:include => [{:issue => :project}, :details, :user],
|
||
|
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||
|
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
|
||
|
before_create :split_private_notes
|
||
|
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}" },
|
||
|
:description => :notes,
|
||
|
:author => :user,
|
||
|
:group => :issue,
|
||
|
:type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
|
||
|
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
|
||
|
acts_as_activity_provider :type => 'issues',
|
||
|
:author_key => :user_id,
|
||
|
:find_options => {:include => [{:issue => :project}, :details, :user],
|
||
|
:conditions => @conditions}
|
||
|
before_create :split_private_notes
|
||
|
after_create :send_notification
|
||
|
scope :visible, lambda {|*args|
|
||
|
user = args.shift || User.current
|
||
|
includes(:issue => :project).
|
||
|
where(Issue.visible_condition(user, *args)).
|
||
|
where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
|
||
|
where(Issue.visible_condition(user, *args)).
|
||
|
where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
|
||
|
}
|
||
|
def event_title
|
||
|
data_for_assigned if new_status.blank? && !new_assigned.blank?
|
||
|
data_for_status if !new_status.blank? && new_assigned.blank?
|
||
|
data_for_assigned_and_status if !new_assigned.blank? && !new_assigned.blank?
|
||
|
@title = "" if @title.blank? # truncate
|
||
|
@title
|
||
|
end
|
||
|
def data_for_assigned
|
||
|
assigned = ((a = new_assigned) ? " #{a}" : nil)
|
||
|
query_for_assigned
|
||
|
@title = "##{issue.id} - now assigned to : (#{assigned})"
|
||
|
end
|
||
|
def data_for_status
|
||
|
status = ((s = new_status) ? " (#{s})" : nil)
|
||
|
query_for_status
|
||
|
@title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}"
|
||
|
end
|
||
|
def data_for_assigned_and_status
|
||
|
assigned = ((a = new_assigned) ? " #{a}" : nil)
|
||
|
status = ((s = new_status) ? " (#{s})" : nil)
|
||
|
query_for_assigned_and_status
|
||
|
@title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}. Now assigned to:(#{assigned})"
|
||
|
end
|
||
|
def query_for_assigned_and_status
|
||
|
@conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||
|
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')" +
|
||
|
" (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
|
||
|
end
|
||
|
def query_for_assigned
|
||
|
@conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||
|
" (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
|
||
|
end
|
||
|
def query_for_status
|
||
|
@conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||
|
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"
|
||
|
end
|
||
|
def save(*args)
|
||
|
# Do not save an empty journal
|
||
|
(details.empty? && notes.blank?) ? false : super
|
||
| ... | ... | |
|
s ? IssueStatus.find_by_id(s.to_i) : nil
|
||
|
end
|
||
|
def new_assigned
|
||
|
a = new_value_for('assigned_to_id')
|
||
|
a ? User.find(a.to_i) : nil
|
||
|
end
|
||
|
def new_value_for(prop)
|
||
|
detail_for_attribute(prop).try(:value)
|
||
|
end
|
||
| ... | ... | |
|
def send_notification
|
||
|
if notify? && (Setting.notified_events.include?('issue_updated') ||
|
||
|
(Setting.notified_events.include?('issue_note_added') && notes.present?) ||
|
||
|
(Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
|
||
|
(Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
|
||
|
(Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
|
||
|
)
|
||
|
(Setting.notified_events.include?('issue_note_added') && notes.present?) ||
|
||
|
(Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
|
||
|
(Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
|
||
|
(Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
|
||
|
)
|
||
|
Mailer.deliver_issue_edit(self)
|
||
|
end
|
||
|
end
|
||