Sha256: dcba966ae7ebe3025a2729da7e3ac2763dc58f2c3c49a4f49edf4f26a34c0df8

Contents?: true

Size: 1.17 KB

Versions: 38

Compression:

Stored size: 1.17 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

      alias_method :manifest, :resource_manifest

      # 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

38 entries across 38 versions & 1 rubygems

Version Path
decidim-core-0.27.0.rc1 lib/decidim/has_resource_permission.rb
decidim-core-0.26.2 lib/decidim/has_resource_permission.rb
decidim-core-0.26.1 lib/decidim/has_resource_permission.rb
decidim-core-0.26.0 lib/decidim/has_resource_permission.rb
decidim-core-0.26.0.rc2 lib/decidim/has_resource_permission.rb
decidim-core-0.26.0.rc1 lib/decidim/has_resource_permission.rb
decidim-core-0.25.2 lib/decidim/has_resource_permission.rb
decidim-core-0.25.1 lib/decidim/has_resource_permission.rb
decidim-core-0.25.0 lib/decidim/has_resource_permission.rb
decidim-core-0.25.0.rc4 lib/decidim/has_resource_permission.rb
decidim-core-0.25.0.rc3 lib/decidim/has_resource_permission.rb
decidim-core-0.25.0.rc2 lib/decidim/has_resource_permission.rb
decidim-core-0.25.0.rc1 lib/decidim/has_resource_permission.rb
decidim-core-0.24.3 lib/decidim/has_resource_permission.rb
decidim-core-0.23.6 lib/decidim/has_resource_permission.rb
decidim-core-0.24.2 lib/decidim/has_resource_permission.rb
decidim-core-0.23.5 lib/decidim/has_resource_permission.rb
decidim-core-0.24.1 lib/decidim/has_resource_permission.rb
decidim-core-0.24.0 lib/decidim/has_resource_permission.rb
decidim-core-0.24.0.rc2 lib/decidim/has_resource_permission.rb