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

Creates an event when a new project is created This used to send a notification using EventfulMailer, but it is no longer required



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/event_factory.rb', line 10

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
end

.project_approved(project, user) ⇒ Object

Creates an event or emails when a project is approved This used to send a notification using EventfulMailer, but it is no longer required



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/event_factory.rb', line 27

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
end

.project_refund_request(project, user, reference) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/event_factory.rb', line 42

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
end

.record_retention_instruction_updates(labware, user, old_retention_instruction) ⇒ Object

Creates an event for retention instructions when labware is updated



94
95
96
97
98
99
100
101
102
103
# File 'lib/event_factory.rb', line 94

def self.record_retention_instruction_updates(labware, user, old_retention_instruction)
  old_retention_instruction = 'nil' if old_retention_instruction.blank?
  Event.create!(
    eventful: labware,
    message: "Set retention instruction from #{old_retention_instruction} to #{labware.retention_instruction}",
    content: Time.zone.today.to_s,
    family: 'set_retention_instruction',
    created_by: user ? user. : nil
  )
end

.request_update_note_to_manager(request, user, message) ⇒ Object

creates an event and sends an email when update(s) to a request fail rubocop:todo Metrics/MethodLength



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/event_factory.rb', line 63

def self.request_update_note_to_manager(request, user, message) # rubocop:todo Metrics/AbcSize
  content =
    # rubocop:todo Layout/LineLength
    "#{message}\nwhilst an attempt was made to update request #{request.id}\nby user '#{user.}' on #{Time.zone.now}"

  # rubocop:enable Layout/LineLength

  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 { |project| recipients << project.manager.email if project && project.manager }

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