2012-02-28 15:01:14 +01:00
|
|
|
class ActivityObserver < ActiveRecord::Observer
|
2012-03-07 09:13:43 +01:00
|
|
|
observe :issue, :merge_request
|
2012-02-28 15:01:14 +01:00
|
|
|
|
|
|
|
def after_create(record)
|
|
|
|
Event.create(
|
|
|
|
:project => record.project,
|
|
|
|
:target_id => record.id,
|
|
|
|
:target_type => record.class.name,
|
2012-03-07 09:13:43 +01:00
|
|
|
:action => Event.determine_action(record),
|
|
|
|
:author_id => record.author_id
|
2012-02-28 15:01:14 +01:00
|
|
|
)
|
|
|
|
end
|
2012-03-07 09:13:43 +01:00
|
|
|
|
|
|
|
def after_save(record)
|
|
|
|
if record.changed.include?("closed")
|
|
|
|
Event.create(
|
|
|
|
: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
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2012-02-28 15:01:14 +01:00
|
|
|
end
|