Skip to the content.

← Back to Awards Plugin

5.2.11 Level Policy Reference

Last Updated: December 4, 2025
Status: Complete
Plugin: Awards
Source: plugins/Awards/src/Policy/LevelPolicy.php

Overview

The LevelPolicy class provides authorization control for Level entities within the Awards plugin. It manages access to award levels including precedence control, hierarchical ordering, and administrative oversight through integration with the KMP RBAC system.

Class Definition

namespace Awards\Policy;

class LevelPolicy extends BasePolicy

All authorization methods are inherited from BasePolicy and delegate to the centralized _hasPolicy() method for consistent RBAC integration.

RBAC Integration Architecture

Permission-Based Authorization

BasePolicy Inheritance

The policy inherits standard CRUD authorization methods:

Method Purpose
canView() Level viewing with organizational access validation
canAdd() Level creation with administrative permission requirements
canEdit() Level editing with precedence adjustment authorization
canDelete() Level removal with precedence integrity validation
canIndex() Level listing with organizational scoping

Level Operations Governance

Authorization is enforced for all level operations:

Operation Authorization Requirements
Creation Administrative permissions for creating levels and defining precedence
Modification Edit permissions with precedence adjustment authorization
Deletion Delete permissions with precedence integrity protection
Precedence Management Specialized permissions for hierarchical ordering operations

Authorization Flow

sequenceDiagram
    participant Controller
    participant Authorization
    participant LevelPolicy
    participant BasePolicy
    participant PermissionsLoader
    
    Controller->>Authorization: authorize($level)
    Authorization->>LevelPolicy: canEdit($user, $level)
    LevelPolicy->>BasePolicy: _hasPolicy()
    BasePolicy->>BasePolicy: before() - Super User Check
    BasePolicy->>PermissionsLoader: Resolve Permissions
    PermissionsLoader-->>BasePolicy: Permission Result
    BasePolicy-->>LevelPolicy: Authorization Decision
    LevelPolicy-->>Authorization: bool
    Authorization-->>Controller: Authorized/Denied

Usage Examples

Controller Integration

// Standard CRUD authorization in LevelsController
public function view($id) {
    $level = $this->Levels->get($id);
    $this->Authorization->authorize($level); // Uses canView()
    $this->set(compact('level'));
}

public function edit($id) {
    $level = $this->Levels->get($id);
    $this->Authorization->authorize($level); // Uses canEdit()
    // Level editing logic...
}

Administrative Operations

// Administrative level management
public function delete($id) {
    $level = $this->Levels->get($id);
    $this->Authorization->authorize($level, 'delete');
    // Level deletion with precedence validation...
}

Service Layer Authorization

// Level management service with policy validation
public function updateLevel($levelId, $data) {
    $level = $this->Levels->get($levelId);
    if (!$this->Authorization->can($level, 'edit')) {
        throw new ForbiddenException('Not authorized to edit level');
    }
    return $this->Levels->patchEntity($level, $data);
}

Integration Points

Levels Controller Integration

RBAC System Integration

Awards Plugin Integration

Security Considerations

Access Control Security

Data Protection