diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-10-07 16:28:34 +0200 |
---|---|---|
committer | Alessandro Desantis <desa.alessandro@gmail.com> | 2020-10-07 16:33:44 +0200 |
commit | ae1b46fe30793cecb13a8591e9d753ada9f89039 (patch) | |
tree | 693299715c4e98ed7c626e218d39d363960421b4 /lib/solidus_subscriptions/permission_sets | |
parent | fb0777566944c9deef6cbacd7a7eac335838746a (diff) |
Migrate ability to permission sets
Custom abilities are deprecated in favor of the new permission sets
API.
Diffstat (limited to 'lib/solidus_subscriptions/permission_sets')
-rw-r--r-- | lib/solidus_subscriptions/permission_sets/subscription_management.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/solidus_subscriptions/permission_sets/subscription_management.rb b/lib/solidus_subscriptions/permission_sets/subscription_management.rb new file mode 100644 index 0000000..8f5edfb --- /dev/null +++ b/lib/solidus_subscriptions/permission_sets/subscription_management.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module SolidusSubscriptions + module PermissionSets + class SubscriptionManagement < ::Spree::PermissionSets::Base + def activate! + can :manage, Subscription do |subscription| + subscription.user == user + end + + can :manage, LineItem do |line_item, order| + (line_item.order && line_item.order == order) || + (line_item.order&.user && line_item.order.user == user) + end + end + end + end +end |