Skip to content

Commit 57f7b17

Browse files
committed
Add custom group backend
Signed-off-by: Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
1 parent 5f45e57 commit 57f7b17

File tree

11 files changed

+1134
-30
lines changed

11 files changed

+1134
-30
lines changed

lib/AppInfo/Application.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,17 @@
2525

2626
namespace OCA\VO_Federation\AppInfo;
2727

28+
use OC\EventDispatcher\EventDispatcher;
29+
use OCA\VO_Federation\Backend\GroupBackend;
30+
use OCA\VO_Federation\Service\GroupsService;
31+
use OCA\VO_Federation\Service\ProviderService;
2832
use OCP\AppFramework\App;
2933
use OCP\AppFramework\Bootstrap\IBootContext;
3034
use OCP\AppFramework\Bootstrap\IBootstrap;
3135
use OCP\AppFramework\Bootstrap\IRegistrationContext;
36+
use OCP\AppFramework\Db\DoesNotExistException;
37+
use OCP\IGroupManager;
38+
use OCP\User\Events\UserLoggedInEvent;
3239

3340
/**
3441
* Class Application
@@ -51,5 +58,38 @@ public function register(IRegistrationContext $context): void {
5158
}
5259

5360
public function boot(IBootContext $context): void {
61+
$context->injectFn(function (
62+
IGroupManager $groupManager,
63+
GroupBackend $groupBackend,
64+
) {
65+
$groupManager->addBackend($groupBackend);
66+
});
67+
68+
$context->injectFn(function (EventDispatcher $dispatcher,
69+
ProviderService $providerService,
70+
GroupsService $groupsService) {
71+
/*
72+
* @todo move the OCP events and then move the registration to `register`
73+
*/
74+
$dispatcher->addListener(
75+
UserLoggedInEvent::class,
76+
function (\OCP\User\Events\UserLoggedInEvent $event) use ($providerService, $groupsService) {
77+
$providers = $providerService->getProvidersWithSettings();
78+
foreach ($providers as $provider) {
79+
$providerId = $provider['id'];
80+
$userId = $event->getUser()->getUID();
81+
try {
82+
$session = $providerService->getProviderSession($userId, $providerId);
83+
if ($session !== null) {
84+
$groupsService->syncUser($userId, $providerId);
85+
}
86+
} catch (DoesNotExistException $e) {
87+
} catch (\Exception $other) {
88+
// TODO: Handle server availability
89+
}
90+
}
91+
}
92+
);
93+
});
5494
}
5595
}

0 commit comments

Comments
 (0)