Apply for role module is doing modification to user role, however, it does not follows 'Drupal way' of user update process. Hence user update event - update & after_update are not fired.

Attached is the patch to add in the user update event when the user's roles are modified.

After which you can make use of module such as workflow_ng to create trigger when a user role changed.

CommentFileSizeAuthor
apply_for_role_miss_user_invoke.patch3.38 KBckng

Comments

ckng’s picture

Just in case someone needed this.
A sample workflow_ng rule to trigger when a role is approved.
For deletion or revoked rules, just clone the same rule and toggle the Negate of both conditions.

array (
  'cfg_6' => 
  array (
    '#event' => 'user_update',
    '#altered' => false,
    '#active' => 1,
    '#type' => 'configuration',
    '#label' => 'Your_Role role is approved',
    '#id' => 1,
    '#weight' => '0',
    '#module' => 'workflow-ng',
    0 => 
    array (
      '#name' => 'workflow_ng_condition_user_hasrole',
      '#id' => 2,
      '#type' => 'condition',
      '#label' => 'User has new role',
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 1,
        ),
        'operation' => 'OR',
      ),
      '#argument map' => 
      array (
        'account' => 'user',
      ),
    ),
    1 => 
    array (
      '#type' => 'action',
      '#name' => 'workflow_ng_action_mail',
      '#settings' => 
      array (
        'to' => '[account:mail]',
        'to_args' => 
        array (
          0 => 'account',
        ),
        'from' => 'your_email@example.com',
        'from_args' => 
        array (
        ),
        'subject' => 'Application for role "Your_Role" has been approved',
        'subject_args' => 
        array (
        ),
        'message' => '[account:user],

Your application for the role "Your_Role" in example.com has been approved.
',
        'message_args' => 
        array (
          0 => 'account',
          1 => 'account_unchanged',
        ),
      ),
      '#id' => 3,
    ),
    2 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_user_hasrole',
      '#argument map' => 
      array (
        'account_unchanged' => 'user',
      ),
      '#negate' => 1,
      '#settings' => 
      array (
        'roles' => 
        array (
          0 => 1,
        ),
        'operation' => 'OR',
      ),
      '#label' => 'User has no Your_Role role previously',
    ),
    '#name' => 'cfg_6',
  ),
)
tborrome’s picture

Thanks, I'm about to try this out as I need this functionality.

do you have a workflow_ng rule for email to be sent to admin when a user applies for a role?

is this possible with applyforrole with workflow-ng?

Soren Jones’s picture

Status: Needs review » Postponed (maintainer needs more info)

Does #351916: Module should not directly manipulate users_roles table address this issue? If so it's been backported to 5 and is available in 5.x-1.8.

ckng’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.