Role assignment on new user not working during Registration

Created on 29 March 2023, over 1 year ago
Updated 21 April 2023, over 1 year ago

Problem/Motivation

I have bene using the Registration role β†’ module for some time but it strikes me that here is a perfect example of where we can wheel-in ECA and thus remove yet another module from the system.

I have a very simple ECA that automatically assigns a role to a new-created User....

uuid: 46cb02a8-f597-4284-9411-fdf2cf6f9a96
langcode: en
status: true
dependencies:
  config:
    - system.action.user_add_role_action.student
  module:
    - eca_content
    - user
id: process_vb2wdrw
modeller: bpmn_io
label: 'Assign role(s) to new user'
version: '1.00'
weight: null
events:
  assign_roles_at_registration:
    plugin: 'content_entity:insert'
    label: 'Intercept newly created User'
    configuration:
      type: 'user user'
    successors:
      -
        id: assign_role_student
        condition: ''
conditions: {  }
gateways: {  }
actions:
  assign_role_student:
    plugin: 'eca_preconfigured_action:user_add_role_action.student'
    label: 'Assign Student role'
    configuration:
      object: user
    successors: {  }

Problem is though, it works fine when I create the user manually but not when they register themselves as a new user.

In my particular case, when the register, they are left Blocked awaiting activation by Admin but I don't see when that should put a stop to the assignment of any roles.

Can anyone advise here please?

πŸ’¬ Support request
Status

Fixed

Version

1.1

Component

Miscellaneous

Created by

πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SirClickALot
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    It's a permission issue. When a user registers themselves, the ECA model is executed under that user's context. As users are not allowed to assign themselves new roles - for good reasons ;-) - they can't do that under ECA either. But if you enhance your model such that you switch the user context to a permitted account, then it should be working there too.

  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

    Brilliant, thank you JΓΌrgen β†’ ,

    That worked a treat!

  • Status changed to Fixed over 1 year ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Excellent, thanks for your feedback.

  • I'm having a similar issue. I use a custom SAML module to check whether a user logging in has the Alpha role. If that user does not have the Alpha role, then it assigns that user the role. I have a use case where some users now require a restricted role. I could update the custom module, but it sounded like ECA could do what I needed. I need to remove the Alpha role from a user upon log in and add the Alpha Restricted role. This does not work. If the user logging in has the administrator role, then it can assign itself the Alpha Restricted role, but a plain Alpha user cannot assign itself the Restricted role - due to permissions as stated by jurgenhaas.

    I'm not sure what this means: "But if you enhance your model such that you switch the user context to a permitted account, then it should be working there too." I wonder if someone can offer some more details on what it means to switch the user context?

    I am using ECA, ECA CM, ECA UI, ECA User.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    @hannakras welcome to ECA. A note before I answer your question: commenting on fixed or closed issues is not recommended. Would be better to start a new one.

    As for "switch the user context to a permitted account", there is an ECA action User: switch current account that you can use to process your ECA model (or parts of it) in that different user context.

    You may get some ideas on how to build ECA models from the library in the ECA Guide, e.g. https://ecaguide.org/library/use%20case/eca_feature_demo/

  • @jurgenhaas, thank you for the etiquette tip. Will be sure to do that in future.

    And thank you for pointing me in the right direction. I was able to make my workflow work using two actions, Current user: load and User: switch current account.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024