2012-08-24 14:24:36 +02:00
|
|
|
# This plain ruby class should handle all user notifications, called by various models
|
|
|
|
class UserNotifier
|
2012-12-23 17:38:04 +01:00
|
|
|
@queue = :foodsoft_notifier
|
2012-08-24 14:24:36 +02:00
|
|
|
|
2012-12-23 17:38:04 +01:00
|
|
|
# Resque style method to perform every class method defined here
|
|
|
|
def self.perform(foodcoop, method_name, *args)
|
2013-06-29 01:48:57 +02:00
|
|
|
FoodsoftConfig.select_foodcoop(foodcoop) if FoodsoftConfig[:multi_coop_install]
|
2012-12-23 17:38:04 +01:00
|
|
|
self.send method_name, args
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.finished_order(args)
|
|
|
|
order_id = args.first
|
2012-08-24 14:24:36 +02:00
|
|
|
Order.find(order_id).group_orders.each do |group_order|
|
2016-03-11 22:52:49 +01:00
|
|
|
next if group_order.ordergroup.nil?
|
2012-08-24 14:24:36 +02:00
|
|
|
group_order.ordergroup.users.each do |user|
|
2017-08-18 01:04:41 +02:00
|
|
|
if user.settings.notify['order_finished']
|
|
|
|
Mailer.deliver_now_with_user_locale user do
|
|
|
|
Mailer.order_result(user, group_order)
|
2014-05-07 17:14:56 +02:00
|
|
|
end
|
2012-08-24 14:24:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-24 14:48:53 +02:00
|
|
|
|
|
|
|
# If this order group's account balance is made negative by the given/last transaction,
|
|
|
|
# a message is sent to all users who have enabled notification.
|
2012-12-23 17:38:04 +01:00
|
|
|
def self.negative_balance(args)
|
|
|
|
ordergroup_id, transaction_id = args
|
2012-08-24 14:48:53 +02:00
|
|
|
transaction = FinancialTransaction.find transaction_id
|
|
|
|
|
|
|
|
Ordergroup.find(ordergroup_id).users.each do |user|
|
2017-08-18 01:04:41 +02:00
|
|
|
if user.settings.notify['negative_balance']
|
|
|
|
Mailer.deliver_now_with_user_locale user do
|
|
|
|
Mailer.negative_balance(user, transaction)
|
2014-05-07 17:14:56 +02:00
|
|
|
end
|
2012-08-24 14:48:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-29 01:48:57 +02:00
|
|
|
end
|