Light API 0.18.0 is a public beta: a minor release such as 0.19.0 may still break. What that means for your module
Light
Developer guideRecipes

Users and permissions

Put your ACL resources in a role area, so roles reach your screens.

Light's roles are built from areas: Orders, Products, Customers, Content and so on. The Staff preset and every custom role tick areas, not ACL resources. This recipe puts your module's resources in an area, so users whose role ticks that area reach your screens.

When to use it

  • Your screens sit under a core section (Built for Light, rule 1) and their ACL resources hang under your module's own menu, which no area covers. Without this, only full-access admins see them.
  • Add your resources to the area whose screens yours sit beside. Don't add an area for one module.

Steps

Role areas (pool role_areas) are global: they go in etc/di.xml, because setup:upgrade reads them. Add your module's top resource as a later item of the area. The pilot adds its account requests to Customers:

app/code/Disrex/RequestAnAccountLight/etc/di.xml
<type name="Mrx\Settings\Model\Users\RoleAreas">
    <arguments>
        <argument name="areas" xsi:type="array">
            <item name="customers" xsi:type="array">
                <item name="resources" xsi:type="array">
                    <item name="account_requests" xsi:type="string">Disrex_RequestAnAccount::registration_requests</item>
                </item>
            </item>
        </argument>
    </arguments>
</type>
  • DI merges it into the core area as a later item, so the area's main resource stays the core one.
  • The resources below yours in acl.xml come with it: view, update, delete and your settings.
  • Don't add resources to RolePresets (pool role_presets): a preset role that already exists keeps its resources.

Then run bin/magento setup:upgrade --keep-generated. Preset roles that already exist pick up the new resources on every setup:upgrade; new preset roles and custom roles get them when the area is ticked.

Besides its areas, every role Light makes gets the same few resources: Home, Light, search, the user's own account and the user's own second factor (Magento_TwoFactorAuth::tfa, without which Magento_TwoFactorAuth refuses the sign-in after the password). They are no area and show no checkbox. On the next setup:upgrade the Staff and Shipping staff preset roles (named so and holding Mrx_Light::light) get any they lack, and every other role that holds Mrx_Light::light without full access, also one made in Magento's own role editor with Light ticked, gets the second factor if it lacks it; a resource such as Home that a merchant removed in the advanced view stays removed. The second factor comes alone, without its parents Magento_Backend::system and Magento_User::acl (since 0.4.6): Magento allows a resource whose parent the role is denied, and Magento_Backend::system itself opens admin/system/*, the Varnish VCL export and the media storage sync. A role keeps System when an area needs it (the cache screen of Settings sits below System). Light's own screens only add, so a role saved before 0.4.6 keeps the parents it held until it is saved in Magento's own role editor with Light ticked, which drops them again, or until you untick System in the advanced view. A role saved in Magento's own role editor with Light ticked gets the second factor on that save too (since 0.4.3), without its parents (Magento's role tree posts them with every ticked resource; Light drops them unless another ticked resource sits below them), and nothing else; "All resources" and roles without Light are saved as ticked. In Magento the second factor also opens the web API routes that name a user (/V1/tfa/user-providers/:userId, providers-to-activate/:userId and default-provider-code/:userId); since 0.4.4 an admin token uses them for another user only when its role also holds user management (Magento_User::acl_users), so a Light role reaches its own user's second factor alone. Full access and integrations keep Magento's behaviour: an integration that holds the second factor resource can still read and change any admin's second factor, so give that resource to an integration only when it should. Don't put your module's resources there: join an area.

A bridge adds a resource to an area

Mrx_SeoMageos adds Mage-OS SEO's MageOS_Seo::organization to the Settings area with a later item in etc/di.xml, the same way as the pilot above. Because the pool is global, the item is there whenever the bridge is installed. A role that ticks Settings then gets that resource with its parents, and with it Mage-OS SEO's own Organization form. Without the bridge the area is as before.

Preset roles

The Staff and Shipping staff presets become roles the first time someone gets them, through Add user or the role editor. Such a role holds exactly its areas and the resources every role gets, each with the resources below it, plus their parents. A parent comes alone: Magento_Backend::stores above a setting, or Magento_Backend::system above the cache screen, never brings the configuration or the user and role screens below it. The second factor brings no parent at all. A resource you join to an area reaches a preset role only through that area.

Light 0.1.0 to 0.1.2 broke that rule for roles made through Add user: they got every resource of the admin. The first setup:upgrade on 0.1.3 resets a role that carries that leak (named Staff or Shipping staff, holding Mrx_Light::light and both Magento_User::acl_users and Magento_User::acl_roles) to exactly its preset, and logs what it removed; a role without Mrx_Light::light is never reset or completed, whatever its name. Only on a shop that ran 0.1.0 to 0.1.2, whose role completion gave Light to any role named Staff or Shipping staff, can a merchant's own role of that name carry the signature (Upgrading from 0.1.2 to 0.1.3). A module that gives a preset role a resource outside the areas, in its own data patch, loses it there; join an area instead.

A resource that spends money gets an area of its own, so the Staff preset doesn't bring it: Mrx_Ai's Mrx_Ai::bulk_translate (starting and steering a bulk translation run, since 0.6.0) sits directly below the admin, outside both Mrx_Light::light (which every role gets with all below it) and the catalog (which the Products area brings), and is the area Translate with AI (ai_translation, described as "Translate products with AI from a run or for a new product, and pause or undo it. Each translation is paid from the AI budget.") that no preset ticks. Its sibling Mrx_Ai::translations_view (since 0.7.0: see the translation report and log on Products > Translations, spend nothing) is in the area Products (products), so every product editor and the Staff preset hold it.

An area's exclude list names resources below it that stay with the owner: the Settings area leaves out sign-in security and developer settings, the Products area the reservation clean-up (MageOS_InventoryReservationsGrid::clean and ::delete) since 0.1.4. A role that held such a resource before keeps it on setup:upgrade, because role completion only adds. The next release's first setup:upgrade takes it from the Staff and Shipping staff roles Light made, once, and logs what it took; saving a preset role in the role editor takes away what its areas exclude every time. A custom role keeps what it has outside its areas (Upgrading).

On Mage-OS 4.0 the Settings area also lists MageOS_Seo::config and MageOS_Aeo::config (from Mrx_SeoMageos' etc/di.xml, beside MageOS_Seo::organization), so a Settings-only role opens the Visibility pages. The same resources open those stock sections in the advanced view for that role. They sit below Magento_Config::config, so a role made before 0.16.0 already holds them.

What the admin sees

Add role on Settings > Users: a role ticks the areas it can open, and a module's screens come with the area they join

A Staff user sees Customers > Account requests and can work there. A custom role with Customers ticked reaches it too.

The invite

Adding a user on Settings > Users shows no password. Light mails the new user "You now have access to" the store name, with a button to choose a password on Magento's own admin reset page. The link works as long as admin/security/password_reset_link_expiration_period says (2 hours by default), and the mail says so. It goes out in the user's admin language, in the brand kit of the main channel. When the mail fails, the screen shows the link to pass on instead. "Send invite again" in the user's row sends a new link until the user first signs in.

The invite a new user receives: a greeting, who gave them access, the "Choose your password" button and how long the link works

Passkeys

With Mage-OS 4.0's MageOS_PasskeyAuth on, Sign-in and security on Settings > Users gets "Staff can sign in with a passkey" (adds the two-factor provider passkey to twofactorauth/general/force_providers or takes it out, never the last provider) and "Customers can sign in with a passkey" (customer/passkey/enabled, All channels; a channel's own value shows under it with a reset). The staff switch needs Magento_TwoFactorAuth::config, which no role area grants, so a Settings-only role doesn't see it. While staff passkeys are on, Your account shows "Your passkey" and "Set up a new passkey", which resets only the signed-in admin's passkey after the current password. Light names no Mage-OS class for this, so a module that builds on it reads the same config paths.

Sign-in and security on Settings > Users with the staff and customer passkey switches

ACL

The area grants your resources; your controllers, nav items and counters still check them one by one.

Check it

  • bin/magento mrx:light:doctor --module=<your module>: acl_unreachable warns when your module adds Light screens and no area reaches any of its resources (one reached resource is enough for the rule, so check each screen in the browser), and wrong_area about RoleAreas in etc/adminhtml/di.xml.
  • tests/playwright/users-and-permissions.spec.ts must still pass, and the pilot's browser test checks an existing Staff role.
  • A browser test that adds a user reads the invite link from the mail, as tests/playwright/user-invite.spec.ts does; the answer of light/settings/usercreate holds no password.

Pitfalls

  • A new area added to a preset reaches only roles made afterwards. Add your resources to an existing area instead.
  • A resource under an area is granted, never taken away: removing your item later leaves the grant on roles that have it.

Last updated on

On this page