Skip to content

Commit 21677d9

Browse files
committed
fix: update external storage mounts on login
Signed-off-by: Robin Appelman <[email protected]>
1 parent 038bded commit 21677d9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

apps/files_external/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
use OCP\Group\Events\GroupDeletedEvent;
5959
use OCP\Group\Events\UserAddedEvent;
6060
use OCP\Group\Events\UserRemovedEvent;
61+
use OCP\User\Events\PostLoginEvent;
6162
use OCP\User\Events\UserCreatedEvent;
6263
use OCP\User\Events\UserDeletedEvent;
6364

@@ -87,6 +88,7 @@ public function register(IRegistrationContext $context): void {
8788
$context->registerEventListener(UserCreatedEvent::class, MountCacheService::class);
8889
$context->registerEventListener(UserAddedEvent::class, MountCacheService::class);
8990
$context->registerEventListener(UserRemovedEvent::class, MountCacheService::class);
91+
$context->registerEventListener(PostLoginEvent::class, MountCacheService::class);
9092

9193
$context->registerConfigLexicon(ConfigLexicon::class);
9294
}

apps/files_external/lib/Service/MountCacheService.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
use OCP\IGroupManager;
2929
use OCP\IUser;
3030
use OCP\IUserManager;
31+
use OCP\User\Events\PostLoginEvent;
3132
use OCP\User\Events\UserCreatedEvent;
3233

3334
/**
3435
* Listens to config events and update the mounts for the applicable users
3536
*
36-
* @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|Event>
37+
* @template-implements IEventListener<StorageCreatedEvent|StorageDeletedEvent|StorageUpdatedEvent|BeforeGroupDeletedEvent|UserCreatedEvent|UserAddedEvent|UserRemovedEvent|PostLoginEvent|Event>
3738
*/
3839
class MountCacheService implements IEventListener {
3940
private CappedMemoryCache $storageRootCache;
@@ -70,6 +71,9 @@ public function handle(Event $event): void {
7071
if ($event instanceof UserCreatedEvent) {
7172
$this->addUser($event->getUser());
7273
}
74+
if ($event instanceof PostLoginEvent) {
75+
$this->onLogin($event->getUser());
76+
}
7377
}
7478

7579

@@ -221,4 +225,14 @@ private function addUser(IUser $user): void {
221225
$this->registerForUser($user, $storage);
222226
}
223227
}
228+
229+
/**
230+
* Since storage config can rely on login credentials, we might need to update the config
231+
*/
232+
private function onLogin(IUser $user): void {
233+
$storages = $this->storagesService->getAllGlobalStorages();
234+
foreach ($storages as $storage) {
235+
$this->registerForUser($user, $storage);
236+
}
237+
}
224238
}

0 commit comments

Comments
 (0)