Class: Yes::Core::Aggregate::Dsl::ClassResolvers::Authorizer

Inherits:
Base
  • Object
show all
Defined in:
lib/yes/core/aggregate/dsl/class_resolvers/authorizer.rb

Overview

Creates and registers authorizer classes for aggregates based on Yes::Core::Authorization::CommandCerbosAuthorizer.

This class resolver generates authorizer classes associated with aggregates. Each authorizer class defines a RESOURCE constant containing the associated read model class and resource name used for authorization checks.

Examples:

Generated authorizer class structure

# Generated for a 'User' aggregate
class GeneratedAuthorizer < Yes::Core::Authorization::CommandCerbosAuthorizer
  RESOURCE = { read_model: Auth::Resources::User, name: 'user' }.freeze
end

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Authorizer

Initializes a new authorizer class resolver

Parameters:

  • options (Yes::Core::Aggregate::HasAuthorizer::AuthorizerOptions)

    Data object containing:

    • authorizer_base_class [Class] The authorizer class to use.

    • context [String] The name of the context (e.g., ‘CompanyManagement’)

    • aggregate [String] The name of the aggregate (e.g., ‘Company’)

    • read_model_class [Class, nil] Optional read model class. Defaults to ‘Auth::Resources::<AggregateName>`.

    • resource_name [String, nil] Optional resource name for Cerbos. Defaults to aggregate name underscored (e.g., ‘company’).

    • authorizer_block [Proc, nil] An optional block defining the custom logic for the ‘call` method if `authorizer_base_class` is not `Yes::Core::Authorization::CommandCerbosAuthorizer`.

Since:

  • 0.1.0



33
34
35
36
37
38
39
40
41
42
# File 'lib/yes/core/aggregate/dsl/class_resolvers/authorizer.rb', line 33

def initialize(options)
  @resource_name = options.resource_name
  @read_model_class = options.read_model_class
  @authorizer_class = options.authorizer_base_class
  @custom_call_logic = options.authorizer_block
  @draftable = options.draftable
  @changes_read_model_class = options.changes_read_model_class
  # Base class expects context_name and aggregate_name parameters
  super(options.context, options.aggregate)
end

Instance Method Details

#callClass

Creates and registers the authorizer class in the Yes::Core configuration

Returns:

  • (Class)

    The found or generated authorizer class that was registered

Since:

  • 0.1.0



47
48
49
50
51
52
53
# File 'lib/yes/core/aggregate/dsl/class_resolvers/authorizer.rb', line 47

def call
  Yes::Core.configuration.register_aggregate_authorizer_class(
    context_name,
    aggregate_name,
    find_or_generate_class
  )
end