GroupRoleStorage returns a user's synchronized roles for all group types, should check for group type being passed in

Created on 24 February 2023, over 1 year ago
Updated 10 March 2023, over 1 year ago

Problem/Motivation

Currently, GroupRoleStorage returns a user's synchronized roles for all group types, not just for the group type being passed in. Take the following snippet:

$memberships = \Drupal::service('group.membership_loader')->loadByUser($user);
if (!empty($memberships)) {
  foreach ($memberships as $membership) {
    $group = $membership->getGroup();
    if ($roles = $membership->getRoles()) {
    ....

The variable $roles is populated with ALL of $user's synchronized roles now, not just the ones for the passed in group. The issue appears to be that this part of GroupRoleStorage::loadByUserAndGroup() should also include a check for the group type.

      if ($include_synchronized) {
        $roles = $account->getRoles();
        $query = $this->getQuery()
          ->condition('scope', $membership ? PermissionScopeInterface::INSIDER_ID : PermissionScopeInterface::OUTSIDER_ID)
          ->condition('global_role', $roles, 'IN');
        $ids = array_merge($ids, $query->accessCheck()->execute());
      }

Proposed resolution

Add an additional check for group type to the query.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States scotwith1t Birmingham, AL

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

Comments & Activities

Production build 0.69.0 2024