Commit 6bc69695 authored by Xavier Perseguers's avatar Xavier Perseguers Committed by Daniel Goerz
Browse files

[BUGFIX] Return alternative group uids when aspect has no user

When a UserAspect is constructed without any associated
AbstractUserAuthentication user (first constructor argument is null)
as created during Application bootstrap within
\TYPO3\CMS\Frontend\Http\Application::initializeContext(), the
alternative list of group uids needs to be made accessible. This
implies that method getGroupIds() should only check for a
BackendUserAuthentication for a special handling and not do the
erroneous check that it could alternatively be a
FrontendUserAuthentication.

Resolves: #92489
Releases: master, 10.4
Change-Id: I0342c86939fdcf03239c20fe95ae020d3d7bfc6a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66053


Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
parent a166d389
......@@ -44,7 +44,7 @@ class UserAspect implements AspectInterface
/**
* Alternative list of groups, usually useful for frontend logins with "magic" groups like "-1" and "-2"
*
* @var int[]
* @var int[]|null
*/
protected $groups;
......@@ -135,15 +135,16 @@ class UserAspect implements AspectInterface
*/
public function getGroupIds(): array
{
$groups = [];
// Alternative groups are set
if (is_array($this->groups)) {
return $this->groups;
}
if ($this->user instanceof BackendUserAuthentication) {
$groups = GeneralUtility::intExplode(',', $this->user->groupList, true);
return GeneralUtility::intExplode(',', $this->user->groupList, true);
}
$groups = [];
if ($this->user instanceof FrontendUserAuthentication) {
// Alternative groups are set
if (is_array($this->groups)) {
$groups = $this->groups;
} elseif ($this->isLoggedIn()) {
if ($this->isLoggedIn()) {
// If a user is logged in, always add "-2"
$groups = [0, -2];
if (!empty($this->user->groupData['uid'])) {
......
......@@ -38,6 +38,17 @@ class UserAspectTest extends UnitTestCase
self::assertEquals([], $subject->get('groupNames'));
}
/**
* @test
*/
public function alternativeGroupsAreAlwaysReturned()
{
$subject = new UserAspect(null, []);
self::assertEquals([], $subject->get('groupIds'));
$subject = new UserAspect(null, [567]);
self::assertEquals([567], $subject->get('groupIds'));
}
/**
* @test
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment