Issue Bug Closed

#104423Refetch groups recursively following AfterGroupsResolvedEvent dispatching

Soren Malling 07/18/24, 14:00 updated 10/23/26, 16:03

Description

In the “GroupResolver” method “resolveGroupsForUser”, we only fetch groups recursively before the event “AfterGroupdResolvedEvent”.

It has the consequence of any groups added afterwards, will not have any subgroups fetched.

$resolvedGroups = $this->fetchGroupsRecursive($originalGroupIds);
$event = $this->eventDispatcher->dispatch(new AfterGroupsResolvedEvent($sourceTable, $resolvedGroups, $originalGroupIds, $userRecord));

We could redo the fetching afterwards, to ensure all groups are loaded recursively

$resolvedGroups = $this->fetchGroupsRecursive($originalGroupIds);
$event = $this->eventDispatcher->dispatch(new AfterGroupsResolvedEvent($sourceTable, $resolvedGroups, $originalGroupIds, $userRecord));
$resolvedGroupsAfterEvent = $this->fetchGroupsRecursive(array_map(fn(array $group) => $group['uid'], $event->getGroups()));

Reviews 1

History 56

  1. Garvin Hicking commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2024-07-18T21:54:54+00:00" > 07/18/24, 21:54 </span>

    I’m wondering if maybe the better place to do this recursively would be to do it inside your event? You can DI inject the GroupResolver to call the method fetchGroupsRecursive on your custom event result?

    My reasoning is, that the event might be specifically be used to not include recursive settings. If we would generally add this after the event, no longer could integrators use the event to restrict groups to main groups for example – so we’d actually lose flexibility with this.

    What do you think?

  2. Soren Malling commented <span data-processor="relativetime" data-value="2024-07-21T20:05:19+00:00" > 07/21/24, 20:05 </span>

    That is a plausible usecase you describe. In terms of API, the method fetchGroupsRecursive is currently protected, so it can’t be called from a DI class.

    And, it’s important to stress that one should not call resolveGroupsForUser as it would turn into a endless loop :-)

  3. Garvin Hicking commented <span data-processor="relativetime" data-value="2024-07-22T04:57:39+00:00" > 07/22/24, 04:57 </span>

    Ah, of course, I didn’t check thoroughly enough.

    Then probably the event would need a new “setRecursive” / “isRecursive” property, so that it can be toggled whether the recursive operation should be fired or not after the event.

    Would you be interested creating a patch for this?

  4. Soren Malling commented <span data-processor="relativetime" data-value="2024-07-24T08:12:43+00:00" > 07/24/24, 08:12 </span>

    Garvin Hicking wrote in #note-3:
    > Would you be interested creating a patch for this?

    I will come up with something 👌

  5. Gerrit Code Review pushed patch set 1 for main to change 96347 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2026-10-03T07:16:36+00:00" > 10/03/26, 07:16 </span>

  6. Georg Ringer commented and changed status Under Review Closed <span data-processor="relativetime" data-value="2026-10-23T16:03:43+00:00" > 10/23/26, 16:03 </span>

    Closing this one. The proposed solution was reviewed in Gerrit (https://review.typo3.org/c/Packages/TYPO3.CMS/+/96347) and Benni Mack objected to adding a public method to the Core that has no user in the Core itself.

    The alternative of fetching the groups recursively again after the event would take away the possibility to restrict the groups to a defined set in a listener, as Garvin pointed out in note 2. Therefore the event stays as it is: groups added by a listener are used as they are, and a listener that adds groups is responsible for adding their subgroups as well.

    As a workaround, the listener can resolve the subgroups itself: read the comma separated subgroup field of each added group, load those groups from the database and repeat this for them, keeping a list of the already processed uids to avoid endless loops. The complete list is then passed back with $event->setGroups().

    The Gerrit change will be abandoned.