Sha256: ade1b2640f2f1215ea4d143850b84dcdff70657297898a3151aedfea1c7e3494

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

module Spree
  module Admin
    class WebhooksSubscribersController < ResourceController
      create.before :process_subscriptions
      update.before :process_subscriptions

      def index
        params[:q] ||= {}
        params[:q][:s] ||= 'created_at desc'

        search = Webhooks::Subscriber.accessible_by(current_ability).ransack(params[:q])
        @webhooks_subscribers = search.result.
                                includes(:events).
                                page(params[:page]).
                                per(params[:per_page])
      end

      def show
        @webhooks_subscriber = Webhooks::Subscriber.find(params[:id])
        @events = @webhooks_subscriber.events.order(created_at: :desc).page(params[:page]).per(params[:per_page])
      end

      private

      def resource
        @resource ||= Spree::Admin::Resource.new 'spree/admin/webhooks/subscribers', 'subscribers', nil
      end

      def process_subscriptions
        params[:webhooks_subscriber][:subscriptions] = if params[:subscribe_to_all_events] == 'true'
                                                         ['*']
                                                       else
                                                         selected_events
                                                       end

        params[:webhooks_subscriber] = params[:webhooks_subscriber].except(*supported_events.keys)
      end

      def selected_events
        supported_events.select { |resource, _events| params[:webhooks_subscriber][resource] == 'true' }.values.flatten
      end

      def supported_events
        @supported_events ||= Spree::Webhooks::Subscriber.supported_events
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_backend-4.8.4 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.8.3 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.8.2 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.8.1 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.7.2 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.6.2 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.7.1 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.7.0 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.6.1 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.6.0 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.5.1 app/controllers/spree/admin/webhooks_subscribers_controller.rb
spree_backend-4.5.0 app/controllers/spree/admin/webhooks_subscribers_controller.rb