Sha256: d4c6508f3d324bbc3aecca3a1e0398a9358760f1d53543aaa92fc69f375f08a6

Contents?: true

Size: 1.27 KB

Versions: 66

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  #
  # Takes care of holding and accessing permissions classes for each artifact.
  #
  class PermissionsRegistry
    def initialize
      @registry = {}
    end

    # Syntactic sugar for the `chain_for` instance method.
    def self.chain_for(artifact)
      ::Decidim.permissions_registry.chain_for(artifact)
    end

    # Returns the registered array of permissions for the given `artifact`.
    #
    # +artifact+ is expected to be the class or module that declares `NeedsPermission.permission_class_chain`.
    def chain_for(artifact)
      @registry[artifact_to_key(artifact)]
    end

    # Registers the of `Permissions` for the given `artifact`.
    #
    # +artifact+ is expected to be the class or module that declares `NeedsPermission.permission_class_chain`.
    # +permission_classes+ are subclasses of `DefaultPermissions`.
    def register_permissions(artifact, *permission_classes)
      @registry[artifact_to_key(artifact)] = permission_classes.dup
    end

    # Registry accepts the class or the class name of the artifact,
    # but the registry only indexes by the name.
    # Artifact name normalization is done here.
    def artifact_to_key(artifact)
      artifact.respond_to?(:name) ? artifact.name : artifact
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

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