Class: EventFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/event_factory.rb

Class Method Summary collapse

Class Method Details

.new_project(project, user) ⇒ Object

project related notifications #

Creates an event and sends an email when a new project is created


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/event_factory.rb', line 7

def self.new_project(project, user)
  content = "Project registered by #{user.}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: 'Project registered',
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save

  admin_emails = User.all_administrators_emails.reject(&:blank?)

  EventfulMailer.confirm_event(
    admin_emails,
    event.eventful,
    event.message,
    event.content,
    'No Milestone'
  ).deliver_now unless admin_emails.empty?
end

.project_approved(project, user) ⇒ Object

Creates an event and sends an email or emails when a project is approved


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/event_factory.rb', line 32

def self.project_approved(project, user)
  content = "Project approved by #{user.}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: 'Project approved',
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save

  recipients_email = []
  project_manager_email = ''
  unless project.manager.blank?
    project_manager_email = (project.manager.email).to_s
    recipients_email << project_manager_email
  end
  if user.is_administrator?
    administrators_email = User.all_administrators_emails
    administrators_email.each do |email|
      recipients_email << email unless email == project_manager_email
    end
  end

  EventfulMailer.confirm_event(recipients_email, event.eventful, event.message, event.content, 'No Milestone').deliver_now
end

.project_refund_request(project, user, reference) ⇒ Object


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/event_factory.rb', line 61

def self.project_refund_request(project, user, reference)
  content = "Refund request by #{user.}. Reference #{reference}"

  event = Event.new(
    eventful_id: project.id,
    eventful_type: 'Project',
    message: "Refund #{reference}",
    created_by: user.,
    content: content,
    of_interest_to: 'administrators'
  )
  event.save

  # EventfulMailer.deliver_confirm_event(User.all_administrators_emails, event.eventful, event.message, event.content, "No Milestone")
end

.request_update_note_to_manager(request, user, message) ⇒ Object

creates an event and sends an email when update(s) to a request fail


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/event_factory.rb', line 108

def self.request_update_note_to_manager(request, user, message)
  content = "#{message}\nwhilst an attempt was made to update request #{request.id}\nby user '#{user.}' on #{Time.now}"

  request_event = Event.create(
    eventful_id: request.id,
    eventful_type: 'Request',
    message: 'Request update(s) failed',
    created_by: user.,
    content: content,
    of_interest_to: 'manager'
  )

  recipients = []
  request.initial_project.tap do |project|
    recipients << project.manager.email if project && project.manager
  end

  EventfulMailer.confirm_event(recipients.reject(&:blank?), request_event.eventful, request_event.message, request_event.content, 'No Milestone').deliver_now
end

.study_has_samples_registered(study, samples, user) ⇒ Object

creates an event and sends an email when samples are register to a study


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/event_factory.rb', line 82

def self.study_has_samples_registered(study, samples, user)
  sample_names_string = samples.map { |s| s.name }.join("','")
  content = "Samples '#{sample_names_string}' registered by user '#{user.}' on #{Time.now}"

  study_event = Event.create(
    eventful_id: study.id,
    eventful_type: 'Study',
    message: 'Sample(s) registered',
    created_by: user.,
    content: content,
    of_interest_to: 'users'
  )

  recipients = []
  study.projects.each do |project|
    recipients << project.manager.email if project.manager
  end

  EventfulMailer.confirm_event(recipients.reject(&:blank?), study_event.eventful, study_event.message, study_event.content, 'No Milestone').deliver_now
end