Sha256: 20be57d9bf5b827410bb0bc257b748d814f4aa404f31d9838d0c2f5e1786977f

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern to include permission to a resource not related with components
  # od a participatory space.
  module HasResourcePermission
    extend ActiveSupport::Concern

    included do
      # An association with the permissions settings for the resource
      has_one :resource_permission, as: :resource, class_name: "Decidim::ResourcePermission"

      delegate :resource_manifest, :resource_key, to: :class

      # Public: Whether the permissions for this object actions can be set at resource level.
      def allow_resource_permissions?
        false
      end

      # Public: Returns permissions for this object actions if they can be set at resource level.
      def permissions
        resource_permission&.permissions if allow_resource_permissions?
      end
    end

    class_methods do
      # Finds the resource manifest for the model.
      #
      # Returns a Decidim::ResourceManifest
      def resource_manifest
        Decidim.find_resource_manifest(self)
      end

      def resource_key
        model_name.param_key
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

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