Sha256: 9967aaf6adbc5a972800cabff4b325a9ae2a95b07b54a71b42af26324941e3dc

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module Decidim
  module Components
    # Controller from which all component engines inherit from. It's in charge of
    # setting the appropiate layout, including necessary helpers, and overall
    # fooling the engine into thinking it's isolated.
    class BaseController < Decidim::ApplicationController
      include Settings
      include ActionAuthorization

      include ParticipatorySpaceContext
      participatory_space_layout

      helper Decidim::FiltersHelper
      helper Decidim::OrdersHelper
      helper Decidim::ResourceReferenceHelper
      helper Decidim::TranslationsHelper
      helper Decidim::IconHelper
      helper Decidim::ResourceHelper
      helper Decidim::ScopesHelper
      helper Decidim::ActionAuthorizationHelper
      helper Decidim::AttachmentsHelper
      helper Decidim::SanitizeHelper

      helper_method :current_component,
                    :current_participatory_space,
                    :current_manifest

      skip_authorize_resource

      before_action do
        authorize! :read, current_component
      end
      before_action :redirect_unless_feature_private

      def current_participatory_space
        request.env["decidim.current_participatory_space"]
      end

      deprecate current_feature: "current_feature is deprecated and will be removed from Decidim's next release"

      def current_component
        request.env["decidim.current_component"]
      end
      alias current_feature current_component

      def current_manifest
        @current_manifest ||= current_component.manifest
      end

      def ability_context
        super.merge(
          current_manifest: current_manifest,
          current_settings: current_settings,
          component_settings: component_settings
        )
      end

      def redirect_unless_feature_private
        raise ActionController::RoutingError, "Not Found" unless current_user_can_visit_space?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.11.2 app/controllers/decidim/components/base_controller.rb
decidim-core-0.11.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.11.0.pre1 app/controllers/decidim/components/base_controller.rb