1
votes

I am working with a Delayed Job that, after its completion, sends an email to the admin user that requested it. So, to do this, I need to know who is the admin user that launched it inside the Spree::Order model. I've tried with try_spree_current_user and spree_current_user but they don't work returning:

NameError (undefined local variable or method `try_spree_current_user' for #<Spree::Order:0x007f93811d7240>):
  app/models/spree/order_decorator.rb:30:in `after_cancel'
  app/controllers/spree/admin/orders_controller_decorator.rb:4:in `cancel'
1

1 Answers

1
votes

Some how you need to make sure that an admin can launch the order:

# Is this user an admin
if spree_current_user.admin?
 # Do some delayed job
 # send the email
 # because spree_current_user.id is the one that sends it
else
 flash[:error] = "You need to be an admin to do this."
 redirect_back_or_default(spree.root_path)
end

The above should do what you want to do. You need to test if the current user is an admin then do what he/she needs to do.

I'm sure you meant the OrdersController? Not model.