Overview
Restrictions allow you to limit access based on custom criteria beyond simple permissions. GAC includes built-in restrictions for date ranges and entity filtering, with support for custom restriction types.Understanding Restrictions
Restrictions are organized into:- Categories - Broad restriction types (e.g.,
by_date,by_branch) - Methods - Specific rules within a category (e.g.,
allow,deny,in_range) - Data - JSON configuration for the restriction
Restriction Tables
Built-in Restrictions
GAC includes two restriction categories with six methods.Entity Restrictions (by_branch)
Control access to specific entities like branches, departments, or locations.Allow Method - Whitelist
Allow Method - Whitelist
Only allow access to specific entities.Database Entry:Code Implementation:The user can ONLY access branches 5, 12, and 18.
Deny Method - Blacklist
Deny Method - Blacklist
Deny access to specific entities (allow all others).Database Entry:Code Implementation:The user can access all branches EXCEPT 3 and 7.
Date Restrictions (by_date)
Control access based on time periods.In Range Method
In Range Method
Allow access only within a date range.Database Entry:Code Implementation:
Out Range Method
Out Range Method
Allow access outside a date range.Database Entry:Access is blocked during July 2024 (vacation period).
Before Method
Before Method
Allow access before a specific date.Database Entry:With Date Wildcards:Wildcards from
src/Restrictions/ByDate.php:147:%Y- Current year%M- Current month%D- Current day
After Method
After Method
Allow access after a specific date.Database Entry:User can only access after June 1, 2024.
Loading Restrictions
Basic Loading
Restriction Types
GAC loads two types of restrictions:- Personal/Role restrictions - Specific to the entity and their roles
- Global restrictions - Apply to all entities (entity_type = ‘3’)
src/GAC.php:165:
Checking Restrictions
Check if Restriction Exists
Get and Validate Restrictions
Multiple Restriction Validation
Practical Examples
Multi-branch Application
Time-limited Access
Global Restrictions
Restriction Priority
Similar to permissions, restrictions have a priority system (src/GAC.php:475):
- Personal restrictions (priority: -1) - Direct to user/client
- Role restrictions (priority: 0-4) - Inherited from roles
- Global restrictions - Always checked
src/GAC.php:503:
Getting Error Details
When a restriction fails, you can get details:src/Restrictions/Restriction.php:40:
Custom Restriction Categories
You can add custom restriction types. See Custom Adapters for creating custom restriction classes. Example: IP-based restrictionNext Steps
Cache Management
Optimize performance with cache strategies
Custom Adapters
Create custom restriction types and adapters