summaryrefslogtreecommitdiff
path: root/lib/solidus_subscriptions/permission_sets/subscription_management.rb
blob: 8f5edfbcb59d689db464202d07fc811d9c00bf46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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