diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/solidus_subscriptions.rb | 1 | ||||
-rw-r--r-- | lib/solidus_subscriptions/permission_sets/default_customer.rb | 19 | ||||
-rw-r--r-- | lib/solidus_subscriptions/permission_sets/subscription_management.rb | 11 |
3 files changed, 22 insertions, 9 deletions
diff --git a/lib/solidus_subscriptions.rb b/lib/solidus_subscriptions.rb index 21a9b40..039b172 100644 --- a/lib/solidus_subscriptions.rb +++ b/lib/solidus_subscriptions.rb @@ -7,6 +7,7 @@ require 'deface' require 'state_machines' require 'solidus_subscriptions/configuration' +require 'solidus_subscriptions/permission_sets/default_customer' require 'solidus_subscriptions/permission_sets/subscription_management' require 'solidus_subscriptions/version' require 'solidus_subscriptions/engine' diff --git a/lib/solidus_subscriptions/permission_sets/default_customer.rb b/lib/solidus_subscriptions/permission_sets/default_customer.rb new file mode 100644 index 0000000..156a5e1 --- /dev/null +++ b/lib/solidus_subscriptions/permission_sets/default_customer.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module PermissionSets + class DefaultCustomer < ::Spree::PermissionSets::Base + def activate! + can :manage, Subscription, Subscription.where(user: user) do |subscription, guest_token| + (subscription.guest_token.present? && subscription.guest_token == guest_token) || + (subscription.user && subscription.user == user) + end + + can :manage, LineItem do |line_item, guest_token| + (line_item.subscription&.guest_token.present? && line_item.subscription.guest_token == guest_token) || + (line_item.subscription&.user && line_item.subscription.user == user) + end + end + end + end +end diff --git a/lib/solidus_subscriptions/permission_sets/subscription_management.rb b/lib/solidus_subscriptions/permission_sets/subscription_management.rb index 9077ab9..f96ed53 100644 --- a/lib/solidus_subscriptions/permission_sets/subscription_management.rb +++ b/lib/solidus_subscriptions/permission_sets/subscription_management.rb @@ -4,15 +4,8 @@ module SolidusSubscriptions module PermissionSets class SubscriptionManagement < ::Spree::PermissionSets::Base def activate! - can :manage, Subscription, Subscription.where(user: user) do |subscription, guest_token| - (subscription.guest_token.present? && subscription.guest_token == guest_token) || - (subscription.user && subscription.user == user) - end - - can :manage, LineItem do |line_item, guest_token| - (line_item.subscription&.guest_token.present? && line_item.subscription.guest_token == guest_token) || - (line_item.subscription&.user && line_item.subscription.user == user) - end + can :manage, Subscription + can :manage, LineItem end end end |