Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions app/mailers/request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class RequestMailer < ApplicationMailer
helper :mail

# Sends the AffiliateBorrowRequestForm
def affiliate_borrow_request_form_email(borrow_request)
@borrow_request = borrow_request
def affiliate_borrow_request_form_email(borrow_request_hash)
@borrow_request = AffiliateBorrowRequestForm::BorrowRequest.new(**borrow_request_hash)

mail(to: borrow_request.department_head_email)
mail(to: @borrow_request.department_head_email)
end

# Send LibstaffEdevicesLoanRequest confirmation email to user
Expand Down Expand Up @@ -40,16 +40,21 @@ def doemoff_room_failure_email(empid, displayname, note)
mail(to: admin_to)
end

# Sends doemoff patron email
def doemoff_patron_email(email_form)
@email_form = email_form
mail(to: @email_form.patron_email, bcc: @email_form.recipient_email, reply_to: @email_form.recipient_email,
subject: 'Message from Doe/Moffitt Libraries Staff')
def doemoff_patron_email(payload)
@email_form = DoemoffPatronEmailForm::PatronEmail.new(**payload)

mail(
to: @email_form.patron_email,
bcc: @email_form.recipient_email,
reply_to: @email_form.recipient_email,
subject: 'Message from Doe/Moffitt Libraries Staff'
)
end

# Sends the Security Incident form email
def security_incident_email(security_incident)
@security_incident = security_incident
def security_incident_email(payload)
@security_incident = SecurityIncidentReportForm::SecurityIncident.new(**payload)

if @security_incident.sup_email.nil?
mail(to: security_to, subject: 'Incident Report Form email')
else
Expand Down Expand Up @@ -227,7 +232,8 @@ def bibliographic_email(email, attachment_contents, subject, body)
mail(to: email, subject:, body:)
end

def efee_invoice_email(efee)
def efee_invoice_email(alma_id)
efee = EfeesInvoice.new(alma_id)
# type probably isn't needed now that I spun this off to a separate url
params = {
type: 'efee',
Expand All @@ -239,7 +245,7 @@ def efee_invoice_email(efee)
@name = efee.name
@link = invoice_link.to_s

mail(to: efee.email)
mail(to: efee.email, subject: 'Library Fees')
end

# Departmental Card Request : alerts to privdesk, Mark Marrow and Supervisor
Expand Down
40 changes: 25 additions & 15 deletions app/models/affiliate_borrow_request_form.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# app/models/affiliate_borrow_request_form.rb
class AffiliateBorrowRequestForm < Form
attr_accessor(
:department_head_email,
:department_head_name,
:department_name,
:employee_email,
:employee_id,
:employee_name,
:employee_personal_email,
:employee_phone,
:employee_preferred_name,
:employee_address
)
ATTRIBUTES = %i[
department_head_email
department_head_name
department_name
employee_email
employee_id
employee_name
employee_personal_email
employee_phone
employee_preferred_name
employee_address
].freeze

BorrowRequest = Struct.new(*ATTRIBUTES, keyword_init: true)

attr_accessor(*ATTRIBUTES)

validates :department_name,
presence: true
Expand Down Expand Up @@ -39,9 +44,14 @@ class AffiliateBorrowRequestForm < Form
validates :employee_address,
presence: true

private
# Return a serializable hash for deliver_later
def to_h
ATTRIBUTES.index_with { |attr| public_send(attr) }
end

def submit!
raise ActiveModel::ValidationError, self unless valid?

def submit
RequestMailer.affiliate_borrow_request_form_email(self).deliver_now
RequestMailer.affiliate_borrow_request_form_email(to_h).deliver_later
end
end
26 changes: 17 additions & 9 deletions app/models/doemoff_patron_email_form.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
class DoemoffPatronEmailForm < Form
attr_accessor(
:patron_email,
:patron_message,
:sender,
:recipient_email
)
ATTRIBUTES = %i[
patron_email
patron_message
sender
recipient_email
].freeze

PatronEmail = Struct.new(*ATTRIBUTES, keyword_init: true)

attr_accessor(*ATTRIBUTES)

validates :patron_email,
email: true,
presence: true

validates :patron_message, :sender, :recipient_email, presence: true

private
def to_h
ATTRIBUTES.index_with { |attr| public_send(attr) }
end

def submit!
raise ActiveModel::ValidationError, self unless valid?

def submit
RequestMailer.doemoff_patron_email(self).deliver_now
RequestMailer.doemoff_patron_email(to_h).deliver_later
end
end
2 changes: 1 addition & 1 deletion app/models/efees_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def encode

def submit!
# Send the email with the link to the user!
RequestMailer.efee_invoice_email(self).deliver_now
RequestMailer.efee_invoice_email(alma_id).deliver_later
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/proxy_borrower_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ProxyBorrowerRequests < ActiveRecord::Base
validate :date_limit

def submit!
RequestMailer.proxy_borrower_request_email(self).deliver_now
RequestMailer.proxy_borrower_alert_email(self).deliver_now
RequestMailer.proxy_borrower_request_email(self).deliver_later
RequestMailer.proxy_borrower_alert_email(self).deliver_later
end

def full_name
Expand Down
6 changes: 3 additions & 3 deletions app/models/reference_card_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class ReferenceCardForm < StackRequest
MAX_LENGTH = 91

def submit!
RequestMailer.reference_card_email(self).deliver_now
RequestMailer.reference_card_email(self).deliver_later
end

def approve!
RequestMailer.reference_card_approved(self).deliver_now
RequestMailer.reference_card_approved(self).deliver_later
end

def deny!
RequestMailer.reference_card_denied(self).deliver_now
RequestMailer.reference_card_denied(self).deliver_later
end

# Add up and return the total number of days this requester
Expand Down
140 changes: 74 additions & 66 deletions app/models/security_incident_report_form.rb
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
class SecurityIncidentReportForm < Form
attr_accessor(
:incident_location,
:incident_date,
:incident_time,
:reporter_name,
:email,
:unit,
:phone,
:incident_description,
:theft_personal,
:theft_library,
:vandalism,
:assault,
:criminal_other,
:rules_violation,
:irate_abusive,
:physical_altercation,
:disruptive_other,
:power_outage,
:flooding,
:elevator,
:fire,
:facility_other,
:library_employee,
:student_patron,
:campus_employee,
:visitor,
:injury_other,
:injury_description,
:subject_affiliation,
:race,
:sex,
:build,
:height,
:weight,
:hair,
:eyes,
:clothing,
:subject_affiliation_1,
:race_1,
:sex_1,
:build_1,
:height_1,
:weight_1,
:hair_1,
:eyes_1,
:clothing_1,
:subject_affiliation_2,
:race_2,
:sex_2,
:build_2,
:height_2,
:weight_2,
:hair_2,
:eyes_2,
:clothing_2,
:property_description,
:police_report_number,
:officer_name_badge,
:fire_department,
:sup_email,
:police_notified
)
ATTRIBUTES = %i[
incident_location
incident_date
incident_time
reporter_name
email
unit
phone
incident_description
theft_personal
theft_library
vandalism
assault
criminal_other
rules_violation
irate_abusive
physical_altercation
disruptive_other
power_outage
flooding
elevator
fire
facility_other
library_employee
student_patron
campus_employee
visitor
injury_other
injury_description
subject_affiliation
race
sex
build
height
weight
hair
eyes
clothing
subject_affiliation_1
race_1
sex_1
build_1
height_1
weight_1
hair_1
eyes_1
clothing_1
subject_affiliation_2
race_2
sex_2
build_2
height_2
weight_2
hair_2
eyes_2
clothing_2
property_description
police_report_number
officer_name_badge
fire_department
sup_email
police_notified
].freeze

SecurityIncident = Struct.new(*ATTRIBUTES, keyword_init: true)

attr_accessor(*ATTRIBUTES)

validates :email, :sup_email,
email: true,
Expand All @@ -70,9 +74,13 @@ class SecurityIncidentReportForm < Form
validates :incident_location, :incident_date, :incident_time, :reporter_name, :unit, :phone,
:incident_description, presence: true

private
def to_h
ATTRIBUTES.index_with { |attr| public_send(attr) }
end

def submit!
raise ActiveModel::ValidationError, self unless valid?

def submit
RequestMailer.security_incident_email(self).deliver_now
RequestMailer.security_incident_email(to_h).deliver_later
end
end
6 changes: 3 additions & 3 deletions app/models/stack_pass_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class StackPassForm < StackRequest
validates :main_stack, acceptance: { message: 'Item must be located in the Main (Gardner) stacks.' }

def submit!
RequestMailer.stack_pass_email(self).deliver_now
RequestMailer.stack_pass_email(self).deliver_later
end

def approve!
RequestMailer.stack_pass_approved(self).deliver_now
RequestMailer.stack_pass_approved(self).deliver_later
end

def deny!
RequestMailer.stack_pass_denied(self).deliver_now
RequestMailer.stack_pass_denied(self).deliver_later
end

def approval_count
Expand Down
9 changes: 5 additions & 4 deletions spec/models/affiliate_borrow_request_form_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'rails_helper'

describe AffiliateBorrowRequestForm do
include ActiveJob::TestHelper
include ActionMailer::TestHelper

it 'validates the form' do
tests = [
{
Expand Down Expand Up @@ -90,10 +93,8 @@
employee_address: '123 North St, Berkeley, CA 94707'
)

expect { form.submit! }.to(change { ActionMailer::Base.deliveries.count }.by(1))
last_email = ActionMailer::Base.deliveries.last
expect(last_email.subject).to eq('UC Berkeley Borrowing Card Requested')
expect(last_email.to).to include('jeff@wilco.com')
expect { form.submit! }.to have_enqueued_job(ActionMailer::MailDeliveryJob)

end

describe :model_name do
Expand Down
Loading