@@ -18,54 +18,54 @@ |
||
18 | 18 | use OCP\Settings\ISettings; |
19 | 19 | |
20 | 20 | class ExampleContentSettings implements ISettings { |
21 | - public function __construct( |
|
22 | - private readonly IAppConfig $appConfig, |
|
23 | - private readonly IInitialState $initialState, |
|
24 | - private readonly IAppManager $appManager, |
|
25 | - private readonly ExampleEventService $exampleEventService, |
|
26 | - private readonly ExampleContactService $exampleContactService, |
|
27 | - ) { |
|
28 | - } |
|
21 | + public function __construct( |
|
22 | + private readonly IAppConfig $appConfig, |
|
23 | + private readonly IInitialState $initialState, |
|
24 | + private readonly IAppManager $appManager, |
|
25 | + private readonly ExampleEventService $exampleEventService, |
|
26 | + private readonly ExampleContactService $exampleContactService, |
|
27 | + ) { |
|
28 | + } |
|
29 | 29 | |
30 | - public function getForm(): TemplateResponse { |
|
31 | - $calendarEnabled = $this->appManager->isEnabledForUser('calendar'); |
|
32 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts'); |
|
33 | - $this->initialState->provideInitialState('calendarEnabled', $calendarEnabled); |
|
34 | - $this->initialState->provideInitialState('contactsEnabled', $contactsEnabled); |
|
30 | + public function getForm(): TemplateResponse { |
|
31 | + $calendarEnabled = $this->appManager->isEnabledForUser('calendar'); |
|
32 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts'); |
|
33 | + $this->initialState->provideInitialState('calendarEnabled', $calendarEnabled); |
|
34 | + $this->initialState->provideInitialState('contactsEnabled', $contactsEnabled); |
|
35 | 35 | |
36 | - if ($calendarEnabled) { |
|
37 | - $enableDefaultEvent = $this->exampleEventService->shouldCreateExampleEvent(); |
|
38 | - $this->initialState->provideInitialState('create_example_event', $enableDefaultEvent); |
|
39 | - $this->initialState->provideInitialState( |
|
40 | - 'has_custom_example_event', |
|
41 | - $this->exampleEventService->hasCustomExampleEvent(), |
|
42 | - ); |
|
43 | - } |
|
36 | + if ($calendarEnabled) { |
|
37 | + $enableDefaultEvent = $this->exampleEventService->shouldCreateExampleEvent(); |
|
38 | + $this->initialState->provideInitialState('create_example_event', $enableDefaultEvent); |
|
39 | + $this->initialState->provideInitialState( |
|
40 | + 'has_custom_example_event', |
|
41 | + $this->exampleEventService->hasCustomExampleEvent(), |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | - if ($contactsEnabled) { |
|
46 | - $this->initialState->provideInitialState( |
|
47 | - 'enableDefaultContact', |
|
48 | - $this->exampleContactService->isDefaultContactEnabled(), |
|
49 | - ); |
|
50 | - $this->initialState->provideInitialState( |
|
51 | - 'hasCustomDefaultContact', |
|
52 | - $this->appConfig->getAppValueBool('hasCustomDefaultContact'), |
|
53 | - ); |
|
54 | - } |
|
45 | + if ($contactsEnabled) { |
|
46 | + $this->initialState->provideInitialState( |
|
47 | + 'enableDefaultContact', |
|
48 | + $this->exampleContactService->isDefaultContactEnabled(), |
|
49 | + ); |
|
50 | + $this->initialState->provideInitialState( |
|
51 | + 'hasCustomDefaultContact', |
|
52 | + $this->appConfig->getAppValueBool('hasCustomDefaultContact'), |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - return new TemplateResponse(Application::APP_ID, 'settings-example-content'); |
|
57 | - } |
|
56 | + return new TemplateResponse(Application::APP_ID, 'settings-example-content'); |
|
57 | + } |
|
58 | 58 | |
59 | - public function getSection(): ?string { |
|
60 | - if (!$this->appManager->isEnabledForUser('contacts') |
|
61 | - && !$this->appManager->isEnabledForUser('calendar')) { |
|
62 | - return null; |
|
63 | - } |
|
59 | + public function getSection(): ?string { |
|
60 | + if (!$this->appManager->isEnabledForUser('contacts') |
|
61 | + && !$this->appManager->isEnabledForUser('calendar')) { |
|
62 | + return null; |
|
63 | + } |
|
64 | 64 | |
65 | - return 'groupware'; |
|
66 | - } |
|
65 | + return 'groupware'; |
|
66 | + } |
|
67 | 67 | |
68 | - public function getPriority(): int { |
|
69 | - return 10; |
|
70 | - } |
|
68 | + public function getPriority(): int { |
|
69 | + return 10; |
|
70 | + } |
|
71 | 71 | } |
@@ -19,114 +19,114 @@ |
||
19 | 19 | use Symfony\Component\Uid\Uuid; |
20 | 20 | |
21 | 21 | class ExampleContactService { |
22 | - private readonly IAppData $appData; |
|
23 | - |
|
24 | - public function __construct( |
|
25 | - IAppDataFactory $appDataFactory, |
|
26 | - private readonly IAppConfig $appConfig, |
|
27 | - private readonly LoggerInterface $logger, |
|
28 | - private readonly CardDavBackend $cardDav, |
|
29 | - ) { |
|
30 | - $this->appData = $appDataFactory->get(Application::APP_ID); |
|
31 | - } |
|
32 | - |
|
33 | - public function isDefaultContactEnabled(): bool { |
|
34 | - return $this->appConfig->getAppValueBool('enableDefaultContact', true); |
|
35 | - } |
|
36 | - |
|
37 | - public function setDefaultContactEnabled(bool $value): void { |
|
38 | - $this->appConfig->setAppValueBool('enableDefaultContact', $value); |
|
39 | - } |
|
40 | - |
|
41 | - public function getCard(): ?string { |
|
42 | - try { |
|
43 | - $folder = $this->appData->getFolder('defaultContact'); |
|
44 | - } catch (NotFoundException $e) { |
|
45 | - return null; |
|
46 | - } |
|
47 | - |
|
48 | - if (!$folder->fileExists('defaultContact.vcf')) { |
|
49 | - return null; |
|
50 | - } |
|
51 | - |
|
52 | - return $folder->getFile('defaultContact.vcf')->getContent(); |
|
53 | - } |
|
54 | - |
|
55 | - public function setCard(?string $cardData = null) { |
|
56 | - try { |
|
57 | - $folder = $this->appData->getFolder('defaultContact'); |
|
58 | - } catch (NotFoundException $e) { |
|
59 | - $folder = $this->appData->newFolder('defaultContact'); |
|
60 | - } |
|
61 | - |
|
62 | - $isCustom = true; |
|
63 | - if (is_null($cardData)) { |
|
64 | - $cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); |
|
65 | - $isCustom = false; |
|
66 | - } |
|
67 | - |
|
68 | - if (!$cardData) { |
|
69 | - throw new \Exception('Could not read exampleContact.vcf'); |
|
70 | - } |
|
71 | - |
|
72 | - $file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); |
|
73 | - $file->putContent($cardData); |
|
74 | - |
|
75 | - $this->appConfig->setAppValueBool('hasCustomDefaultContact', $isCustom); |
|
76 | - } |
|
77 | - |
|
78 | - public function defaultContactExists(): bool { |
|
79 | - try { |
|
80 | - $folder = $this->appData->getFolder('defaultContact'); |
|
81 | - } catch (NotFoundException $e) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - return $folder->fileExists('defaultContact.vcf'); |
|
85 | - } |
|
86 | - |
|
87 | - public function createDefaultContact(int $addressBookId): void { |
|
88 | - if (!$this->isDefaultContactEnabled()) { |
|
89 | - return; |
|
90 | - } |
|
91 | - |
|
92 | - try { |
|
93 | - $folder = $this->appData->getFolder('defaultContact'); |
|
94 | - $defaultContactFile = $folder->getFile('defaultContact.vcf'); |
|
95 | - $data = $defaultContactFile->getContent(); |
|
96 | - } catch (\Exception $e) { |
|
97 | - $this->logger->error('Couldn\'t get default contact file', ['exception' => $e]); |
|
98 | - return; |
|
99 | - } |
|
100 | - |
|
101 | - // Make sure the UID is unique |
|
102 | - $newUid = Uuid::v4()->toRfc4122(); |
|
103 | - $newRev = date('Ymd\THis\Z'); |
|
104 | - $vcard = \Sabre\VObject\Reader::read($data, \Sabre\VObject\Reader::OPTION_FORGIVING); |
|
105 | - if ($vcard->UID) { |
|
106 | - $vcard->UID->setValue($newUid); |
|
107 | - } else { |
|
108 | - $vcard->add('UID', $newUid); |
|
109 | - } |
|
110 | - if ($vcard->REV) { |
|
111 | - $vcard->REV->setValue($newRev); |
|
112 | - } else { |
|
113 | - $vcard->add('REV', $newRev); |
|
114 | - } |
|
115 | - |
|
116 | - // Level 3 means that the document is invalid |
|
117 | - // https://sabre.io/vobject/vcard/#validating-vcard |
|
118 | - $level3Warnings = array_filter($vcard->validate(), static function ($warning) { |
|
119 | - return $warning['level'] === 3; |
|
120 | - }); |
|
121 | - |
|
122 | - if (!empty($level3Warnings)) { |
|
123 | - $this->logger->error('Default contact is invalid', ['warnings' => $level3Warnings]); |
|
124 | - return; |
|
125 | - } |
|
126 | - try { |
|
127 | - $this->cardDav->createCard($addressBookId, 'default', $vcard->serialize(), false); |
|
128 | - } catch (\Exception $e) { |
|
129 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
130 | - } |
|
131 | - } |
|
22 | + private readonly IAppData $appData; |
|
23 | + |
|
24 | + public function __construct( |
|
25 | + IAppDataFactory $appDataFactory, |
|
26 | + private readonly IAppConfig $appConfig, |
|
27 | + private readonly LoggerInterface $logger, |
|
28 | + private readonly CardDavBackend $cardDav, |
|
29 | + ) { |
|
30 | + $this->appData = $appDataFactory->get(Application::APP_ID); |
|
31 | + } |
|
32 | + |
|
33 | + public function isDefaultContactEnabled(): bool { |
|
34 | + return $this->appConfig->getAppValueBool('enableDefaultContact', true); |
|
35 | + } |
|
36 | + |
|
37 | + public function setDefaultContactEnabled(bool $value): void { |
|
38 | + $this->appConfig->setAppValueBool('enableDefaultContact', $value); |
|
39 | + } |
|
40 | + |
|
41 | + public function getCard(): ?string { |
|
42 | + try { |
|
43 | + $folder = $this->appData->getFolder('defaultContact'); |
|
44 | + } catch (NotFoundException $e) { |
|
45 | + return null; |
|
46 | + } |
|
47 | + |
|
48 | + if (!$folder->fileExists('defaultContact.vcf')) { |
|
49 | + return null; |
|
50 | + } |
|
51 | + |
|
52 | + return $folder->getFile('defaultContact.vcf')->getContent(); |
|
53 | + } |
|
54 | + |
|
55 | + public function setCard(?string $cardData = null) { |
|
56 | + try { |
|
57 | + $folder = $this->appData->getFolder('defaultContact'); |
|
58 | + } catch (NotFoundException $e) { |
|
59 | + $folder = $this->appData->newFolder('defaultContact'); |
|
60 | + } |
|
61 | + |
|
62 | + $isCustom = true; |
|
63 | + if (is_null($cardData)) { |
|
64 | + $cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); |
|
65 | + $isCustom = false; |
|
66 | + } |
|
67 | + |
|
68 | + if (!$cardData) { |
|
69 | + throw new \Exception('Could not read exampleContact.vcf'); |
|
70 | + } |
|
71 | + |
|
72 | + $file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); |
|
73 | + $file->putContent($cardData); |
|
74 | + |
|
75 | + $this->appConfig->setAppValueBool('hasCustomDefaultContact', $isCustom); |
|
76 | + } |
|
77 | + |
|
78 | + public function defaultContactExists(): bool { |
|
79 | + try { |
|
80 | + $folder = $this->appData->getFolder('defaultContact'); |
|
81 | + } catch (NotFoundException $e) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + return $folder->fileExists('defaultContact.vcf'); |
|
85 | + } |
|
86 | + |
|
87 | + public function createDefaultContact(int $addressBookId): void { |
|
88 | + if (!$this->isDefaultContactEnabled()) { |
|
89 | + return; |
|
90 | + } |
|
91 | + |
|
92 | + try { |
|
93 | + $folder = $this->appData->getFolder('defaultContact'); |
|
94 | + $defaultContactFile = $folder->getFile('defaultContact.vcf'); |
|
95 | + $data = $defaultContactFile->getContent(); |
|
96 | + } catch (\Exception $e) { |
|
97 | + $this->logger->error('Couldn\'t get default contact file', ['exception' => $e]); |
|
98 | + return; |
|
99 | + } |
|
100 | + |
|
101 | + // Make sure the UID is unique |
|
102 | + $newUid = Uuid::v4()->toRfc4122(); |
|
103 | + $newRev = date('Ymd\THis\Z'); |
|
104 | + $vcard = \Sabre\VObject\Reader::read($data, \Sabre\VObject\Reader::OPTION_FORGIVING); |
|
105 | + if ($vcard->UID) { |
|
106 | + $vcard->UID->setValue($newUid); |
|
107 | + } else { |
|
108 | + $vcard->add('UID', $newUid); |
|
109 | + } |
|
110 | + if ($vcard->REV) { |
|
111 | + $vcard->REV->setValue($newRev); |
|
112 | + } else { |
|
113 | + $vcard->add('REV', $newRev); |
|
114 | + } |
|
115 | + |
|
116 | + // Level 3 means that the document is invalid |
|
117 | + // https://sabre.io/vobject/vcard/#validating-vcard |
|
118 | + $level3Warnings = array_filter($vcard->validate(), static function ($warning) { |
|
119 | + return $warning['level'] === 3; |
|
120 | + }); |
|
121 | + |
|
122 | + if (!empty($level3Warnings)) { |
|
123 | + $this->logger->error('Default contact is invalid', ['warnings' => $level3Warnings]); |
|
124 | + return; |
|
125 | + } |
|
126 | + try { |
|
127 | + $this->cardDav->createCard($addressBookId, 'default', $vcard->serialize(), false); |
|
128 | + } catch (\Exception $e) { |
|
129 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |
@@ -22,77 +22,77 @@ |
||
22 | 22 | use Psr\Log\LoggerInterface; |
23 | 23 | |
24 | 24 | class ExampleContentController extends ApiController { |
25 | - public function __construct( |
|
26 | - IRequest $request, |
|
27 | - private readonly LoggerInterface $logger, |
|
28 | - private readonly ExampleEventService $exampleEventService, |
|
29 | - private readonly ExampleContactService $exampleContactService, |
|
30 | - ) { |
|
31 | - parent::__construct(Application::APP_ID, $request); |
|
32 | - } |
|
25 | + public function __construct( |
|
26 | + IRequest $request, |
|
27 | + private readonly LoggerInterface $logger, |
|
28 | + private readonly ExampleEventService $exampleEventService, |
|
29 | + private readonly ExampleContactService $exampleContactService, |
|
30 | + ) { |
|
31 | + parent::__construct(Application::APP_ID, $request); |
|
32 | + } |
|
33 | 33 | |
34 | - #[FrontpageRoute(verb: 'PUT', url: '/api/defaultcontact/config')] |
|
35 | - public function setEnableDefaultContact(bool $allow): JSONResponse { |
|
36 | - if ($allow && !$this->exampleContactService->defaultContactExists()) { |
|
37 | - try { |
|
38 | - $this->exampleContactService->setCard(); |
|
39 | - } catch (\Exception $e) { |
|
40 | - $this->logger->error('Could not create default contact', ['exception' => $e]); |
|
41 | - return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
42 | - } |
|
43 | - } |
|
44 | - $this->exampleContactService->setDefaultContactEnabled($allow); |
|
45 | - return new JSONResponse([], Http::STATUS_OK); |
|
46 | - } |
|
34 | + #[FrontpageRoute(verb: 'PUT', url: '/api/defaultcontact/config')] |
|
35 | + public function setEnableDefaultContact(bool $allow): JSONResponse { |
|
36 | + if ($allow && !$this->exampleContactService->defaultContactExists()) { |
|
37 | + try { |
|
38 | + $this->exampleContactService->setCard(); |
|
39 | + } catch (\Exception $e) { |
|
40 | + $this->logger->error('Could not create default contact', ['exception' => $e]); |
|
41 | + return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); |
|
42 | + } |
|
43 | + } |
|
44 | + $this->exampleContactService->setDefaultContactEnabled($allow); |
|
45 | + return new JSONResponse([], Http::STATUS_OK); |
|
46 | + } |
|
47 | 47 | |
48 | - #[NoCSRFRequired] |
|
49 | - #[FrontpageRoute(verb: 'GET', url: '/api/defaultcontact/contact')] |
|
50 | - public function getDefaultContact(): DataDownloadResponse { |
|
51 | - $cardData = $this->exampleContactService->getCard() |
|
52 | - ?? file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); |
|
53 | - return new DataDownloadResponse($cardData, 'example_contact.vcf', 'text/vcard'); |
|
54 | - } |
|
48 | + #[NoCSRFRequired] |
|
49 | + #[FrontpageRoute(verb: 'GET', url: '/api/defaultcontact/contact')] |
|
50 | + public function getDefaultContact(): DataDownloadResponse { |
|
51 | + $cardData = $this->exampleContactService->getCard() |
|
52 | + ?? file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); |
|
53 | + return new DataDownloadResponse($cardData, 'example_contact.vcf', 'text/vcard'); |
|
54 | + } |
|
55 | 55 | |
56 | - #[FrontpageRoute(verb: 'PUT', url: '/api/defaultcontact/contact')] |
|
57 | - public function setDefaultContact(?string $contactData = null) { |
|
58 | - if (!$this->exampleContactService->isDefaultContactEnabled()) { |
|
59 | - return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
60 | - } |
|
61 | - $this->exampleContactService->setCard($contactData); |
|
62 | - return new JSONResponse([], Http::STATUS_OK); |
|
63 | - } |
|
56 | + #[FrontpageRoute(verb: 'PUT', url: '/api/defaultcontact/contact')] |
|
57 | + public function setDefaultContact(?string $contactData = null) { |
|
58 | + if (!$this->exampleContactService->isDefaultContactEnabled()) { |
|
59 | + return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
60 | + } |
|
61 | + $this->exampleContactService->setCard($contactData); |
|
62 | + return new JSONResponse([], Http::STATUS_OK); |
|
63 | + } |
|
64 | 64 | |
65 | - #[FrontpageRoute(verb: 'POST', url: '/api/exampleEvent/enable')] |
|
66 | - public function setCreateExampleEvent(bool $enable): JSONResponse { |
|
67 | - $this->exampleEventService->setCreateExampleEvent($enable); |
|
68 | - return new JsonResponse([]); |
|
69 | - } |
|
65 | + #[FrontpageRoute(verb: 'POST', url: '/api/exampleEvent/enable')] |
|
66 | + public function setCreateExampleEvent(bool $enable): JSONResponse { |
|
67 | + $this->exampleEventService->setCreateExampleEvent($enable); |
|
68 | + return new JsonResponse([]); |
|
69 | + } |
|
70 | 70 | |
71 | - #[FrontpageRoute(verb: 'GET', url: '/api/exampleEvent/event')] |
|
72 | - #[NoCSRFRequired] |
|
73 | - public function downloadExampleEvent(): DataDownloadResponse { |
|
74 | - $exampleEvent = $this->exampleEventService->getExampleEvent(); |
|
75 | - return new DataDownloadResponse( |
|
76 | - $exampleEvent->getIcs(), |
|
77 | - 'example_event.ics', |
|
78 | - 'text/calendar', |
|
79 | - ); |
|
80 | - } |
|
71 | + #[FrontpageRoute(verb: 'GET', url: '/api/exampleEvent/event')] |
|
72 | + #[NoCSRFRequired] |
|
73 | + public function downloadExampleEvent(): DataDownloadResponse { |
|
74 | + $exampleEvent = $this->exampleEventService->getExampleEvent(); |
|
75 | + return new DataDownloadResponse( |
|
76 | + $exampleEvent->getIcs(), |
|
77 | + 'example_event.ics', |
|
78 | + 'text/calendar', |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | - #[FrontpageRoute(verb: 'POST', url: '/api/exampleEvent/event')] |
|
83 | - public function uploadExampleEvent(string $ics): JSONResponse { |
|
84 | - if (!$this->exampleEventService->shouldCreateExampleEvent()) { |
|
85 | - return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
86 | - } |
|
82 | + #[FrontpageRoute(verb: 'POST', url: '/api/exampleEvent/event')] |
|
83 | + public function uploadExampleEvent(string $ics): JSONResponse { |
|
84 | + if (!$this->exampleEventService->shouldCreateExampleEvent()) { |
|
85 | + return new JSONResponse([], Http::STATUS_FORBIDDEN); |
|
86 | + } |
|
87 | 87 | |
88 | - $this->exampleEventService->saveCustomExampleEvent($ics); |
|
89 | - return new JsonResponse([]); |
|
90 | - } |
|
88 | + $this->exampleEventService->saveCustomExampleEvent($ics); |
|
89 | + return new JsonResponse([]); |
|
90 | + } |
|
91 | 91 | |
92 | - #[FrontpageRoute(verb: 'DELETE', url: '/api/exampleEvent/event')] |
|
93 | - public function deleteExampleEvent(): JSONResponse { |
|
94 | - $this->exampleEventService->deleteCustomExampleEvent(); |
|
95 | - return new JsonResponse([]); |
|
96 | - } |
|
92 | + #[FrontpageRoute(verb: 'DELETE', url: '/api/exampleEvent/event')] |
|
93 | + public function deleteExampleEvent(): JSONResponse { |
|
94 | + $this->exampleEventService->deleteCustomExampleEvent(); |
|
95 | + return new JsonResponse([]); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -33,149 +33,149 @@ |
||
33 | 33 | /** @template-implements IEventListener<UserFirstTimeLoggedInEvent|UserIdAssignedEvent|BeforeUserIdUnassignedEvent|UserIdUnassignedEvent|BeforeUserDeletedEvent|UserDeletedEvent|UserCreatedEvent|UserChangedEvent|UserUpdatedEvent> */ |
34 | 34 | class UserEventsListener implements IEventListener { |
35 | 35 | |
36 | - /** @var IUser[] */ |
|
37 | - private array $usersToDelete = []; |
|
38 | - |
|
39 | - private array $calendarsToDelete = []; |
|
40 | - private array $subscriptionsToDelete = []; |
|
41 | - private array $addressBooksToDelete = []; |
|
42 | - |
|
43 | - public function __construct( |
|
44 | - private IUserManager $userManager, |
|
45 | - private SyncService $syncService, |
|
46 | - private CalDavBackend $calDav, |
|
47 | - private CardDavBackend $cardDav, |
|
48 | - private Defaults $themingDefaults, |
|
49 | - private ExampleContactService $exampleContactService, |
|
50 | - private ExampleEventService $exampleEventService, |
|
51 | - private LoggerInterface $logger, |
|
52 | - ) { |
|
53 | - } |
|
54 | - |
|
55 | - public function handle(Event $event): void { |
|
56 | - if ($event instanceof UserCreatedEvent) { |
|
57 | - $this->postCreateUser($event->getUser()); |
|
58 | - } elseif ($event instanceof UserIdAssignedEvent) { |
|
59 | - $user = $this->userManager->get($event->getUserId()); |
|
60 | - if ($user !== null) { |
|
61 | - $this->postCreateUser($user); |
|
62 | - } |
|
63 | - } elseif ($event instanceof BeforeUserDeletedEvent) { |
|
64 | - $this->preDeleteUser($event->getUser()); |
|
65 | - } elseif ($event instanceof BeforeUserIdUnassignedEvent) { |
|
66 | - $this->preUnassignedUserId($event->getUserId()); |
|
67 | - } elseif ($event instanceof UserDeletedEvent) { |
|
68 | - $this->postDeleteUser($event->getUid()); |
|
69 | - } elseif ($event instanceof UserIdUnassignedEvent) { |
|
70 | - $this->postDeleteUser($event->getUserId()); |
|
71 | - } elseif ($event instanceof UserChangedEvent) { |
|
72 | - $this->changeUser($event->getUser(), $event->getFeature()); |
|
73 | - } elseif ($event instanceof UserFirstTimeLoggedInEvent) { |
|
74 | - $this->firstLogin($event->getUser()); |
|
75 | - } elseif ($event instanceof UserUpdatedEvent) { |
|
76 | - $this->updateUser($event->getUser()); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - public function postCreateUser(IUser $user): void { |
|
81 | - $this->syncService->updateUser($user); |
|
82 | - } |
|
83 | - |
|
84 | - public function updateUser(IUser $user): void { |
|
85 | - $this->syncService->updateUser($user); |
|
86 | - } |
|
87 | - |
|
88 | - public function preDeleteUser(IUser $user): void { |
|
89 | - $uid = $user->getUID(); |
|
90 | - $userPrincipalUri = 'principals/users/' . $uid; |
|
91 | - $this->usersToDelete[$uid] = $user; |
|
92 | - $this->calendarsToDelete[$uid] = $this->calDav->getUsersOwnCalendars($userPrincipalUri); |
|
93 | - $this->subscriptionsToDelete[$uid] = $this->calDav->getSubscriptionsForUser($userPrincipalUri); |
|
94 | - $this->addressBooksToDelete[$uid] = $this->cardDav->getUsersOwnAddressBooks($userPrincipalUri); |
|
95 | - } |
|
96 | - |
|
97 | - public function preUnassignedUserId(string $uid): void { |
|
98 | - $user = $this->userManager->get($uid); |
|
99 | - if ($user !== null) { |
|
100 | - $this->usersToDelete[$uid] = $user; |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - public function postDeleteUser(string $uid): void { |
|
105 | - if (isset($this->usersToDelete[$uid])) { |
|
106 | - $this->syncService->deleteUser($this->usersToDelete[$uid]); |
|
107 | - } |
|
108 | - |
|
109 | - foreach ($this->calendarsToDelete[$uid] as $calendar) { |
|
110 | - $this->calDav->deleteCalendar( |
|
111 | - $calendar['id'], |
|
112 | - true // Make sure the data doesn't go into the trashbin, a new user with the same UID would later see it otherwise |
|
113 | - ); |
|
114 | - } |
|
115 | - |
|
116 | - foreach ($this->subscriptionsToDelete[$uid] as $subscription) { |
|
117 | - $this->calDav->deleteSubscription( |
|
118 | - $subscription['id'], |
|
119 | - ); |
|
120 | - } |
|
121 | - $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
122 | - |
|
123 | - foreach ($this->addressBooksToDelete[$uid] as $addressBook) { |
|
124 | - $this->cardDav->deleteAddressBook($addressBook['id']); |
|
125 | - } |
|
126 | - |
|
127 | - unset($this->calendarsToDelete[$uid]); |
|
128 | - unset($this->subscriptionsToDelete[$uid]); |
|
129 | - unset($this->addressBooksToDelete[$uid]); |
|
130 | - } |
|
131 | - |
|
132 | - public function changeUser(IUser $user, string $feature): void { |
|
133 | - // This case is already covered by the account manager firing up a signal |
|
134 | - // later on |
|
135 | - if ($feature !== 'eMailAddress' && $feature !== 'displayName') { |
|
136 | - $this->syncService->updateUser($user); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - public function firstLogin(IUser $user): void { |
|
141 | - $principal = 'principals/users/' . $user->getUID(); |
|
142 | - |
|
143 | - $calendarId = null; |
|
144 | - if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
|
145 | - try { |
|
146 | - $calendarId = $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
|
147 | - '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
148 | - '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), |
|
149 | - 'components' => 'VEVENT' |
|
150 | - ]); |
|
151 | - } catch (\Exception $e) { |
|
152 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
153 | - } |
|
154 | - } |
|
155 | - if ($calendarId !== null) { |
|
156 | - try { |
|
157 | - $this->exampleEventService->createExampleEvent($calendarId); |
|
158 | - } catch (\Exception $e) { |
|
159 | - $this->logger->error('Failed to create example event: ' . $e->getMessage(), [ |
|
160 | - 'exception' => $e, |
|
161 | - 'userId' => $user->getUID(), |
|
162 | - 'calendarId' => $calendarId, |
|
163 | - ]); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - $addressBookId = null; |
|
168 | - if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { |
|
169 | - try { |
|
170 | - $addressBookId = $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ |
|
171 | - '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, |
|
172 | - ]); |
|
173 | - } catch (\Exception $e) { |
|
174 | - $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
175 | - } |
|
176 | - } |
|
177 | - if ($addressBookId) { |
|
178 | - $this->exampleContactService->createDefaultContact($addressBookId); |
|
179 | - } |
|
180 | - } |
|
36 | + /** @var IUser[] */ |
|
37 | + private array $usersToDelete = []; |
|
38 | + |
|
39 | + private array $calendarsToDelete = []; |
|
40 | + private array $subscriptionsToDelete = []; |
|
41 | + private array $addressBooksToDelete = []; |
|
42 | + |
|
43 | + public function __construct( |
|
44 | + private IUserManager $userManager, |
|
45 | + private SyncService $syncService, |
|
46 | + private CalDavBackend $calDav, |
|
47 | + private CardDavBackend $cardDav, |
|
48 | + private Defaults $themingDefaults, |
|
49 | + private ExampleContactService $exampleContactService, |
|
50 | + private ExampleEventService $exampleEventService, |
|
51 | + private LoggerInterface $logger, |
|
52 | + ) { |
|
53 | + } |
|
54 | + |
|
55 | + public function handle(Event $event): void { |
|
56 | + if ($event instanceof UserCreatedEvent) { |
|
57 | + $this->postCreateUser($event->getUser()); |
|
58 | + } elseif ($event instanceof UserIdAssignedEvent) { |
|
59 | + $user = $this->userManager->get($event->getUserId()); |
|
60 | + if ($user !== null) { |
|
61 | + $this->postCreateUser($user); |
|
62 | + } |
|
63 | + } elseif ($event instanceof BeforeUserDeletedEvent) { |
|
64 | + $this->preDeleteUser($event->getUser()); |
|
65 | + } elseif ($event instanceof BeforeUserIdUnassignedEvent) { |
|
66 | + $this->preUnassignedUserId($event->getUserId()); |
|
67 | + } elseif ($event instanceof UserDeletedEvent) { |
|
68 | + $this->postDeleteUser($event->getUid()); |
|
69 | + } elseif ($event instanceof UserIdUnassignedEvent) { |
|
70 | + $this->postDeleteUser($event->getUserId()); |
|
71 | + } elseif ($event instanceof UserChangedEvent) { |
|
72 | + $this->changeUser($event->getUser(), $event->getFeature()); |
|
73 | + } elseif ($event instanceof UserFirstTimeLoggedInEvent) { |
|
74 | + $this->firstLogin($event->getUser()); |
|
75 | + } elseif ($event instanceof UserUpdatedEvent) { |
|
76 | + $this->updateUser($event->getUser()); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + public function postCreateUser(IUser $user): void { |
|
81 | + $this->syncService->updateUser($user); |
|
82 | + } |
|
83 | + |
|
84 | + public function updateUser(IUser $user): void { |
|
85 | + $this->syncService->updateUser($user); |
|
86 | + } |
|
87 | + |
|
88 | + public function preDeleteUser(IUser $user): void { |
|
89 | + $uid = $user->getUID(); |
|
90 | + $userPrincipalUri = 'principals/users/' . $uid; |
|
91 | + $this->usersToDelete[$uid] = $user; |
|
92 | + $this->calendarsToDelete[$uid] = $this->calDav->getUsersOwnCalendars($userPrincipalUri); |
|
93 | + $this->subscriptionsToDelete[$uid] = $this->calDav->getSubscriptionsForUser($userPrincipalUri); |
|
94 | + $this->addressBooksToDelete[$uid] = $this->cardDav->getUsersOwnAddressBooks($userPrincipalUri); |
|
95 | + } |
|
96 | + |
|
97 | + public function preUnassignedUserId(string $uid): void { |
|
98 | + $user = $this->userManager->get($uid); |
|
99 | + if ($user !== null) { |
|
100 | + $this->usersToDelete[$uid] = $user; |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + public function postDeleteUser(string $uid): void { |
|
105 | + if (isset($this->usersToDelete[$uid])) { |
|
106 | + $this->syncService->deleteUser($this->usersToDelete[$uid]); |
|
107 | + } |
|
108 | + |
|
109 | + foreach ($this->calendarsToDelete[$uid] as $calendar) { |
|
110 | + $this->calDav->deleteCalendar( |
|
111 | + $calendar['id'], |
|
112 | + true // Make sure the data doesn't go into the trashbin, a new user with the same UID would later see it otherwise |
|
113 | + ); |
|
114 | + } |
|
115 | + |
|
116 | + foreach ($this->subscriptionsToDelete[$uid] as $subscription) { |
|
117 | + $this->calDav->deleteSubscription( |
|
118 | + $subscription['id'], |
|
119 | + ); |
|
120 | + } |
|
121 | + $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
122 | + |
|
123 | + foreach ($this->addressBooksToDelete[$uid] as $addressBook) { |
|
124 | + $this->cardDav->deleteAddressBook($addressBook['id']); |
|
125 | + } |
|
126 | + |
|
127 | + unset($this->calendarsToDelete[$uid]); |
|
128 | + unset($this->subscriptionsToDelete[$uid]); |
|
129 | + unset($this->addressBooksToDelete[$uid]); |
|
130 | + } |
|
131 | + |
|
132 | + public function changeUser(IUser $user, string $feature): void { |
|
133 | + // This case is already covered by the account manager firing up a signal |
|
134 | + // later on |
|
135 | + if ($feature !== 'eMailAddress' && $feature !== 'displayName') { |
|
136 | + $this->syncService->updateUser($user); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + public function firstLogin(IUser $user): void { |
|
141 | + $principal = 'principals/users/' . $user->getUID(); |
|
142 | + |
|
143 | + $calendarId = null; |
|
144 | + if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
|
145 | + try { |
|
146 | + $calendarId = $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
|
147 | + '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
148 | + '{http://apple.com/ns/ical/}calendar-color' => $this->themingDefaults->getColorPrimary(), |
|
149 | + 'components' => 'VEVENT' |
|
150 | + ]); |
|
151 | + } catch (\Exception $e) { |
|
152 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
153 | + } |
|
154 | + } |
|
155 | + if ($calendarId !== null) { |
|
156 | + try { |
|
157 | + $this->exampleEventService->createExampleEvent($calendarId); |
|
158 | + } catch (\Exception $e) { |
|
159 | + $this->logger->error('Failed to create example event: ' . $e->getMessage(), [ |
|
160 | + 'exception' => $e, |
|
161 | + 'userId' => $user->getUID(), |
|
162 | + 'calendarId' => $calendarId, |
|
163 | + ]); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + $addressBookId = null; |
|
168 | + if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { |
|
169 | + try { |
|
170 | + $addressBookId = $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ |
|
171 | + '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, |
|
172 | + ]); |
|
173 | + } catch (\Exception $e) { |
|
174 | + $this->logger->error($e->getMessage(), ['exception' => $e]); |
|
175 | + } |
|
176 | + } |
|
177 | + if ($addressBookId) { |
|
178 | + $this->exampleContactService->createDefaultContact($addressBookId); |
|
179 | + } |
|
180 | + } |
|
181 | 181 | } |
@@ -24,133 +24,133 @@ |
||
24 | 24 | use Test\TestCase; |
25 | 25 | |
26 | 26 | class UserEventsListenerTest extends TestCase { |
27 | - private IUserManager&MockObject $userManager; |
|
28 | - private SyncService&MockObject $syncService; |
|
29 | - private CalDavBackend&MockObject $calDavBackend; |
|
30 | - private CardDavBackend&MockObject $cardDavBackend; |
|
31 | - private Defaults&MockObject $defaults; |
|
32 | - private ExampleContactService&MockObject $exampleContactService; |
|
33 | - private ExampleEventService&MockObject $exampleEventService; |
|
34 | - private LoggerInterface&MockObject $logger; |
|
35 | - |
|
36 | - private UserEventsListener $userEventsListener; |
|
37 | - |
|
38 | - protected function setUp(): void { |
|
39 | - parent::setUp(); |
|
40 | - |
|
41 | - $this->userManager = $this->createMock(IUserManager::class); |
|
42 | - $this->syncService = $this->createMock(SyncService::class); |
|
43 | - $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
44 | - $this->cardDavBackend = $this->createMock(CardDavBackend::class); |
|
45 | - $this->defaults = $this->createMock(Defaults::class); |
|
46 | - $this->exampleContactService = $this->createMock(ExampleContactService::class); |
|
47 | - $this->exampleEventService = $this->createMock(ExampleEventService::class); |
|
48 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
49 | - |
|
50 | - $this->userEventsListener = new UserEventsListener( |
|
51 | - $this->userManager, |
|
52 | - $this->syncService, |
|
53 | - $this->calDavBackend, |
|
54 | - $this->cardDavBackend, |
|
55 | - $this->defaults, |
|
56 | - $this->exampleContactService, |
|
57 | - $this->exampleEventService, |
|
58 | - $this->logger, |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - public function test(): void { |
|
63 | - $user = $this->createMock(IUser::class); |
|
64 | - $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
65 | - |
|
66 | - $this->defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca'); |
|
67 | - |
|
68 | - $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); |
|
69 | - $this->calDavBackend->expects($this->once())->method('createCalendar')->with( |
|
70 | - 'principals/users/newUser', |
|
71 | - 'personal', [ |
|
72 | - '{DAV:}displayname' => 'Personal', |
|
73 | - '{http://apple.com/ns/ical/}calendar-color' => '#745bca', |
|
74 | - 'components' => 'VEVENT' |
|
75 | - ]) |
|
76 | - ->willReturn(1000); |
|
77 | - $this->calDavBackend->expects(self::never()) |
|
78 | - ->method('getCalendarsForUser'); |
|
79 | - $this->exampleEventService->expects(self::once()) |
|
80 | - ->method('createExampleEvent') |
|
81 | - ->with(1000); |
|
82 | - |
|
83 | - $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); |
|
84 | - $this->cardDavBackend->expects($this->once())->method('createAddressBook')->with( |
|
85 | - 'principals/users/newUser', |
|
86 | - 'contacts', ['{DAV:}displayname' => 'Contacts']); |
|
87 | - |
|
88 | - $this->userEventsListener->firstLogin($user); |
|
89 | - } |
|
90 | - |
|
91 | - public function testWithExisting(): void { |
|
92 | - $user = $this->createMock(IUser::class); |
|
93 | - $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
94 | - |
|
95 | - $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(1); |
|
96 | - $this->calDavBackend->expects($this->never())->method('createCalendar'); |
|
97 | - $this->calDavBackend->expects(self::never()) |
|
98 | - ->method('createCalendar'); |
|
99 | - $this->exampleEventService->expects(self::never()) |
|
100 | - ->method('createExampleEvent'); |
|
101 | - |
|
102 | - $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1); |
|
103 | - $this->cardDavBackend->expects($this->never())->method('createAddressBook'); |
|
104 | - |
|
105 | - $this->userEventsListener->firstLogin($user); |
|
106 | - } |
|
107 | - |
|
108 | - public function testWithBirthdayCalendar(): void { |
|
109 | - $user = $this->createMock(IUser::class); |
|
110 | - $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
111 | - |
|
112 | - $this->defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca'); |
|
113 | - |
|
114 | - $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); |
|
115 | - $this->calDavBackend->expects($this->once())->method('createCalendar')->with( |
|
116 | - 'principals/users/newUser', |
|
117 | - 'personal', [ |
|
118 | - '{DAV:}displayname' => 'Personal', |
|
119 | - '{http://apple.com/ns/ical/}calendar-color' => '#745bca', |
|
120 | - 'components' => 'VEVENT' |
|
121 | - ]); |
|
122 | - |
|
123 | - $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); |
|
124 | - $this->cardDavBackend->expects($this->once())->method('createAddressBook')->with( |
|
125 | - 'principals/users/newUser', |
|
126 | - 'contacts', ['{DAV:}displayname' => 'Contacts']); |
|
127 | - |
|
128 | - $this->userEventsListener->firstLogin($user); |
|
129 | - } |
|
130 | - |
|
131 | - public function testDeleteCalendar(): void { |
|
132 | - $user = $this->createMock(IUser::class); |
|
133 | - $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
134 | - |
|
135 | - $this->syncService->expects($this->once()) |
|
136 | - ->method('deleteUser'); |
|
137 | - |
|
138 | - $this->calDavBackend->expects($this->once())->method('getUsersOwnCalendars')->willReturn([ |
|
139 | - ['id' => 'personal'] |
|
140 | - ]); |
|
141 | - $this->calDavBackend->expects($this->once())->method('getSubscriptionsForUser')->willReturn([ |
|
142 | - ['id' => 'some-subscription'] |
|
143 | - ]); |
|
144 | - $this->calDavBackend->expects($this->once())->method('deleteCalendar')->with('personal'); |
|
145 | - $this->calDavBackend->expects($this->once())->method('deleteSubscription')->with('some-subscription'); |
|
146 | - $this->calDavBackend->expects($this->once())->method('deleteAllSharesByUser'); |
|
147 | - |
|
148 | - $this->cardDavBackend->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([ |
|
149 | - ['id' => 'personal'] |
|
150 | - ]); |
|
151 | - $this->cardDavBackend->expects($this->once())->method('deleteAddressBook'); |
|
152 | - |
|
153 | - $this->userEventsListener->preDeleteUser($user); |
|
154 | - $this->userEventsListener->postDeleteUser('newUser'); |
|
155 | - } |
|
27 | + private IUserManager&MockObject $userManager; |
|
28 | + private SyncService&MockObject $syncService; |
|
29 | + private CalDavBackend&MockObject $calDavBackend; |
|
30 | + private CardDavBackend&MockObject $cardDavBackend; |
|
31 | + private Defaults&MockObject $defaults; |
|
32 | + private ExampleContactService&MockObject $exampleContactService; |
|
33 | + private ExampleEventService&MockObject $exampleEventService; |
|
34 | + private LoggerInterface&MockObject $logger; |
|
35 | + |
|
36 | + private UserEventsListener $userEventsListener; |
|
37 | + |
|
38 | + protected function setUp(): void { |
|
39 | + parent::setUp(); |
|
40 | + |
|
41 | + $this->userManager = $this->createMock(IUserManager::class); |
|
42 | + $this->syncService = $this->createMock(SyncService::class); |
|
43 | + $this->calDavBackend = $this->createMock(CalDavBackend::class); |
|
44 | + $this->cardDavBackend = $this->createMock(CardDavBackend::class); |
|
45 | + $this->defaults = $this->createMock(Defaults::class); |
|
46 | + $this->exampleContactService = $this->createMock(ExampleContactService::class); |
|
47 | + $this->exampleEventService = $this->createMock(ExampleEventService::class); |
|
48 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
49 | + |
|
50 | + $this->userEventsListener = new UserEventsListener( |
|
51 | + $this->userManager, |
|
52 | + $this->syncService, |
|
53 | + $this->calDavBackend, |
|
54 | + $this->cardDavBackend, |
|
55 | + $this->defaults, |
|
56 | + $this->exampleContactService, |
|
57 | + $this->exampleEventService, |
|
58 | + $this->logger, |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + public function test(): void { |
|
63 | + $user = $this->createMock(IUser::class); |
|
64 | + $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
65 | + |
|
66 | + $this->defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca'); |
|
67 | + |
|
68 | + $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); |
|
69 | + $this->calDavBackend->expects($this->once())->method('createCalendar')->with( |
|
70 | + 'principals/users/newUser', |
|
71 | + 'personal', [ |
|
72 | + '{DAV:}displayname' => 'Personal', |
|
73 | + '{http://apple.com/ns/ical/}calendar-color' => '#745bca', |
|
74 | + 'components' => 'VEVENT' |
|
75 | + ]) |
|
76 | + ->willReturn(1000); |
|
77 | + $this->calDavBackend->expects(self::never()) |
|
78 | + ->method('getCalendarsForUser'); |
|
79 | + $this->exampleEventService->expects(self::once()) |
|
80 | + ->method('createExampleEvent') |
|
81 | + ->with(1000); |
|
82 | + |
|
83 | + $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); |
|
84 | + $this->cardDavBackend->expects($this->once())->method('createAddressBook')->with( |
|
85 | + 'principals/users/newUser', |
|
86 | + 'contacts', ['{DAV:}displayname' => 'Contacts']); |
|
87 | + |
|
88 | + $this->userEventsListener->firstLogin($user); |
|
89 | + } |
|
90 | + |
|
91 | + public function testWithExisting(): void { |
|
92 | + $user = $this->createMock(IUser::class); |
|
93 | + $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
94 | + |
|
95 | + $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(1); |
|
96 | + $this->calDavBackend->expects($this->never())->method('createCalendar'); |
|
97 | + $this->calDavBackend->expects(self::never()) |
|
98 | + ->method('createCalendar'); |
|
99 | + $this->exampleEventService->expects(self::never()) |
|
100 | + ->method('createExampleEvent'); |
|
101 | + |
|
102 | + $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(1); |
|
103 | + $this->cardDavBackend->expects($this->never())->method('createAddressBook'); |
|
104 | + |
|
105 | + $this->userEventsListener->firstLogin($user); |
|
106 | + } |
|
107 | + |
|
108 | + public function testWithBirthdayCalendar(): void { |
|
109 | + $user = $this->createMock(IUser::class); |
|
110 | + $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
111 | + |
|
112 | + $this->defaults->expects($this->once())->method('getColorPrimary')->willReturn('#745bca'); |
|
113 | + |
|
114 | + $this->calDavBackend->expects($this->once())->method('getCalendarsForUserCount')->willReturn(0); |
|
115 | + $this->calDavBackend->expects($this->once())->method('createCalendar')->with( |
|
116 | + 'principals/users/newUser', |
|
117 | + 'personal', [ |
|
118 | + '{DAV:}displayname' => 'Personal', |
|
119 | + '{http://apple.com/ns/ical/}calendar-color' => '#745bca', |
|
120 | + 'components' => 'VEVENT' |
|
121 | + ]); |
|
122 | + |
|
123 | + $this->cardDavBackend->expects($this->once())->method('getAddressBooksForUserCount')->willReturn(0); |
|
124 | + $this->cardDavBackend->expects($this->once())->method('createAddressBook')->with( |
|
125 | + 'principals/users/newUser', |
|
126 | + 'contacts', ['{DAV:}displayname' => 'Contacts']); |
|
127 | + |
|
128 | + $this->userEventsListener->firstLogin($user); |
|
129 | + } |
|
130 | + |
|
131 | + public function testDeleteCalendar(): void { |
|
132 | + $user = $this->createMock(IUser::class); |
|
133 | + $user->expects($this->once())->method('getUID')->willReturn('newUser'); |
|
134 | + |
|
135 | + $this->syncService->expects($this->once()) |
|
136 | + ->method('deleteUser'); |
|
137 | + |
|
138 | + $this->calDavBackend->expects($this->once())->method('getUsersOwnCalendars')->willReturn([ |
|
139 | + ['id' => 'personal'] |
|
140 | + ]); |
|
141 | + $this->calDavBackend->expects($this->once())->method('getSubscriptionsForUser')->willReturn([ |
|
142 | + ['id' => 'some-subscription'] |
|
143 | + ]); |
|
144 | + $this->calDavBackend->expects($this->once())->method('deleteCalendar')->with('personal'); |
|
145 | + $this->calDavBackend->expects($this->once())->method('deleteSubscription')->with('some-subscription'); |
|
146 | + $this->calDavBackend->expects($this->once())->method('deleteAllSharesByUser'); |
|
147 | + |
|
148 | + $this->cardDavBackend->expects($this->once())->method('getUsersOwnAddressBooks')->willReturn([ |
|
149 | + ['id' => 'personal'] |
|
150 | + ]); |
|
151 | + $this->cardDavBackend->expects($this->once())->method('deleteAddressBook'); |
|
152 | + |
|
153 | + $this->userEventsListener->preDeleteUser($user); |
|
154 | + $this->userEventsListener->postDeleteUser('newUser'); |
|
155 | + } |
|
156 | 156 | } |
@@ -4,20 +4,20 @@ |
||
4 | 4 | * SPDX-License-Identifier: AGPL-3.0-or-later |
5 | 5 | */ |
6 | 6 | return [ |
7 | - 'routes' => [ |
|
8 | - ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'], |
|
9 | - ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'], |
|
10 | - ['name' => 'invitation_response#accept', 'url' => '/invitation/accept/{token}', 'verb' => 'GET'], |
|
11 | - ['name' => 'invitation_response#decline', 'url' => '/invitation/decline/{token}', 'verb' => 'GET'], |
|
12 | - ['name' => 'invitation_response#options', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'GET'], |
|
13 | - ['name' => 'invitation_response#processMoreOptionsResult', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'POST'], |
|
14 | - ], |
|
15 | - 'ocs' => [ |
|
16 | - ['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'], |
|
17 | - ['name' => 'upcoming_events#getEvents', 'url' => '/api/v1/events/upcoming', 'verb' => 'GET'], |
|
18 | - ['name' => 'out_of_office#getCurrentOutOfOfficeData', 'url' => '/api/v1/outOfOffice/{userId}/now', 'verb' => 'GET'], |
|
19 | - ['name' => 'out_of_office#getOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'GET'], |
|
20 | - ['name' => 'out_of_office#setOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'POST'], |
|
21 | - ['name' => 'out_of_office#clearOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'DELETE'], |
|
22 | - ], |
|
7 | + 'routes' => [ |
|
8 | + ['name' => 'birthday_calendar#enable', 'url' => '/enableBirthdayCalendar', 'verb' => 'POST'], |
|
9 | + ['name' => 'birthday_calendar#disable', 'url' => '/disableBirthdayCalendar', 'verb' => 'POST'], |
|
10 | + ['name' => 'invitation_response#accept', 'url' => '/invitation/accept/{token}', 'verb' => 'GET'], |
|
11 | + ['name' => 'invitation_response#decline', 'url' => '/invitation/decline/{token}', 'verb' => 'GET'], |
|
12 | + ['name' => 'invitation_response#options', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'GET'], |
|
13 | + ['name' => 'invitation_response#processMoreOptionsResult', 'url' => '/invitation/moreOptions/{token}', 'verb' => 'POST'], |
|
14 | + ], |
|
15 | + 'ocs' => [ |
|
16 | + ['name' => 'direct#getUrl', 'url' => '/api/v1/direct', 'verb' => 'POST'], |
|
17 | + ['name' => 'upcoming_events#getEvents', 'url' => '/api/v1/events/upcoming', 'verb' => 'GET'], |
|
18 | + ['name' => 'out_of_office#getCurrentOutOfOfficeData', 'url' => '/api/v1/outOfOffice/{userId}/now', 'verb' => 'GET'], |
|
19 | + ['name' => 'out_of_office#getOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'GET'], |
|
20 | + ['name' => 'out_of_office#setOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'POST'], |
|
21 | + ['name' => 'out_of_office#clearOutOfOffice', 'url' => '/api/v1/outOfOffice/{userId}', 'verb' => 'DELETE'], |
|
22 | + ], |
|
23 | 23 | ]; |