diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-10-09 09:50:03 +0200 |
---|---|---|
committer | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-10-09 09:50:03 +0200 |
commit | 811e7df206c304987b3ce4984ea6840f1fa78440 (patch) | |
tree | a3c31a1ba2bb3e52de34cfa1327a6605ab0f8858 /lib/solidus_subscriptions/permission_sets | |
parent | f55ce37d3d28d7c18b8458b657431bb7c07ac4a1 (diff) |
Add a permission set for administrators
Diffstat (limited to 'lib/solidus_subscriptions/permission_sets')
-rw-r--r-- | lib/solidus_subscriptions/permission_sets/default_customer.rb | 19 | ||||
-rw-r--r-- | lib/solidus_subscriptions/permission_sets/subscription_management.rb | 11 |
2 files changed, 21 insertions, 9 deletions
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 |