Class: EventCreateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/event_create_service.rb

Overview

EventCreateService class

Used for creating events feed on dashboard after certain user action

Ex.

EventCreateService.new.new_issue(issue, current_user)

Constant Summary collapse

IllegalActionError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#approve_mr(merge_request, current_user) ⇒ Object


130
131
132
# File 'app/services/event_create_service.rb', line 130

def approve_mr(merge_request, current_user)
  create_record_event(merge_request, current_user, :approved)
end

#bulk_push(project, current_user, push_data) ⇒ Object


91
92
93
# File 'app/services/event_create_service.rb', line 91

def bulk_push(project, current_user, push_data)
  create_push_event(BulkPushEventPayloadService, project, current_user, push_data)
end

#close_issue(issue, current_user) ⇒ Object


17
18
19
# File 'app/services/event_create_service.rb', line 17

def close_issue(issue, current_user)
  create_record_event(issue, current_user, :closed)
end

#close_milestone(milestone, current_user) ⇒ Object


51
52
53
# File 'app/services/event_create_service.rb', line 51

def close_milestone(milestone, current_user)
  create_record_event(milestone, current_user, :closed)
end

#close_mr(merge_request, current_user) ⇒ Object


31
32
33
34
35
# File 'app/services/event_create_service.rb', line 31

def close_mr(merge_request, current_user)
  create_record_event(merge_request, current_user, :closed).tap do
    track_event(event_action: :closed, event_target: MergeRequest, author_id: current_user.id)
  end
end

#create_project(project, current_user) ⇒ Object


83
84
85
# File 'app/services/event_create_service.rb', line 83

def create_project(project, current_user)
  create_event(project, current_user, :created)
end

#destroy_designs(designs, current_user) ⇒ Object


102
103
104
105
106
# File 'app/services/event_create_service.rb', line 102

def destroy_designs(designs, current_user)
  return [] unless designs.present?

  create_record_events(designs.zip([:destroyed].cycle), current_user)
end

#destroy_milestone(milestone, current_user) ⇒ Object


59
60
61
# File 'app/services/event_create_service.rb', line 59

def destroy_milestone(milestone, current_user)
  create_record_event(milestone, current_user, :destroyed)
end

#expired_leave_project(project, current_user) ⇒ Object


79
80
81
# File 'app/services/event_create_service.rb', line 79

def expired_leave_project(project, current_user)
  create_event(project, current_user, :expired)
end

#join_project(project, current_user) ⇒ Object


71
72
73
# File 'app/services/event_create_service.rb', line 71

def join_project(project, current_user)
  create_event(project, current_user, :joined)
end

#leave_note(note, current_user) ⇒ Object


63
64
65
66
67
68
69
# File 'app/services/event_create_service.rb', line 63

def leave_note(note, current_user)
  create_record_event(note, current_user, :commented).tap do
    if note.is_a?(DiffNote) && note.for_merge_request?
      track_event(event_action: :commented, event_target: MergeRequest, author_id: current_user.id)
    end
  end
end

#leave_project(project, current_user) ⇒ Object


75
76
77
# File 'app/services/event_create_service.rb', line 75

def leave_project(project, current_user)
  create_event(project, current_user, :left)
end

#merge_mr(merge_request, current_user) ⇒ Object


41
42
43
44
45
# File 'app/services/event_create_service.rb', line 41

def merge_mr(merge_request, current_user)
  create_record_event(merge_request, current_user, :merged).tap do
    track_event(event_action: :merged, event_target: MergeRequest, author_id: current_user.id)
  end
end

#open_issue(issue, current_user) ⇒ Object


13
14
15
# File 'app/services/event_create_service.rb', line 13

def open_issue(issue, current_user)
  create_record_event(issue, current_user, :created)
end

#open_milestone(milestone, current_user) ⇒ Object


47
48
49
# File 'app/services/event_create_service.rb', line 47

def open_milestone(milestone, current_user)
  create_record_event(milestone, current_user, :created)
end

#open_mr(merge_request, current_user) ⇒ Object


25
26
27
28
29
# File 'app/services/event_create_service.rb', line 25

def open_mr(merge_request, current_user)
  create_record_event(merge_request, current_user, :created).tap do
    track_event(event_action: :created, event_target: MergeRequest, author_id: current_user.id)
  end
end

#push(project, current_user, push_data) ⇒ Object


87
88
89
# File 'app/services/event_create_service.rb', line 87

def push(project, current_user, push_data)
  create_push_event(PushEventPayloadService, project, current_user, push_data)
end

#reopen_issue(issue, current_user) ⇒ Object


21
22
23
# File 'app/services/event_create_service.rb', line 21

def reopen_issue(issue, current_user)
  create_record_event(issue, current_user, :reopened)
end

#reopen_milestone(milestone, current_user) ⇒ Object


55
56
57
# File 'app/services/event_create_service.rb', line 55

def reopen_milestone(milestone, current_user)
  create_record_event(milestone, current_user, :reopened)
end

#reopen_mr(merge_request, current_user) ⇒ Object


37
38
39
# File 'app/services/event_create_service.rb', line 37

def reopen_mr(merge_request, current_user)
  create_record_event(merge_request, current_user, :reopened)
end

#save_designs(current_user, create: [], update: []) ⇒ Object


95
96
97
98
99
100
# File 'app/services/event_create_service.rb', line 95

def save_designs(current_user, create: [], update: [])
  records = create.zip([:created].cycle) + update.zip([:updated].cycle)
  return [] if records.empty?

  create_record_events(records, current_user)
end

#wiki_event(wiki_page_meta, author, action, fingerprint) ⇒ Event

Create a new wiki page event

The fingerprint, if provided, should be sufficient to find duplicate events. Suitable values would be, for example, the current page SHA.

Parameters:

  • wiki_page_meta (WikiPage::Meta)

    The event target

  • author (User)

    The event author

  • action (Symbol)

    One of the Event::WIKI_ACTIONS

  • fingerprint (String)

    The de-duplication fingerprint

Returns:

Raises:


119
120
121
122
123
124
125
126
127
128
# File 'app/services/event_create_service.rb', line 119

def wiki_event(wiki_page_meta, author, action, fingerprint)
  raise IllegalActionError, action unless Event::WIKI_ACTIONS.include?(action)

  track_event(event_action: action, event_target: wiki_page_meta.class, author_id: author.id)

  duplicate = Event.for_wiki_meta(wiki_page_meta).for_fingerprint(fingerprint).first
  return duplicate if duplicate.present?

  create_record_event(wiki_page_meta, author, action, fingerprint.presence)
end