Commit 6cc4ac7b98b0fb2ba028644fd8dc4e2d89b65e2a
1 parent
12d08100
Exists in
spb-stable
and in
3 other branches
Drop activity observer. User EventCreateService instead
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
7 additions
and
43 deletions
Show diff stats
app/models/event.rb
@@ -47,14 +47,6 @@ class Event < ActiveRecord::Base | @@ -47,14 +47,6 @@ class Event < ActiveRecord::Base | ||
47 | scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } | 47 | scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } |
48 | 48 | ||
49 | class << self | 49 | class << self |
50 | - def determine_action(record) | ||
51 | - if [Issue, MergeRequest].include? record.class | ||
52 | - Event::CREATED | ||
53 | - elsif record.kind_of? Note | ||
54 | - Event::COMMENTED | ||
55 | - end | ||
56 | - end | ||
57 | - | ||
58 | def create_ref_event(project, user, ref, action = 'add', prefix = 'refs/heads') | 50 | def create_ref_event(project, user, ref, action = 'add', prefix = 'refs/heads') |
59 | commit = project.repository.commit(ref.target) | 51 | commit = project.repository.commit(ref.target) |
60 | 52 |
app/observers/activity_observer.rb
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -class ActivityObserver < BaseObserver | ||
2 | - observe :issue, :note, :milestone | ||
3 | - | ||
4 | - def after_create(record) | ||
5 | - if record.kind_of?(Note) | ||
6 | - # Skip system notes, like status changes and cross-references. | ||
7 | - return true if record.system? | ||
8 | - | ||
9 | - # Skip wall notes to prevent spamming of dashboard | ||
10 | - return true if record.noteable_type.blank? | ||
11 | - end | ||
12 | - | ||
13 | - create_event(record, Event.determine_action(record)) if current_user | ||
14 | - end | ||
15 | - | ||
16 | - def after_close(record, transition) | ||
17 | - create_event(record, Event::CLOSED) | ||
18 | - end | ||
19 | - | ||
20 | - def after_reopen(record, transition) | ||
21 | - create_event(record, Event::REOPENED) | ||
22 | - end | ||
23 | - | ||
24 | - protected | ||
25 | - | ||
26 | - def create_event(record, status) | ||
27 | - Event.create( | ||
28 | - project: record.project, | ||
29 | - target_id: record.id, | ||
30 | - target_type: record.class.name, | ||
31 | - action: status, | ||
32 | - author_id: current_user.id | ||
33 | - ) | ||
34 | - end | ||
35 | -end |
app/observers/base_observer.rb
@@ -3,6 +3,10 @@ class BaseObserver < ActiveRecord::Observer | @@ -3,6 +3,10 @@ class BaseObserver < ActiveRecord::Observer | ||
3 | NotificationService.new | 3 | NotificationService.new |
4 | end | 4 | end |
5 | 5 | ||
6 | + def event_service | ||
7 | + EventCreateService.new | ||
8 | + end | ||
9 | + | ||
6 | def log_info message | 10 | def log_info message |
7 | Gitlab::AppLogger.info message | 11 | Gitlab::AppLogger.info message |
8 | end | 12 | end |
app/observers/issue_observer.rb
1 | class IssueObserver < BaseObserver | 1 | class IssueObserver < BaseObserver |
2 | def after_create(issue) | 2 | def after_create(issue) |
3 | notification.new_issue(issue, current_user) | 3 | notification.new_issue(issue, current_user) |
4 | + event_service.open_issue(issue, current_user) | ||
4 | issue.create_cross_references!(issue.project, current_user) | 5 | issue.create_cross_references!(issue.project, current_user) |
5 | execute_hooks(issue) | 6 | execute_hooks(issue) |
6 | end | 7 | end |
7 | 8 | ||
8 | def after_close(issue, transition) | 9 | def after_close(issue, transition) |
9 | notification.close_issue(issue, current_user) | 10 | notification.close_issue(issue, current_user) |
11 | + event_service.close_issue(issue, current_user) | ||
10 | create_note(issue) | 12 | create_note(issue) |
11 | execute_hooks(issue) | 13 | execute_hooks(issue) |
12 | end | 14 | end |
13 | 15 | ||
14 | def after_reopen(issue, transition) | 16 | def after_reopen(issue, transition) |
17 | + event_service.reopen_issue(issue, current_user) | ||
15 | create_note(issue) | 18 | create_note(issue) |
16 | execute_hooks(issue) | 19 | execute_hooks(issue) |
17 | end | 20 | end |