Sha256: a652ced5229f35be1305701346266b3b14a2da963ea77426f143c5ad0770e175

Contents?: true

Size: 1.15 KB

Versions: 58

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # This concern contains the logic related to scopes included by components.
  module ScopableComponent
    extend ActiveSupport::Concern

    included do
      include Scopable

      validate :scope_belongs_to_participatory_space

      # Whether the component or participatory_space has subscopes or not.
      #
      # Returns a boolean.
      def has_subscopes?
        (scopes_enabled? || participatory_space.scopes_enabled?) && subscopes.any?
      end

      # Public: Returns the component Scope
      def scope
        return participatory_space.scope unless scopes_enabled?

        participatory_space.scopes.find_by(id: settings.scope_id)
      end

      # Returns a boolean.
      def scopes_enabled
        settings.try(:scopes_enabled)
      end

      private

      # Validation to ensure that the component is scoped within its participatory space Scope.
      def scope_belongs_to_participatory_space
        return if !scopes_enabled? || !participatory_space

        errors.add(:scope, :invalid) if participatory_space.out_of_scope?(scope)
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-core-0.29.1 lib/decidim/scopable_component.rb
decidim-core-0.28.4 lib/decidim/scopable_component.rb
decidim-core-0.27.9 lib/decidim/scopable_component.rb
decidim-core-0.29.0 lib/decidim/scopable_component.rb
decidim-core-0.28.3 lib/decidim/scopable_component.rb
decidim-core-0.27.8 lib/decidim/scopable_component.rb
decidim-core-0.29.0.rc4 lib/decidim/scopable_component.rb
decidim-core-0.29.0.rc3 lib/decidim/scopable_component.rb
decidim-core-0.29.0.rc2 lib/decidim/scopable_component.rb
decidim-core-0.29.0.rc1 lib/decidim/scopable_component.rb
decidim-core-0.28.2 lib/decidim/scopable_component.rb
decidim-core-0.27.7 lib/decidim/scopable_component.rb
decidim-core-0.28.1 lib/decidim/scopable_component.rb
decidim-core-0.27.6 lib/decidim/scopable_component.rb
decidim-core-0.26.10 lib/decidim/scopable_component.rb
decidim-core-0.26.9 lib/decidim/scopable_component.rb
decidim-core-0.28.0 lib/decidim/scopable_component.rb
decidim-core-0.27.5 lib/decidim/scopable_component.rb
decidim-core-0.28.0.rc5 lib/decidim/scopable_component.rb
decidim-core-0.28.0.rc4 lib/decidim/scopable_component.rb