summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/permission_sets/default_customer.rb
blob: ebe888edfd8a1c3dda2c20d76585dd39e5d90cd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module SolidusSubscriptions
  module PermissionSets
    class DefaultCustomer < ::Spree::PermissionSets::Base
      def activate!
        can [:display, :update, :skip, :cancel], Subscription, ['user_id = ?', user.id] do |subscription, guest_token|
          (subscription.guest_token.present? && subscription.guest_token == guest_token) ||
            (subscription.user && subscription.user == user)
        end

        can [:display, :update, :destroy], 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