2021-05-19 18:12:52 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Check the access policies for API::LocalPaymentsController
|
|
|
|
class LocalPaymentPolicy < ApplicationPolicy
|
|
|
|
def confirm_payment?
|
2021-10-12 14:07:35 +02:00
|
|
|
# only admins and managers can offer free extensions of a subscription
|
|
|
|
has_free_days = record.shopping_cart.items.any? { |item| item.is_a? CartItem::FreeExtension }
|
2023-06-13 11:38:06 +02:00
|
|
|
event = record.shopping_cart.items.find { |item| item.is_a? CartItem::EventReservation }
|
2021-10-12 14:07:35 +02:00
|
|
|
|
2023-06-13 11:38:06 +02:00
|
|
|
((user.admin? || user.manager?) && record.shopping_cart.customer.id != user.id) || (record.price.zero? && !has_free_days) || event&.reservable&.pre_registration
|
2021-05-19 18:12:52 +02:00
|
|
|
end
|
|
|
|
end
|