Skip to content

Fix possible deprecation warning in UsersManager.getUsersPlusRole API #21810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Jan 15, 2024

Description:

When UsersManager.getUsersPlusRole is being called as anonymous user, the API currently throws a deprecation warning on PHP 8+.

As the anonymous user actually doesn't need to see any users or roles this PR changes the behavior, so the method always returns an empty data set in that case.

fixes #21253

Review

@sgiehl sgiehl added the Needs Review PRs that need a code review label Jan 15, 2024
@sgiehl sgiehl added this to the 5.0.2 milestone Jan 15, 2024
@sgiehl sgiehl requested a review from a team January 15, 2024 16:18
@sgiehl sgiehl added the Bug For errors / faults / flaws / inconsistencies etc. label Jan 15, 2024
@michalkleiner
Copy link
Contributor

I'm fine with the additional check for the anonymous user, but I think we still should safeguard for any users being returned as the original issue suggested (false not being an array) and change

$user = $this->model->getUser($this->access->getLogin());
$user['role'] = $this->access->getRoleForSite($idSite);
$user['capabilities'] = $this->access->getCapabilitiesForSite($idSite);
$users = [$user];
$totalResults = 1;

to

$users = [];
$user = $this->model->getUser($this->access->getLogin());
if ($user) {
    $user['role'] = $this->access->getRoleForSite($idSite);
    $user['capabilities'] = $this->access->getCapabilitiesForSite($idSite);
    $users = [$user];
}
$totalResults = count($users);

Then the rest of the code would work as is.

@sgiehl
Copy link
Member Author

sgiehl commented Jan 16, 2024

I'm fine with the additional check for the anonymous user, but I think we still should safeguard for any users being returned as the original issue suggested (false not being an array)

Changing that doesn't hurt. But from a logical point of view, that would mean that you would need to be authenticated with a user that doesn't exist. (Which is only the case for the anonymous user)

Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good, test failures unrelated.

@sgiehl sgiehl merged commit 148799b into 5.x-dev Jan 16, 2024
@sgiehl sgiehl deleted the dev-17182 branch January 16, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review
Development

Successfully merging this pull request may close these issues.

PHP 8.1 incompatibility - UsersManager API - getUsersPlusRole
2 participants