summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/permission_sets
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2020-10-07 16:28:34 +0200
committerAlessandro Desantis <desa.alessandro@gmail.com>2020-10-07 16:33:44 +0200
commitae1b46fe30793cecb13a8591e9d753ada9f89039 (patch)
tree693299715c4e98ed7c626e218d39d363960421b4 /lib/solidus_subscriptions/permission_sets
parentfb0777566944c9deef6cbacd7a7eac335838746a (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.rb18
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