Problem/Motivation

The mapped roles are stored in a field on the user. Only one profile can revoke roles correctly.

Steps to reproduce

Proposed resolution

Use the user.data service to store the mappings. This will allow every profile to revoke roles previously granted correctly.

$user = \Drupal::currentUser();

// Define an array of role => profile.
$roles= [
  'administrator' => 'profile_a',
  'teacher' => 'profile_b',
  'staff' => 'profile_b',
];

// Store the array as user data.
\Drupal::service('user.data')->set('authorization_drupal_roles', $user->id(), 'roles', $roles);

Remaining tasks

Update existing code to use user.data.

Write hook_update_N function to store the users existing roles.

Remove 'authorization_drupal_roles_roles' field.

User interface changes

API changes

Data model changes

The 'authorization_drupal_roles_roles' field will be removed from the user.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bluegeek9 created an issue. See original summary.

bluegeek9’s picture

Assigned: Unassigned » bluegeek9

  • bluegeek9 committed 76a8ab62 on 8.x-1.x
    Issue #3399979: Drupal Roles Consumer - store mappings in user.data
    
bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
Status: Active » Fixed
bluegeek9’s picture

Status: Fixed » Active

I want integration tests for the update function. This is the largest change to authorization since the 'authorization_drupal_roles_roles' field was introduced.

bluegeek9’s picture

Status: Active » Fixed

Drupal 11 is here.

Status: Fixed » Closed (fixed)

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