Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guard so seller_order_updated and other mailer won't send to empty recipients list #3348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 20 additions & 24 deletions app/mailers/order_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def buyer_confirmation(order)

@order = BuyerOrder.new(order)

to_list = recipient_list(order)
to_list = recipient_list(order.organization)

if !to_list.blank?
mail(
Expand All @@ -22,11 +22,7 @@ def seller_confirmation(order, seller)
@order = SellerOrder.new(order, seller) # Selling users organizations only see
@seller = seller

to_list = seller.
users.
confirmed.
map { |u| u.enabled_for_organization?(seller) && !u.pretty_email.nil? ? u.pretty_email : nil}.
compact
to_list = recipient_list(seller)

if !to_list.blank?
mail(
Expand All @@ -49,14 +45,14 @@ def market_manager_confirmation(order)
end

def invoice(order_id)

@order = BuyerOrder.new(Order.find(order_id))
@market = @order.market
return if @market.is_consignment_market?

attachments["invoice.pdf"] = {mime_type: "application/pdf", content: @order.invoice_pdf.try(:data)}

to_list = recipient_list(@order)
to_list = recipient_list(@order.organization)

if !to_list.blank?
mail(
to: to_list,
Expand All @@ -72,7 +68,7 @@ def buyer_order_updated(order)
@order = BuyerOrder.new(order) # Market Managers should see all items

mail(
to: recipient_list(order),
to: recipient_list(order.organization),
subject: "#{@market.name}: Order #{order.order_number} Updated",
template_name: "order_updated"
)
Expand All @@ -85,7 +81,7 @@ def buyer_order_removed(order)
@order = BuyerOrder.new(order) # Market Managers should see all items

mail(
to: recipient_list(order),
to: recipient_list(order.organization),
subject: "#{@market.name}: Order #{order.order_number} Updated - Item Removed",
template_name: "order_updated"
)
Expand All @@ -98,16 +94,15 @@ def seller_order_updated(order, seller)
@order = SellerOrder.new(order, seller) # Selling users organizations only see
@seller = seller

to_list = seller.
users.
map { |u| u.enabled_for_organization?(seller) ? u.pretty_email : nil}.
compact
to_list = recipient_list(seller)

mail(
to: to_list,
subject: "#{@market.name}: Order #{order.order_number} Updated",
template_name: "order_updated"
)
if !to_list.blank?
mail(
to: to_list,
subject: "#{@market.name}: Order #{order.order_number} Updated",
template_name: "order_updated"
)
end
end

def market_manager_order_updated(order)
Expand Down Expand Up @@ -135,21 +130,22 @@ def seller_order_item_removal(order, seller, pdf, csv)
attachments["packing_list.csv"] = {mime_type: "application/csv", content: csv}
end

to_list = recipient_list(seller)

mail(
to: seller.users.map(&:pretty_email),
to: to_list,
subject: "#{@market.name}: Order #{order.order_number} Updated - Item Removed",
template_name: "order_updated"
)
end

private

def recipient_list(order)
order.
organization.
def recipient_list(organization)
organization.
users.
confirmed.
map { |u| u.enabled_for_organization?(order.organization) ? u.pretty_email : nil}.
map { |u| u.enabled_for_organization?(organization) ? u.pretty_email : nil}.
compact
end
end
Loading