2013-03-26 13:00:54 -04:00
|
|
|
class ActivityObserver < BaseObserver
|
2013-04-25 10:15:33 -04:00
|
|
|
observe :issue, :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
|
|
|
|
2013-03-19 08:50:26 -04:00
|
|
|
if record.kind_of?(Note)
|
2013-05-30 19:16:49 -04:00
|
|
|
# Skip system notes, like status changes and cross-references.
|
|
|
|
return true if record.system?
|
2013-03-19 08:50:26 -04:00
|
|
|
|
2013-07-29 06:46:00 -04:00
|
|
|
# Skip wall notes to prevent spamming of dashboard
|
2013-03-19 08:50:26 -04:00
|
|
|
return true if record.noteable_type.blank?
|
2012-12-14 14:39:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if event_author_id
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(record, Event.determine_action(record))
|
2012-12-14 14:39:55 -05:00
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|
2012-03-07 03:13:43 -05:00
|
|
|
|
2013-02-18 07:49:17 -05:00
|
|
|
def after_close(record, transition)
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(record, Event::CLOSED)
|
2013-02-18 07:49:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(record, transition)
|
2013-04-25 10:15:33 -04:00
|
|
|
create_event(record, Event::REOPENED)
|
2012-03-07 03:13:43 -05:00
|
|
|
end
|
2013-02-27 10:48:51 -05:00
|
|
|
|
2013-04-25 10:15:33 -04:00
|
|
|
protected
|
2013-02-27 10:48:51 -05:00
|
|
|
|
2013-04-25 10:15:33 -04:00
|
|
|
def create_event(record, status)
|
2013-02-27 10:48:51 -05:00
|
|
|
Event.create(
|
2013-08-14 07:19:11 -04:00
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: status,
|
2013-08-14 09:02:21 -04:00
|
|
|
author_id: current_user.id
|
2013-02-27 10:48:51 -05:00
|
|
|
)
|
|
|
|
end
|
2012-02-28 09:01:14 -05:00
|
|
|
end
|