Skip to content

Access Control & Feature Flags ​

How modules declare domain permissions (access_config.php) and runtime feature switches (flag_config.php), enforce them inside Core/Services/, and sync them via LimsRouter's built-in Master consoles.

ConceptConfig fileRuntime checkWhen denied/offMaster exception?
Access Controlaccess_config.phpCurrentUser::can($module, $action)Throw 403 (HttpException)Yes (Master bypasses grants)
Feature Flagsflag_config.phpCurrentUser::hasFlag($module, $flag)Throw 404 (feature absent)No (off means off for everyone)

Like Database/, LimsRouter automatically discovers access_config.php and flag_config.php in the parent module and all of its submodules.


Access control (access_config.php) ​

Place access_config.php in your module's root directory (never inside an INSTALL/ folder), or in a submodule's root folder when it needs its own independent permission module key:

php
<?php

return [
    'module' => 'sales',
    'label' => 'Sales',
    'primary_table' => 'orders',
    'related_tables' => ['order_lines', 'invoices'],
    'actions' => [
        'approve_orders' => [
            'label' => 'Approve orders',
            'description' => 'Approve and cancel orders.',
            'default' => false,
            'risk' => 'high',
        ],
    ],
];

Rules ​

  • module is the grant key prefix: sales.approve_orders. A submodule's config gets its own key (e.g. sales_invoices → sales_invoices.void).
  • Built-in actions are automatic: Only declare domain-specific actions. add, edit, remove, and settings are added automatically by the sync.
  • Enforce in Core/Services/: Always check CurrentUser::can('sales', 'approve_orders') inside services and throw an HttpException with status 403. Pass booleans or a <Record>PermissionsDTO to Angular solely to show/hide buttons.
  • Combine with ownership where needed (e.g. "the author of a draft, or anyone with sales.approve_orders").

Syncing access rights (?feature=access) ​

Master users get a built-in access sync page on every LimsRouter module at /admin/Modules/<Module>/View?feature=access. It inspects the module and all of its submodules, highlights any differences from the registry, and lets Master users sync with one click. Whenever a sync would change something, LimsRouter displays a warning banner above every page of the module on every environment.

Unsynced actions are blocked in production

Until an action is synced at ?feature=access, it is allowed on local/staging environments but denied in production. Always sync right after deploying new or renamed actions.


Feature flags (flag_config.php) ​

Place flag_config.php in your module's root folder (or a submodule's root folder for submodule-scoped flags):

php
<?php

return [
    'module' => 'sales',
    'label' => 'Sales',
    'flags' => [
        'bulk_approve' => [
            'label' => 'Bulk approve',
            'description' => 'Approve several orders at once from the register.',
            'default' => false,
        ],
    ],
];

Rules ​

  • module matches access_config.php, keying the flag as sales.bulk_approve. Keys use letters, digits, _, and -.
  • Checking a flag: Call CurrentUser::hasFlag('sales', 'bulk_approve') where the feature starts. Return 404 when a flagged endpoint is disabled (as if the feature didn't exist) and pass a boolean prop (e.g. hasBulkApprove) to hide UI entry points.
  • Flags are NOT permissions: Master users receive no exception — an off flag is off for Master users too.
  • Retire flags when permanent: Once a feature is on everywhere for good, remove the flag and its checks; the next sync switches it off cleanly in the registry.

Managing flags (?feature=flags) ​

Master users sync and configure flags at /admin/Modules/<Module>/View?feature=flags (with automatic out-of-sync notices above every module page). For each synced flag they can set:

  • Global setting: Follow flag_config.php default, force on for everyone, or force off for everyone.
  • Role & user overrides: Turn on/off for a specific role or user regardless of the global setting. User overrides win over role overrides.

Syncing never alters existing settings or overrides. Every sync and change is audited in feature_flag_log.

See the access-control & feature-flags API Reference for underlying package classes and sync APIs.

Labmin LIMS Module Developer Documentation