2013-03-26 17:00:54 +00:00
|
|
|
class ActivityObserver < BaseObserver
|
2013-04-25 14:15:33 +00:00
|
|
|
observe :issue, :note, :milestone
|
2012-02-28 14:01:14 +00:00
|
|
|
|
|
|
|
def after_create(record)
|
2012-12-14 20:05:10 +00:00
|
|
|
event_author_id = record.author_id
|
2012-12-14 19:39:55 +00:00
|
|
|
|
2013-03-19 12:50:26 +00:00
|
|
|
if record.kind_of?(Note)
|
|
|
|
# Skip system status notes like 'status changed to close'
|
|
|
|
return true if record.note.include?("_Status changed to ")
|
|
|
|
|
2013-07-29 10:46:00 +00:00
|
|
|
# Skip wall notes to prevent spamming of dashboard
|
2013-03-19 12:50:26 +00:00
|
|
|
return true if record.noteable_type.blank?
|
2012-12-14 19:39:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if event_author_id
|
2013-04-25 14:15:33 +00:00
|
|
|
create_event(record, Event.determine_action(record))
|
2012-12-14 19:39:55 +00:00
|
|
|
end
|
2012-02-28 14:01:14 +00:00
|
|
|
end
|
2012-03-07 08:13:43 +00:00
|
|
|
|
2013-02-18 12:49:17 +00:00
|
|
|
def after_close(record, transition)
|
2013-04-25 14:15:33 +00:00
|
|
|
create_event(record, Event::CLOSED)
|
2013-02-18 12:49:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(record, transition)
|
2013-04-25 14:15:33 +00:00
|
|
|
create_event(record, Event::REOPENED)
|
2012-03-07 08:13:43 +00:00
|
|
|
end
|
2013-02-27 15:48:51 +00:00
|
|
|
|
2013-04-25 14:15:33 +00:00
|
|
|
protected
|
2013-02-27 15:48:51 +00:00
|
|
|
|
2013-04-25 14:15:33 +00:00
|
|
|
def create_event(record, status)
|
2013-02-27 15:48:51 +00:00
|
|
|
Event.create(
|
2013-08-14 11:19:11 +00:00
|
|
|
project: record.project,
|
|
|
|
target_id: record.id,
|
|
|
|
target_type: record.class.name,
|
|
|
|
action: status,
|
|
|
|
author_id: current_user
|
2013-02-27 15:48:51 +00:00
|
|
|
)
|
|
|
|
end
|
2012-02-28 14:01:14 +00:00
|
|
|
end
|