Users with roles "Students" are displaying as "Managers" in "Who's New" and "Who's Online"

Created on 30 August 2023, about 1 year ago
Updated 23 November 2023, 12 months ago

Problem/Motivation

We have Opigno 3.1.0 installed. We notice Users who have already been assigned the role "Student" displays with a role of "Manager" when in the "Who's Online" or "Who's New" view blocks. Tracing this through the user--compact.html.twig and function aristotle_preprocess_user(&$variables), it seems this is due to the the function getUsrRole in the class Drupal\opigno_statistics\Services\UserStatisticsManager

 public function getUserRole(?AccountInterface $user = NULL): TranslatableMarkup {
    // Add user role.
    if (!$user) {
      $user = $this->account;
    }

    $roles = $user->getRoles(TRUE);
    if (!$roles) {
      $role = $this->t('Student');
    }
    elseif (in_array('administrator', $roles)) {
      $role = $this->t('Administrator');
    }
    else {
      $role = $this->t('Manager');
    }

    return $role;

It seems, since a role is set, the first if statement is skipped nd since administrator is not in the roles, Manager is returned....

Steps to reproduce

Create a new user from the admin screen and assign student role to the new user. You will then see the user has "Manager" role.

Proposed resolution

Why do we need this check? Can we just use the role that is returned?

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.1

Component

Code

Created by

🇦🇺Australia ajlow

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

Comments & Activities

Production build 0.71.5 2024