Module: Tasker::Authorization

Defined in:
lib/tasker/authorization.rb,
lib/tasker/authorization/errors.rb,
lib/tasker/authorization/base_coordinator.rb,
lib/tasker/authorization/resource_registry.rb,
lib/tasker/authorization/resource_constants.rb

Overview

Authorization module providing resource-based authorization for Tasker.

This module implements a flexible, configuration-driven authorization system that follows the same dependency injection pattern as the authentication system. It provides:

  • Resource-based permissions using "resource:action" patterns
  • Pluggable authorization coordinators for custom logic
  • Automatic controller integration via concerns
  • User model integration via the Authorizable concern

Examples:

Basic configuration

Tasker::Configuration.configuration do |config|
  config.auth do |auth|
    auth.enabled = true
    auth.coordinator_class = 'MyAuthorizationCoordinator'
    auth.user_class = 'User'
  end
end

Custom authorization coordinator

class MyAuthorizationCoordinator < Tasker::Authorization::BaseCoordinator
  protected

  def authorized?(resource, action, context = {})
    case resource
    when 'tasker.task'
      user.can_manage_tasks?
    else
      false
    end
  end
end

Defined Under Namespace

Modules: ResourceConstants Classes: AuthorizationError, BaseCoordinator, ConfigurationError, ResourceRegistry, UnauthorizedError

Class Method Summary collapse

Class Method Details

.action_exists?(resource, action) ⇒ Boolean

Check if an action exists for a resource

Parameters:

  • resource (String)

    Resource name

  • action (Symbol, String)

    Action name

Returns:

  • (Boolean)

    True if action exists for the resource



71
72
73
# File 'lib/tasker/authorization.rb', line 71

def self.action_exists?(resource, action)
  ResourceRegistry.action_exists?(resource, action)
end

.all_permissionsArray<String>

Get all available permissions in "resource:action" format

Returns:

  • (Array<String>)

    All available permissions



54
55
56
# File 'lib/tasker/authorization.rb', line 54

def self.all_permissions
  ResourceRegistry.all_permissions
end

.resource_exists?(resource) ⇒ Boolean

Check if a resource exists

Parameters:

  • resource (String)

    Resource name

Returns:

  • (Boolean)

    True if resource exists



62
63
64
# File 'lib/tasker/authorization.rb', line 62

def self.resource_exists?(resource)
  ResourceRegistry.resource_exists?(resource)
end

.resourcesHash

Get all available resources and their actions

Returns:

  • (Hash)

    Resource registry



47
48
49
# File 'lib/tasker/authorization.rb', line 47

def self.resources
  ResourceRegistry.resources
end