summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/permission_sets
diff options
context:
space:
mode:
authorAlessandro Desantis <desa.alessandro@gmail.com>2020-10-09 09:50:03 +0200
committerAlessandro Desantis <desa.alessandro@gmail.com>2020-10-09 09:50:03 +0200
commit811e7df206c304987b3ce4984ea6840f1fa78440 (patch)
treea3c31a1ba2bb3e52de34cfa1327a6605ab0f8858 /lib/solidus_subscriptions/permission_sets
parentf55ce37d3d28d7c18b8458b657431bb7c07ac4a1 (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.rb19
-rw-r--r--lib/solidus_subscriptions/permission_sets/subscription_management.rb11
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