Sha256: ad99ad27e268e59eed1e2f7e2501cd440c492aa1eac76f2123c29c2d44f79bc9

Contents?: true

Size: 1.58 KB

Versions: 28

Compression:

Stored size: 1.58 KB

Contents

module Workarea
  module Admin
    class FulfillmentTokensController < Admin::ApplicationController
      required_permissions :catalog

      before_action :find_sku
      before_action :find_token, only: :update

      def index
        @tokens =
          Fulfillment::Token
            .for_sku(@sku.id)
            .page(params[:page])
            .per(Workarea.config.per_page)
            .order_by(find_sort(Fulfillment::Token))
      end

      def create
        @token = Fulfillment::Token.new(sku: @sku.id)

        if @token.save
          flash[:success] = t('workarea.admin.fulfillment_tokens.flash_messages.created')
        else
          flash[:error] = t('workarea.admin.fulfillment_tokens.flash_messages.error')
        end

        redirect_to fulfillment_sku_tokens_path(@sku, new_token: @token.id)
      end

      def update
        result = @token.update(params[:token])

        if result && @token.enabled?
          flash[:success] = t('workarea.admin.fulfillment_tokens.flash_messages.enabled')
        elsif result
          flash[:success] = t('workarea.admin.fulfillment_tokens.flash_messages.disabled')
        else
          flash[:error] = t('workarea.admin.fulfillment_tokens.flash_messages.update_failed')
        end

        redirect_back_or fulfillment_sku_tokens_path(@sku)
      end

      private

      def find_sku
        model = Fulfillment::Sku.find(params['fulfillment_sku_id'])
        @sku = Admin::FulfillmentSkuViewModel.wrap(model, view_model_options)
      end

      def find_token
        @token = Fulfillment::Token.find(params[:id])
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.15 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.14 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.13 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.12 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.11 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.10 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.9 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.8 app/controllers/workarea/admin/fulfillment_tokens_controller.rb
workarea-admin-3.5.7 app/controllers/workarea/admin/fulfillment_tokens_controller.rb