mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-21 00:47:26 +00:00
Adding controller actions and routes for pausing and unpausing a standing order
This commit is contained in:
@@ -50,6 +50,16 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def pause
|
||||
@standing_order.update_attributes(paused_at: Time.zone.now)
|
||||
render_as_json @standing_order, fee_calculator: fee_calculator
|
||||
end
|
||||
|
||||
def unpause
|
||||
@standing_order.update_attributes(paused_at: nil)
|
||||
render_as_json @standing_order, fee_calculator: fee_calculator
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def permissions
|
||||
|
||||
@@ -253,7 +253,7 @@ class AbilityDecorator
|
||||
can [:create], Customer
|
||||
can [:admin, :index, :update, :destroy], Customer, enterprise_id: Enterprise.managed_by(user).pluck(:id)
|
||||
can [:admin, :new, :index], StandingOrder
|
||||
can [:create, :edit, :update, :cancel], StandingOrder do |standing_order|
|
||||
can [:create, :edit, :update, :cancel, :pause, :unpause], StandingOrder do |standing_order|
|
||||
user.enterprises.include?(standing_order.shop)
|
||||
end
|
||||
can [:admin, :build], StandingLineItem
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Api::Admin::StandingOrderSerializer < ActiveModel::Serializer
|
||||
attributes :id, :shop_id, :customer_id, :schedule_id, :payment_method_id, :shipping_method_id, :begins_at, :ends_at
|
||||
attributes :customer_email, :schedule_name, :edit_path, :canceled_at
|
||||
attributes :customer_email, :schedule_name, :edit_path, :canceled_at, :paused_at
|
||||
|
||||
has_many :standing_line_items, serializer: Api::Admin::StandingLineItemSerializer
|
||||
has_many :closed_standing_order_orders, serializer: Api::Admin::StandingOrderOrderSerializer
|
||||
@@ -16,6 +16,10 @@ class Api::Admin::StandingOrderSerializer < ActiveModel::Serializer
|
||||
object.ends_at.andand.strftime('%F')
|
||||
end
|
||||
|
||||
def paused_at
|
||||
object.paused_at.andand.strftime('%F')
|
||||
end
|
||||
|
||||
def canceled_at
|
||||
object.canceled_at.andand.strftime('%F')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user