Problem/Motivation

#404318 added two registration modes:

user — assign the configured role(s) only on self-registration
admin — assign the configured role(s) on self-registration and on any admin-created account
This covers the "should every created account get the role" question, but it doesn't cover a common permissions setup: a site has a role (e.g. "editor") that has administer users so it can create/manage accounts, but deliberately does not have administer permissions, because giving a non-admin role administer users in Drupal core also exposes the full Roles checkbox list on the user add/edit form (AccountForm::form() gates the whole Roles fieldset on a single permission, administer permissions, with no per-role granularity).

Without administer permissions, that role's "add user" form has no Roles field at all, so every account it creates lands with no role unless something assigns one automatically. registration_mode: admin looks like the fix, but it also forces the role onto accounts created by actual administrators (users who already hold administer permissions and can pick any role explicitly) — so admins get an unwanted extra role tag-along on every user they create, with no way to opt out short of manually removing it after the fact.

There's currently no mode that says "auto-assign only for the actors who need it (self-registration + non-admin account creators), and leave full control with actors who already have full control."

Proposed resolution

Add a third registration_mode option: non_admin — "Both user self registration and user creation except by admin."

In registration_role_user_presave(), when registration_mode is non_admin, assign the configured role(s) if the account is self-registered or the acting user creating it does not have the administer permissions permission. Users who do have administer permissions are skipped entirely, since they can already assign any role themselves via the normal Roles field.

This reuses the exact permission core itself checks to decide whether to show the Roles field (Drupal\user\AccountForm::form()), so the new mode's boundary lines up with "does this actor already have a Roles field to make an explicit choice in."

Patch attached, tested against a fresh composer update drupal/registration_role reinstall:

Self-registration → role assigned
Non-admin account creator (has administer users but not administer permissions) → role assigned
Admin account creator (has administer permissions) → role not forced

Remaining tasks

  • Review/feedback on the non_admin machine name and label wording
  • Update README.md to document the three modes (not included in the current patch)
  • Tests, if the module's test coverage conventions require them (module currently has none for registration_mode behavior)

User interface changes

Adds a third radio option to the "Registration mode" setting at /admin/people/registration-role

"Both user self registration and user creation except by admin"

Comments

nishtha.pradhan created an issue. See original summary.

nishtha.pradhan’s picture

StatusFileSize
new2.73 KB
nishtha.pradhan’s picture

Status: Active » Needs review

I tested, and it cleanly applies. Needs to be validated.