From cb8fb349d24cd2fa404ce1ab3fe0c490a171c46e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Apr 2026 19:08:02 +0200 Subject: [PATCH] fix: don't trigger on-setup share update from inside the share listener Signed-off-by: Robin Appelman --- apps/files_sharing/lib/Listener/SharesUpdatedListener.php | 6 ++++++ apps/files_sharing/lib/Listener/UserHomeSetupListener.php | 7 +++++++ apps/files_sharing/tests/SharesUpdatedListenerTest.php | 3 +++ 3 files changed, 16 insertions(+) diff --git a/apps/files_sharing/lib/Listener/SharesUpdatedListener.php b/apps/files_sharing/lib/Listener/SharesUpdatedListener.php index 06f09d8a026..d3ebf7afa82 100644 --- a/apps/files_sharing/lib/Listener/SharesUpdatedListener.php +++ b/apps/files_sharing/lib/Listener/SharesUpdatedListener.php @@ -54,11 +54,15 @@ class SharesUpdatedListener implements IEventListener { private readonly ClockInterface $clock, private readonly LoggerInterface $logger, IAppConfig $appConfig, + private readonly UserHomeSetupListener $homeSetupListener, ) { $this->cutOffMarkTime = $appConfig->getValueFloat(Application::APP_ID, ConfigLexicon::UPDATE_CUTOFF_TIME, 3.0); } public function handle(Event $event): void { + // don't trigger the on-setup checks if this handler triggers an fs setup + $this->homeSetupListener->setDisabled(true); + if ($event instanceof UserShareAccessUpdatedEvent) { foreach ($event->getUsers() as $user) { $this->updateOrMarkUser($user); @@ -107,6 +111,8 @@ class SharesUpdatedListener implements IEventListener { }); } } + + $this->homeSetupListener->setDisabled(false); } private function markOrRun(IUser $user, callable $callback): void { diff --git a/apps/files_sharing/lib/Listener/UserHomeSetupListener.php b/apps/files_sharing/lib/Listener/UserHomeSetupListener.php index 9e1d0ea765b..b057a3d082d 100644 --- a/apps/files_sharing/lib/Listener/UserHomeSetupListener.php +++ b/apps/files_sharing/lib/Listener/UserHomeSetupListener.php @@ -23,16 +23,23 @@ use OCP\Files\Events\UserHomeSetupEvent; * @template-implements IEventListener */ class UserHomeSetupListener implements IEventListener { + private bool $disabled = false; public function __construct( private readonly ShareRecipientUpdater $updater, private readonly IUserConfig $userConfig, ) { } + public function setDisabled(bool $disabled): void { + $this->disabled = $disabled; + } public function handle(Event $event): void { if (!$event instanceof UserHomeSetupEvent) { return; } + if ($this->disabled) { + return; + } $user = $event->getUser(); if ($this->userConfig->getValueBool($user->getUID(), Application::APP_ID, ConfigLexicon::USER_NEEDS_SHARE_REFRESH, true)) { diff --git a/apps/files_sharing/tests/SharesUpdatedListenerTest.php b/apps/files_sharing/tests/SharesUpdatedListenerTest.php index 5349ec0fd3a..3598f6cfb5b 100644 --- a/apps/files_sharing/tests/SharesUpdatedListenerTest.php +++ b/apps/files_sharing/tests/SharesUpdatedListenerTest.php @@ -10,6 +10,7 @@ namespace OCA\Files_Sharing\Tests; use OCA\Files_Sharing\Config\ConfigLexicon; use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent; use OCA\Files_Sharing\Listener\SharesUpdatedListener; +use OCA\Files_Sharing\Listener\UserHomeSetupListener; use OCA\Files_Sharing\ShareRecipientUpdater; use OCP\Config\IUserConfig; use OCP\IAppConfig; @@ -57,6 +58,7 @@ class SharesUpdatedListenerTest extends \Test\TestCase { return ($this->clockFn)(); }); $this->logger = $this->createMock(LoggerInterface::class); + $homeSetupListener = new UserHomeSetupListener($this->shareRecipientUpdater, $this->userConfig); $this->sharesUpdatedListener = new SharesUpdatedListener( $this->manager, @@ -65,6 +67,7 @@ class SharesUpdatedListenerTest extends \Test\TestCase { $this->clock, $this->logger, $this->appConfig, + $homeSetupListener, ); }