2012-02-28 15:01:14 +01:00
|
|
|
class ActivityObserver < ActiveRecord::Observer
|
2012-12-14 18:33:33 +01:00
|
|
|
observe :issue, :merge_request, :note, :milestone
|
2012-02-28 15:01:14 +01:00
|
|
|
|
|
|
|
def after_create(record)
|
2012-12-14 21:05:10 +01:00
|
|
|
event_author_id = record.author_id
|
2012-12-14 20:39:55 +01: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 15:01:14 +01:00
|
|
|
end
|
2012-03-07 09:13:43 +01:00
|
|
|
|
2013-02-18 13:49:17 +01:00
|
|
|
def after_close(record, transition)
|
2013-02-25 20:26:15 +01:00
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event::CLOSED,
|
|
|
|
author_id: record.author_id_of_changes
|
|
|
|
)
|
2013-02-18 13:49:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(record, transition)
|
2013-02-25 20:26:15 +01:00
|
|
|
Event.create(
|
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: Event::REOPENED,
|
|
|
|
author_id: record.author_id_of_changes
|
|
|
|
)
|
2012-03-07 09:13:43 +01:00
|
|
|
end
|
2012-02-28 15:01:14 +01:00
|
|
|
end
|