Sha256: 65e76ee6b45757bbacc5f3b2449cd3b7e5289cb157d7b269b8c357bed764d415

Contents?: true

Size: 1.91 KB

Versions: 11

Compression:

Stored size: 1.91 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 Decidim::NeedsPermission

      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 Decidim::PadHelper

      helper_method :current_component,
                    :current_participatory_space,
                    :current_manifest

      before_action do
        enforce_permission_to :read, :component, component: current_component
      end

      before_action :redirect_unless_feature_private

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

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

      def current_manifest
        @current_manifest ||= current_component.manifest
      end

      def permission_scope
        :public
      end

      def permission_class_chain
        [
          current_component.manifest.permissions_class,
          current_participatory_space.manifest.permissions_class,
          Decidim::Admin::Permissions,
          Decidim::Permissions
        ]
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-core-0.20.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.20.0 app/controllers/decidim/components/base_controller.rb
decidim-core-0.19.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.18.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.19.0 app/controllers/decidim/components/base_controller.rb
decidim-core-0.17.2 app/controllers/decidim/components/base_controller.rb
decidim-core-0.18.0 app/controllers/decidim/components/base_controller.rb
decidim-core-0.17.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.16.1 app/controllers/decidim/components/base_controller.rb
decidim-core-0.17.0 app/controllers/decidim/components/base_controller.rb
decidim-core-0.16.0 app/controllers/decidim/components/base_controller.rb