2012-02-28 09:01:14 -05:00
|
|
|
class ActivityObserver < ActiveRecord::Observer
|
2012-12-14 12:33:33 -05:00
|
|
|
observe :issue, :merge_request, :note, :milestone
|
2012-02-28 09:01:14 -05:00
|
|
|
|
|
|
|
def after_create(record)
|
2012-12-14 15:05:10 -05:00
|
|
|
event_author_id = record.author_id
|
2012-12-14 14:39:55 -05:00
|
|
|
|
|
|
|
# Skip status notes
|
|
|
|
if record.kind_of?(Note) && record.note.include?("_Status changed to ")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if event_author_id
|
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event.determine_action(record),
|
|
|
|
author_id: event_author_id
|
|
|
|
)
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|
2012-03-07 03:13:43 -05:00
|
|
|
|
|
|
|
def after_save(record)
|
2012-12-14 14:39:55 -05:00
|
|
|
if record.changed.include?("closed") && record.author_id_of_changes
|
2012-03-07 03:13:43 -05:00
|
|
|
Event.create(
|
2012-08-10 18:07:50 -04:00
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: (record.closed ? Event::Closed : Event::Reopened),
|
|
|
|
author_id: record.author_id_of_changes
|
2012-03-07 03:13:43 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|