Passed
Push — master ( 5cfcde...3ea9dd )
by John
70:54 queued 12s
created
apps/dav/appinfo/v1/caldav.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
 use OCA\DAV\Connector\Sabre\Principal;
36 36
 
37 37
 $authBackend = new Auth(
38
-	\OC::$server->getSession(),
39
-	\OC::$server->getUserSession(),
40
-	\OC::$server->getRequest(),
41
-	\OC::$server->getTwoFactorAuthManager(),
42
-	\OC::$server->getBruteForceThrottler(),
43
-	'principals/'
38
+    \OC::$server->getSession(),
39
+    \OC::$server->getUserSession(),
40
+    \OC::$server->getRequest(),
41
+    \OC::$server->getTwoFactorAuthManager(),
42
+    \OC::$server->getBruteForceThrottler(),
43
+    'principals/'
44 44
 );
45 45
 $principalBackend = new Principal(
46
-	\OC::$server->getUserManager(),
47
-	\OC::$server->getGroupManager(),
48
-	\OC::$server->getShareManager(),
49
-	\OC::$server->getUserSession(),
50
-	\OC::$server->getAppManager(),
51
-	\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
52
-	\OC::$server->getConfig(),
53
-	'principals/'
46
+    \OC::$server->getUserManager(),
47
+    \OC::$server->getGroupManager(),
48
+    \OC::$server->getShareManager(),
49
+    \OC::$server->getUserSession(),
50
+    \OC::$server->getAppManager(),
51
+    \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
52
+    \OC::$server->getConfig(),
53
+    'principals/'
54 54
 );
55 55
 $db = \OC::$server->getDatabaseConnection();
56 56
 $userManager = \OC::$server->getUserManager();
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 $addressBookRoot->disableListing = !$debugging; // Disable listing
71 71
 
72 72
 $nodes = [
73
-	$principalCollection,
74
-	$addressBookRoot,
73
+    $principalCollection,
74
+    $addressBookRoot,
75 75
 ];
76 76
 
77 77
 // Fire up server
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
 $server->addPlugin(new LegacyDAVACL());
89 89
 if ($debugging) {
90
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
90
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
91 91
 }
92 92
 
93 93
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
96 96
 
97 97
 if ($sendInvitations) {
98
-	$server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
98
+    $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
99 99
 }
100 100
 $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
101 101
 
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -54,235 +54,235 @@
 block discarded – undo
54 54
 use Symfony\Component\EventDispatcher\GenericEvent;
55 55
 
56 56
 class Application extends App {
57
-	public const APP_ID = 'dav';
57
+    public const APP_ID = 'dav';
58 58
 
59
-	/**
60
-	 * Application constructor.
61
-	 */
62
-	public function __construct() {
63
-		parent::__construct('dav');
59
+    /**
60
+     * Application constructor.
61
+     */
62
+    public function __construct() {
63
+        parent::__construct('dav');
64 64
 
65
-		$container = $this->getContainer();
66
-		$server = $container->getServer();
65
+        $container = $this->getContainer();
66
+        $server = $container->getServer();
67 67
 
68
-		$container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
69
-			return new PhotoCache(
70
-				$server->getAppDataDir('dav-photocache'),
71
-				$server->getLogger()
72
-			);
73
-		});
68
+        $container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
69
+            return new PhotoCache(
70
+                $server->getAppDataDir('dav-photocache'),
71
+                $server->getLogger()
72
+            );
73
+        });
74 74
 
75
-		/*
75
+        /*
76 76
 		 * Register capabilities
77 77
 		 */
78
-		$container->registerCapability(Capabilities::class);
79
-	}
78
+        $container->registerCapability(Capabilities::class);
79
+    }
80 80
 
81
-	/**
82
-	 * @param IContactsManager $contactsManager
83
-	 * @param string $userID
84
-	 */
85
-	public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
86
-		/** @var ContactsManager $cm */
87
-		$cm = $this->getContainer()->query(ContactsManager::class);
88
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
89
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
90
-	}
81
+    /**
82
+     * @param IContactsManager $contactsManager
83
+     * @param string $userID
84
+     */
85
+    public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
86
+        /** @var ContactsManager $cm */
87
+        $cm = $this->getContainer()->query(ContactsManager::class);
88
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
89
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
90
+    }
91 91
 
92
-	/**
93
-	 * @param IContactsManager $contactsManager
94
-	 */
95
-	public function setupSystemContactsProvider(IContactsManager $contactsManager) {
96
-		/** @var ContactsManager $cm */
97
-		$cm = $this->getContainer()->query(ContactsManager::class);
98
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
99
-		$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
100
-	}
92
+    /**
93
+     * @param IContactsManager $contactsManager
94
+     */
95
+    public function setupSystemContactsProvider(IContactsManager $contactsManager) {
96
+        /** @var ContactsManager $cm */
97
+        $cm = $this->getContainer()->query(ContactsManager::class);
98
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
99
+        $cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
100
+    }
101 101
 
102
-	/**
103
-	 * @param ICalendarManager $calendarManager
104
-	 * @param string $userId
105
-	 */
106
-	public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
107
-		$cm = $this->getContainer()->query(CalendarManager::class);
108
-		$cm->setupCalendarProvider($calendarManager, $userId);
109
-	}
102
+    /**
103
+     * @param ICalendarManager $calendarManager
104
+     * @param string $userId
105
+     */
106
+    public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
107
+        $cm = $this->getContainer()->query(CalendarManager::class);
108
+        $cm->setupCalendarProvider($calendarManager, $userId);
109
+    }
110 110
 
111
-	public function registerHooks() {
112
-		/** @var HookManager $hm */
113
-		$hm = $this->getContainer()->query(HookManager::class);
114
-		$hm->setup();
111
+    public function registerHooks() {
112
+        /** @var HookManager $hm */
113
+        $hm = $this->getContainer()->query(HookManager::class);
114
+        $hm->setup();
115 115
 
116
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
116
+        $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
117 117
 
118
-		// first time login event setup
119
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
120
-			if ($event instanceof GenericEvent) {
121
-				$hm->firstLogin($event->getSubject());
122
-			}
123
-		});
118
+        // first time login event setup
119
+        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
120
+            if ($event instanceof GenericEvent) {
121
+                $hm->firstLogin($event->getSubject());
122
+            }
123
+        });
124 124
 
125
-		$birthdayListener = function ($event) {
126
-			if ($event instanceof GenericEvent) {
127
-				/** @var BirthdayService $b */
128
-				$b = $this->getContainer()->query(BirthdayService::class);
129
-				$b->onCardChanged(
130
-					$event->getArgument('addressBookId'),
131
-					$event->getArgument('cardUri'),
132
-					$event->getArgument('cardData')
133
-				);
134
-			}
135
-		};
125
+        $birthdayListener = function ($event) {
126
+            if ($event instanceof GenericEvent) {
127
+                /** @var BirthdayService $b */
128
+                $b = $this->getContainer()->query(BirthdayService::class);
129
+                $b->onCardChanged(
130
+                    $event->getArgument('addressBookId'),
131
+                    $event->getArgument('cardUri'),
132
+                    $event->getArgument('cardData')
133
+                );
134
+            }
135
+        };
136 136
 
137
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
138
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
139
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
140
-			if ($event instanceof GenericEvent) {
141
-				/** @var BirthdayService $b */
142
-				$b = $this->getContainer()->query(BirthdayService::class);
143
-				$b->onCardDeleted(
144
-					$event->getArgument('addressBookId'),
145
-					$event->getArgument('cardUri')
146
-				);
147
-			}
148
-		});
137
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
138
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
139
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
140
+            if ($event instanceof GenericEvent) {
141
+                /** @var BirthdayService $b */
142
+                $b = $this->getContainer()->query(BirthdayService::class);
143
+                $b->onCardDeleted(
144
+                    $event->getArgument('addressBookId'),
145
+                    $event->getArgument('cardUri')
146
+                );
147
+            }
148
+        });
149 149
 
150
-		$clearPhotoCache = function ($event) {
151
-			if ($event instanceof GenericEvent) {
152
-				/** @var PhotoCache $p */
153
-				$p = $this->getContainer()->query(PhotoCache::class);
154
-				$p->delete(
155
-					$event->getArgument('addressBookId'),
156
-					$event->getArgument('cardUri')
157
-				);
158
-			}
159
-		};
160
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
161
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
150
+        $clearPhotoCache = function ($event) {
151
+            if ($event instanceof GenericEvent) {
152
+                /** @var PhotoCache $p */
153
+                $p = $this->getContainer()->query(PhotoCache::class);
154
+                $p->delete(
155
+                    $event->getArgument('addressBookId'),
156
+                    $event->getArgument('cardUri')
157
+                );
158
+            }
159
+        };
160
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
161
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
162 162
 
163
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
164
-			$user = $event->getSubject();
165
-			$syncService = $this->getContainer()->query(SyncService::class);
166
-			$syncService->updateUser($user);
167
-		});
163
+        $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
164
+            $user = $event->getSubject();
165
+            $syncService = $this->getContainer()->query(SyncService::class);
166
+            $syncService->updateUser($user);
167
+        });
168 168
 
169
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
170
-			/** @var Backend $backend */
171
-			$backend = $this->getContainer()->query(Backend::class);
172
-			$backend->onCalendarAdd(
173
-				$event->getArgument('calendarData')
174
-			);
175
-		});
176
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
177
-			/** @var Backend $backend */
178
-			$backend = $this->getContainer()->query(Backend::class);
179
-			$backend->onCalendarUpdate(
180
-				$event->getArgument('calendarData'),
181
-				$event->getArgument('shares'),
182
-				$event->getArgument('propertyMutations')
183
-			);
184
-		});
185
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
186
-			/** @var Backend $backend */
187
-			$backend = $this->getContainer()->query(Backend::class);
188
-			$backend->onCalendarDelete(
189
-				$event->getArgument('calendarData'),
190
-				$event->getArgument('shares')
191
-			);
169
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
170
+            /** @var Backend $backend */
171
+            $backend = $this->getContainer()->query(Backend::class);
172
+            $backend->onCalendarAdd(
173
+                $event->getArgument('calendarData')
174
+            );
175
+        });
176
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
177
+            /** @var Backend $backend */
178
+            $backend = $this->getContainer()->query(Backend::class);
179
+            $backend->onCalendarUpdate(
180
+                $event->getArgument('calendarData'),
181
+                $event->getArgument('shares'),
182
+                $event->getArgument('propertyMutations')
183
+            );
184
+        });
185
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
186
+            /** @var Backend $backend */
187
+            $backend = $this->getContainer()->query(Backend::class);
188
+            $backend->onCalendarDelete(
189
+                $event->getArgument('calendarData'),
190
+                $event->getArgument('shares')
191
+            );
192 192
 
193
-			$reminderBackend = $this->getContainer()->query(ReminderBackend::class);
194
-			$reminderBackend->cleanRemindersForCalendar(
195
-				$event->getArgument('calendarId')
196
-			);
197
-		});
198
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
199
-			/** @var Backend $backend */
200
-			$backend = $this->getContainer()->query(Backend::class);
201
-			$backend->onCalendarUpdateShares(
202
-				$event->getArgument('calendarData'),
203
-				$event->getArgument('shares'),
204
-				$event->getArgument('add'),
205
-				$event->getArgument('remove')
206
-			);
193
+            $reminderBackend = $this->getContainer()->query(ReminderBackend::class);
194
+            $reminderBackend->cleanRemindersForCalendar(
195
+                $event->getArgument('calendarId')
196
+            );
197
+        });
198
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
199
+            /** @var Backend $backend */
200
+            $backend = $this->getContainer()->query(Backend::class);
201
+            $backend->onCalendarUpdateShares(
202
+                $event->getArgument('calendarData'),
203
+                $event->getArgument('shares'),
204
+                $event->getArgument('add'),
205
+                $event->getArgument('remove')
206
+            );
207 207
 
208
-			// Here we should recalculate if reminders should be sent to new or old sharees
209
-		});
208
+            // Here we should recalculate if reminders should be sent to new or old sharees
209
+        });
210 210
 
211
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
212
-			/** @var Backend $backend */
213
-			$backend = $this->getContainer()->query(Backend::class);
214
-			$backend->onCalendarPublication(
215
-				$event->getArgument('calendarData'),
216
-				$event->getArgument('public')
217
-			);
218
-		});
211
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
212
+            /** @var Backend $backend */
213
+            $backend = $this->getContainer()->query(Backend::class);
214
+            $backend->onCalendarPublication(
215
+                $event->getArgument('calendarData'),
216
+                $event->getArgument('public')
217
+            );
218
+        });
219 219
 
220
-		$listener = function (GenericEvent $event, $eventName) {
221
-			/** @var Backend $backend */
222
-			$backend = $this->getContainer()->query(Backend::class);
220
+        $listener = function (GenericEvent $event, $eventName) {
221
+            /** @var Backend $backend */
222
+            $backend = $this->getContainer()->query(Backend::class);
223 223
 
224
-			$subject = Event::SUBJECT_OBJECT_ADD;
225
-			if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
226
-				$subject = Event::SUBJECT_OBJECT_UPDATE;
227
-			} elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
228
-				$subject = Event::SUBJECT_OBJECT_DELETE;
229
-			}
230
-			$backend->onTouchCalendarObject(
231
-				$subject,
232
-				$event->getArgument('calendarData'),
233
-				$event->getArgument('shares'),
234
-				$event->getArgument('objectData')
235
-			);
224
+            $subject = Event::SUBJECT_OBJECT_ADD;
225
+            if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
226
+                $subject = Event::SUBJECT_OBJECT_UPDATE;
227
+            } elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
228
+                $subject = Event::SUBJECT_OBJECT_DELETE;
229
+            }
230
+            $backend->onTouchCalendarObject(
231
+                $subject,
232
+                $event->getArgument('calendarData'),
233
+                $event->getArgument('shares'),
234
+                $event->getArgument('objectData')
235
+            );
236 236
 
237
-			/** @var ReminderService $reminderBackend */
238
-			$reminderService = $this->getContainer()->query(ReminderService::class);
237
+            /** @var ReminderService $reminderBackend */
238
+            $reminderService = $this->getContainer()->query(ReminderService::class);
239 239
 
240
-			$reminderService->onTouchCalendarObject(
241
-				$eventName,
242
-				$event->getArgument('objectData')
243
-			);
244
-		};
245
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
246
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
247
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
240
+            $reminderService->onTouchCalendarObject(
241
+                $eventName,
242
+                $event->getArgument('objectData')
243
+            );
244
+        };
245
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
246
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
247
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
248 248
 
249
-		/**
250
-		 * In case the user has set their default calendar to this one
251
-		 */
252
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
253
-			/** @var IConfig $config */
254
-			$config = $this->getContainer()->getServer()->getConfig();
255
-			$principalUri = $event->getArgument('calendarData')['principaluri'];
256
-			if (strpos($principalUri, 'principals/users') === 0) {
257
-				list(, $UID) = \Sabre\Uri\split($principalUri);
258
-				$uri = $event->getArgument('calendarData')['uri'];
259
-				if ($config->getUserValue($UID, 'dav', 'defaultCalendar') === $uri) {
260
-					$config->deleteUserValue($UID, 'dav', 'defaultCalendar');
261
-				}
262
-			}
263
-		});
264
-	}
249
+        /**
250
+         * In case the user has set their default calendar to this one
251
+         */
252
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
253
+            /** @var IConfig $config */
254
+            $config = $this->getContainer()->getServer()->getConfig();
255
+            $principalUri = $event->getArgument('calendarData')['principaluri'];
256
+            if (strpos($principalUri, 'principals/users') === 0) {
257
+                list(, $UID) = \Sabre\Uri\split($principalUri);
258
+                $uri = $event->getArgument('calendarData')['uri'];
259
+                if ($config->getUserValue($UID, 'dav', 'defaultCalendar') === $uri) {
260
+                    $config->deleteUserValue($UID, 'dav', 'defaultCalendar');
261
+                }
262
+            }
263
+        });
264
+    }
265 265
 
266
-	public function getSyncService() {
267
-		return $this->getContainer()->query(SyncService::class);
268
-	}
266
+    public function getSyncService() {
267
+        return $this->getContainer()->query(SyncService::class);
268
+    }
269 269
 
270
-	public function registerNotifier():void {
271
-		$this->getContainer()
272
-			->getServer()
273
-			->getNotificationManager()
274
-			->registerNotifierService(Notifier::class);
275
-	}
270
+    public function registerNotifier():void {
271
+        $this->getContainer()
272
+            ->getServer()
273
+            ->getNotificationManager()
274
+            ->registerNotifierService(Notifier::class);
275
+    }
276 276
 
277
-	public function registerCalendarReminders():void {
278
-		try {
279
-			/** @var NotificationProviderManager $notificationProviderManager */
280
-			$notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
281
-			$notificationProviderManager->registerProvider(AudioProvider::class);
282
-			$notificationProviderManager->registerProvider(EmailProvider::class);
283
-			$notificationProviderManager->registerProvider(PushProvider::class);
284
-		} catch (\Exception $ex) {
285
-			$this->getContainer()->getServer()->getLogger()->logException($ex);
286
-		}
287
-	}
277
+    public function registerCalendarReminders():void {
278
+        try {
279
+            /** @var NotificationProviderManager $notificationProviderManager */
280
+            $notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
281
+            $notificationProviderManager->registerProvider(AudioProvider::class);
282
+            $notificationProviderManager->registerProvider(EmailProvider::class);
283
+            $notificationProviderManager->registerProvider(PushProvider::class);
284
+        } catch (\Exception $ex) {
285
+            $this->getContainer()->getServer()->getLogger()->logException($ex);
286
+        }
287
+    }
288 288
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		$container = $this->getContainer();
66 66
 		$server = $container->getServer();
67 67
 
68
-		$container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
68
+		$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
69 69
 			return new PhotoCache(
70 70
 				$server->getAppDataDir('dav-photocache'),
71 71
 				$server->getLogger()
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
 		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
117 117
 
118 118
 		// first time login event setup
119
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
119
+		$dispatcher->addListener(IUser::class.'::firstLogin', function($event) use ($hm) {
120 120
 			if ($event instanceof GenericEvent) {
121 121
 				$hm->firstLogin($event->getSubject());
122 122
 			}
123 123
 		});
124 124
 
125
-		$birthdayListener = function ($event) {
125
+		$birthdayListener = function($event) {
126 126
 			if ($event instanceof GenericEvent) {
127 127
 				/** @var BirthdayService $b */
128 128
 				$b = $this->getContainer()->query(BirthdayService::class);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
 		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
138 138
 		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
139
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
139
+		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
140 140
 			if ($event instanceof GenericEvent) {
141 141
 				/** @var BirthdayService $b */
142 142
 				$b = $this->getContainer()->query(BirthdayService::class);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 			}
148 148
 		});
149 149
 
150
-		$clearPhotoCache = function ($event) {
150
+		$clearPhotoCache = function($event) {
151 151
 			if ($event instanceof GenericEvent) {
152 152
 				/** @var PhotoCache $p */
153 153
 				$p = $this->getContainer()->query(PhotoCache::class);
@@ -160,20 +160,20 @@  discard block
 block discarded – undo
160 160
 		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
161 161
 		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
162 162
 
163
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
163
+		$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
164 164
 			$user = $event->getSubject();
165 165
 			$syncService = $this->getContainer()->query(SyncService::class);
166 166
 			$syncService->updateUser($user);
167 167
 		});
168 168
 
169
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
169
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
170 170
 			/** @var Backend $backend */
171 171
 			$backend = $this->getContainer()->query(Backend::class);
172 172
 			$backend->onCalendarAdd(
173 173
 				$event->getArgument('calendarData')
174 174
 			);
175 175
 		});
176
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
176
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
177 177
 			/** @var Backend $backend */
178 178
 			$backend = $this->getContainer()->query(Backend::class);
179 179
 			$backend->onCalendarUpdate(
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 				$event->getArgument('propertyMutations')
183 183
 			);
184 184
 		});
185
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
185
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
186 186
 			/** @var Backend $backend */
187 187
 			$backend = $this->getContainer()->query(Backend::class);
188 188
 			$backend->onCalendarDelete(
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 				$event->getArgument('calendarId')
196 196
 			);
197 197
 		});
198
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
198
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
199 199
 			/** @var Backend $backend */
200 200
 			$backend = $this->getContainer()->query(Backend::class);
201 201
 			$backend->onCalendarUpdateShares(
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 			// Here we should recalculate if reminders should be sent to new or old sharees
209 209
 		});
210 210
 
211
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
211
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
212 212
 			/** @var Backend $backend */
213 213
 			$backend = $this->getContainer()->query(Backend::class);
214 214
 			$backend->onCalendarPublication(
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 			);
218 218
 		});
219 219
 
220
-		$listener = function (GenericEvent $event, $eventName) {
220
+		$listener = function(GenericEvent $event, $eventName) {
221 221
 			/** @var Backend $backend */
222 222
 			$backend = $this->getContainer()->query(Backend::class);
223 223
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		/**
250 250
 		 * In case the user has set their default calendar to this one
251 251
 		 */
252
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
252
+		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
253 253
 			/** @var IConfig $config */
254 254
 			$config = $this->getContainer()->getServer()->getConfig();
255 255
 			$principalUri = $event->getArgument('calendarData')['principaluri'];
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/Plugin.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -52,165 +52,165 @@  discard block
 block discarded – undo
52 52
 
53 53
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
54 54
 
55
-	/**
56
-	 * @var IConfig
57
-	 */
58
-	private $config;
59
-
60
-	/** @var ITip\Message[] */
61
-	private $schedulingResponses = [];
62
-
63
-	/** @var string|null */
64
-	private $pathOfCalendarObjectChange = null;
65
-
66
-	public const CALENDAR_USER_TYPE = '{' . self::NS_CALDAV . '}calendar-user-type';
67
-	public const SCHEDULE_DEFAULT_CALENDAR_URL = '{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL';
68
-
69
-	/**
70
-	 * @param IConfig $config
71
-	 */
72
-	public function __construct(IConfig $config) {
73
-		$this->config = $config;
74
-	}
75
-
76
-	/**
77
-	 * Initializes the plugin
78
-	 *
79
-	 * @param Server $server
80
-	 * @return void
81
-	 */
82
-	public function initialize(Server $server) {
83
-		parent::initialize($server);
84
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
85
-		$server->on('afterWriteContent', [$this, 'dispatchSchedulingResponses']);
86
-		$server->on('afterCreateFile', [$this, 'dispatchSchedulingResponses']);
87
-	}
88
-
89
-	/**
90
-	 * This method handler is invoked during fetching of properties.
91
-	 *
92
-	 * We use this event to add calendar-auto-schedule-specific properties.
93
-	 *
94
-	 * @param PropFind $propFind
95
-	 * @param INode $node
96
-	 * @return void
97
-	 */
98
-	public function propFind(PropFind $propFind, INode $node) {
99
-		if ($node instanceof IPrincipal) {
100
-			// overwrite Sabre/Dav's implementation
101
-			$propFind->handle(self::CALENDAR_USER_TYPE, function () use ($node) {
102
-				if ($node instanceof IProperties) {
103
-					$props = $node->getProperties([self::CALENDAR_USER_TYPE]);
104
-
105
-					if (isset($props[self::CALENDAR_USER_TYPE])) {
106
-						return $props[self::CALENDAR_USER_TYPE];
107
-					}
108
-				}
109
-
110
-				return 'INDIVIDUAL';
111
-			});
112
-		}
113
-
114
-		parent::propFind($propFind, $node);
115
-	}
116
-
117
-	/**
118
-	 * Returns a list of addresses that are associated with a principal.
119
-	 *
120
-	 * @param string $principal
121
-	 * @return array
122
-	 */
123
-	protected function getAddressesForPrincipal($principal) {
124
-		$result = parent::getAddressesForPrincipal($principal);
125
-
126
-		if ($result === null) {
127
-			$result = [];
128
-		}
129
-
130
-		return $result;
131
-	}
132
-
133
-	/**
134
-	 * @param RequestInterface $request
135
-	 * @param ResponseInterface $response
136
-	 * @param VCalendar $vCal
137
-	 * @param mixed $calendarPath
138
-	 * @param mixed $modified
139
-	 * @param mixed $isNew
140
-	 */
141
-	public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
142
-		// Save the first path we get as a calendar-object-change request
143
-		if (!$this->pathOfCalendarObjectChange) {
144
-			$this->pathOfCalendarObjectChange = $request->getPath();
145
-		}
146
-
147
-		parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
148
-	}
149
-
150
-	/**
151
-	 * @inheritDoc
152
-	 */
153
-	public function scheduleLocalDelivery(ITip\Message $iTipMessage):void {
154
-		parent::scheduleLocalDelivery($iTipMessage);
155
-
156
-		// We only care when the message was successfully delivered locally
157
-		if ($iTipMessage->scheduleStatus !== '1.2;Message delivered locally') {
158
-			return;
159
-		}
160
-
161
-		// We only care about request. reply and cancel are properly handled
162
-		// by parent::scheduleLocalDelivery already
163
-		if (strcasecmp($iTipMessage->method, 'REQUEST') !== 0) {
164
-			return;
165
-		}
166
-
167
-		// If parent::scheduleLocalDelivery set scheduleStatus to 1.2,
168
-		// it means that it was successfully delivered locally.
169
-		// Meaning that the ACL plugin is loaded and that a principial
170
-		// exists for the given recipient id, no need to double check
171
-		/** @var \Sabre\DAVACL\Plugin $aclPlugin */
172
-		$aclPlugin = $this->server->getPlugin('acl');
173
-		$principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
174
-		$calendarUserType = $this->getCalendarUserTypeForPrincipal($principalUri);
175
-		if (strcasecmp($calendarUserType, 'ROOM') !== 0 && strcasecmp($calendarUserType, 'RESOURCE') !== 0) {
176
-			return;
177
-		}
178
-
179
-		$attendee = $this->getCurrentAttendee($iTipMessage);
180
-		if (!$attendee) {
181
-			return;
182
-		}
183
-
184
-		// We only respond when a response was actually requested
185
-		$rsvp = $this->getAttendeeRSVP($attendee);
186
-		if (!$rsvp) {
187
-			return;
188
-		}
189
-
190
-		if (!isset($iTipMessage->message)) {
191
-			return;
192
-		}
193
-
194
-		$vcalendar = $iTipMessage->message;
195
-		if (!isset($vcalendar->VEVENT)) {
196
-			return;
197
-		}
198
-
199
-		/** @var Component $vevent */
200
-		$vevent = $vcalendar->VEVENT;
201
-
202
-		// We don't support autoresponses for recurrencing events for now
203
-		if (isset($vevent->RRULE) || isset($vevent->RDATE)) {
204
-			return;
205
-		}
206
-
207
-		$dtstart = $vevent->DTSTART;
208
-		$dtend =  $this->getDTEndFromVEvent($vevent);
209
-		$uid = $vevent->UID->getValue();
210
-		$sequence = isset($vevent->SEQUENCE) ? $vevent->SEQUENCE->getValue() : 0;
211
-		$recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->serialize() : '';
212
-
213
-		$message = <<<EOF
55
+    /**
56
+     * @var IConfig
57
+     */
58
+    private $config;
59
+
60
+    /** @var ITip\Message[] */
61
+    private $schedulingResponses = [];
62
+
63
+    /** @var string|null */
64
+    private $pathOfCalendarObjectChange = null;
65
+
66
+    public const CALENDAR_USER_TYPE = '{' . self::NS_CALDAV . '}calendar-user-type';
67
+    public const SCHEDULE_DEFAULT_CALENDAR_URL = '{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL';
68
+
69
+    /**
70
+     * @param IConfig $config
71
+     */
72
+    public function __construct(IConfig $config) {
73
+        $this->config = $config;
74
+    }
75
+
76
+    /**
77
+     * Initializes the plugin
78
+     *
79
+     * @param Server $server
80
+     * @return void
81
+     */
82
+    public function initialize(Server $server) {
83
+        parent::initialize($server);
84
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
85
+        $server->on('afterWriteContent', [$this, 'dispatchSchedulingResponses']);
86
+        $server->on('afterCreateFile', [$this, 'dispatchSchedulingResponses']);
87
+    }
88
+
89
+    /**
90
+     * This method handler is invoked during fetching of properties.
91
+     *
92
+     * We use this event to add calendar-auto-schedule-specific properties.
93
+     *
94
+     * @param PropFind $propFind
95
+     * @param INode $node
96
+     * @return void
97
+     */
98
+    public function propFind(PropFind $propFind, INode $node) {
99
+        if ($node instanceof IPrincipal) {
100
+            // overwrite Sabre/Dav's implementation
101
+            $propFind->handle(self::CALENDAR_USER_TYPE, function () use ($node) {
102
+                if ($node instanceof IProperties) {
103
+                    $props = $node->getProperties([self::CALENDAR_USER_TYPE]);
104
+
105
+                    if (isset($props[self::CALENDAR_USER_TYPE])) {
106
+                        return $props[self::CALENDAR_USER_TYPE];
107
+                    }
108
+                }
109
+
110
+                return 'INDIVIDUAL';
111
+            });
112
+        }
113
+
114
+        parent::propFind($propFind, $node);
115
+    }
116
+
117
+    /**
118
+     * Returns a list of addresses that are associated with a principal.
119
+     *
120
+     * @param string $principal
121
+     * @return array
122
+     */
123
+    protected function getAddressesForPrincipal($principal) {
124
+        $result = parent::getAddressesForPrincipal($principal);
125
+
126
+        if ($result === null) {
127
+            $result = [];
128
+        }
129
+
130
+        return $result;
131
+    }
132
+
133
+    /**
134
+     * @param RequestInterface $request
135
+     * @param ResponseInterface $response
136
+     * @param VCalendar $vCal
137
+     * @param mixed $calendarPath
138
+     * @param mixed $modified
139
+     * @param mixed $isNew
140
+     */
141
+    public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew) {
142
+        // Save the first path we get as a calendar-object-change request
143
+        if (!$this->pathOfCalendarObjectChange) {
144
+            $this->pathOfCalendarObjectChange = $request->getPath();
145
+        }
146
+
147
+        parent::calendarObjectChange($request, $response, $vCal, $calendarPath, $modified, $isNew);
148
+    }
149
+
150
+    /**
151
+     * @inheritDoc
152
+     */
153
+    public function scheduleLocalDelivery(ITip\Message $iTipMessage):void {
154
+        parent::scheduleLocalDelivery($iTipMessage);
155
+
156
+        // We only care when the message was successfully delivered locally
157
+        if ($iTipMessage->scheduleStatus !== '1.2;Message delivered locally') {
158
+            return;
159
+        }
160
+
161
+        // We only care about request. reply and cancel are properly handled
162
+        // by parent::scheduleLocalDelivery already
163
+        if (strcasecmp($iTipMessage->method, 'REQUEST') !== 0) {
164
+            return;
165
+        }
166
+
167
+        // If parent::scheduleLocalDelivery set scheduleStatus to 1.2,
168
+        // it means that it was successfully delivered locally.
169
+        // Meaning that the ACL plugin is loaded and that a principial
170
+        // exists for the given recipient id, no need to double check
171
+        /** @var \Sabre\DAVACL\Plugin $aclPlugin */
172
+        $aclPlugin = $this->server->getPlugin('acl');
173
+        $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
174
+        $calendarUserType = $this->getCalendarUserTypeForPrincipal($principalUri);
175
+        if (strcasecmp($calendarUserType, 'ROOM') !== 0 && strcasecmp($calendarUserType, 'RESOURCE') !== 0) {
176
+            return;
177
+        }
178
+
179
+        $attendee = $this->getCurrentAttendee($iTipMessage);
180
+        if (!$attendee) {
181
+            return;
182
+        }
183
+
184
+        // We only respond when a response was actually requested
185
+        $rsvp = $this->getAttendeeRSVP($attendee);
186
+        if (!$rsvp) {
187
+            return;
188
+        }
189
+
190
+        if (!isset($iTipMessage->message)) {
191
+            return;
192
+        }
193
+
194
+        $vcalendar = $iTipMessage->message;
195
+        if (!isset($vcalendar->VEVENT)) {
196
+            return;
197
+        }
198
+
199
+        /** @var Component $vevent */
200
+        $vevent = $vcalendar->VEVENT;
201
+
202
+        // We don't support autoresponses for recurrencing events for now
203
+        if (isset($vevent->RRULE) || isset($vevent->RDATE)) {
204
+            return;
205
+        }
206
+
207
+        $dtstart = $vevent->DTSTART;
208
+        $dtend =  $this->getDTEndFromVEvent($vevent);
209
+        $uid = $vevent->UID->getValue();
210
+        $sequence = isset($vevent->SEQUENCE) ? $vevent->SEQUENCE->getValue() : 0;
211
+        $recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->serialize() : '';
212
+
213
+        $message = <<<EOF
214 214
 BEGIN:VCALENDAR
215 215
 PRODID:-//Nextcloud/Nextcloud CalDAV Server//EN
216 216
 METHOD:REPLY
@@ -225,331 +225,331 @@  discard block
 block discarded – undo
225 225
 END:VCALENDAR
226 226
 EOF;
227 227
 
228
-		if ($this->isAvailableAtTime($attendee->getValue(), $dtstart->getDateTime(), $dtend->getDateTime(), $uid)) {
229
-			$partStat = 'ACCEPTED';
230
-		} else {
231
-			$partStat = 'DECLINED';
232
-		}
233
-
234
-		$vObject = Reader::read(vsprintf($message, [
235
-			$partStat,
236
-			$iTipMessage->recipient,
237
-			$iTipMessage->sender,
238
-			$uid,
239
-			$sequence,
240
-			$recurrenceId
241
-		]));
242
-
243
-		$responseITipMessage = new ITip\Message();
244
-		$responseITipMessage->uid = $uid;
245
-		$responseITipMessage->component = 'VEVENT';
246
-		$responseITipMessage->method = 'REPLY';
247
-		$responseITipMessage->sequence = $sequence;
248
-		$responseITipMessage->sender = $iTipMessage->recipient;
249
-		$responseITipMessage->recipient = $iTipMessage->sender;
250
-		$responseITipMessage->message = $vObject;
251
-
252
-		// We can't dispatch them now already, because the organizers calendar-object
253
-		// was not yet created. Hence Sabre/DAV won't find a calendar-object, when we
254
-		// send our reply.
255
-		$this->schedulingResponses[] = $responseITipMessage;
256
-	}
257
-
258
-	/**
259
-	 * @param string $uri
260
-	 */
261
-	public function dispatchSchedulingResponses(string $uri):void {
262
-		if ($uri !== $this->pathOfCalendarObjectChange) {
263
-			return;
264
-		}
265
-
266
-		foreach ($this->schedulingResponses as $schedulingResponse) {
267
-			$this->scheduleLocalDelivery($schedulingResponse);
268
-		}
269
-	}
270
-
271
-	/**
272
-	 * Always use the personal calendar as target for scheduled events
273
-	 *
274
-	 * @param PropFind $propFind
275
-	 * @param INode $node
276
-	 * @return void
277
-	 */
278
-	public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
279
-		if ($node instanceof IPrincipal) {
280
-			$propFind->handle(self::SCHEDULE_DEFAULT_CALENDAR_URL, function () use ($node) {
281
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
282
-				$caldavPlugin = $this->server->getPlugin('caldav');
283
-				$principalUrl = $node->getPrincipalUrl();
284
-
285
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
286
-				if (!$calendarHomePath) {
287
-					return null;
288
-				}
289
-
290
-				if (strpos($principalUrl, 'principals/users') === 0) {
291
-					list(, $userId) = split($principalUrl);
292
-					$uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
293
-					$displayName = CalDavBackend::PERSONAL_CALENDAR_NAME;
294
-				} elseif (strpos($principalUrl, 'principals/calendar-resources') === 0 ||
295
-						  strpos($principalUrl, 'principals/calendar-rooms') === 0) {
296
-					$uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI;
297
-					$displayName = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME;
298
-				} else {
299
-					// How did we end up here?
300
-					// TODO - throw exception or just ignore?
301
-					return null;
302
-				}
303
-
304
-				/** @var CalendarHome $calendarHome */
305
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
306
-				if (!$calendarHome->childExists($uri)) {
307
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
308
-						'{DAV:}displayname' => $displayName,
309
-					]);
310
-				}
311
-
312
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
313
-				if (empty($result)) {
314
-					return null;
315
-				}
316
-
317
-				return new LocalHref($result[0]['href']);
318
-			});
319
-		}
320
-	}
321
-
322
-	/**
323
-	 * Returns a list of addresses that are associated with a principal.
324
-	 *
325
-	 * @param string $principal
326
-	 * @return string?
327
-	 */
328
-	protected function getCalendarUserTypeForPrincipal($principal):?string {
329
-		$calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
330
-		$properties = $this->server->getProperties(
331
-			$principal,
332
-			[$calendarUserType]
333
-		);
334
-
335
-		// If we can't find this information, we'll stop processing
336
-		if (!isset($properties[$calendarUserType])) {
337
-			return null;
338
-		}
339
-
340
-		return $properties[$calendarUserType];
341
-	}
342
-
343
-	/**
344
-	 * @param ITip\Message $iTipMessage
345
-	 * @return null|Property
346
-	 */
347
-	private function getCurrentAttendee(ITip\Message $iTipMessage):?Property {
348
-		/** @var VEvent $vevent */
349
-		$vevent = $iTipMessage->message->VEVENT;
350
-		$attendees = $vevent->select('ATTENDEE');
351
-		foreach ($attendees as $attendee) {
352
-			/** @var Property $attendee */
353
-			if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
354
-				return $attendee;
355
-			}
356
-		}
357
-		return null;
358
-	}
359
-
360
-	/**
361
-	 * @param Property|null $attendee
362
-	 * @return bool
363
-	 */
364
-	private function getAttendeeRSVP(Property $attendee = null):bool {
365
-		if ($attendee !== null) {
366
-			$rsvp = $attendee->offsetGet('RSVP');
367
-			if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
368
-				return true;
369
-			}
370
-		}
371
-		// RFC 5545 3.2.17: default RSVP is false
372
-		return false;
373
-	}
374
-
375
-	/**
376
-	 * @param VEvent $vevent
377
-	 * @return Property\ICalendar\DateTime
378
-	 */
379
-	private function getDTEndFromVEvent(VEvent $vevent):Property\ICalendar\DateTime {
380
-		if (isset($vevent->DTEND)) {
381
-			return $vevent->DTEND;
382
-		}
383
-
384
-		if (isset($vevent->DURATION)) {
385
-			$isFloating = $vevent->DTSTART->isFloating();
386
-			/** @var Property\ICalendar\DateTime $end */
387
-			$end = clone $vevent->DTSTART;
388
-			$endDateTime = $end->getDateTime();
389
-			$endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
390
-			$end->setDateTime($endDateTime, $isFloating);
391
-			return $end;
392
-		}
393
-
394
-		if (!$vevent->DTSTART->hasTime()) {
395
-			$isFloating = $vevent->DTSTART->isFloating();
396
-			/** @var Property\ICalendar\DateTime $end */
397
-			$end = clone $vevent->DTSTART;
398
-			$endDateTime = $end->getDateTime();
399
-			$endDateTime = $endDateTime->modify('+1 day');
400
-			$end->setDateTime($endDateTime, $isFloating);
401
-			return $end;
402
-		}
403
-
404
-		return clone $vevent->DTSTART;
405
-	}
406
-
407
-	/**
408
-	 * @param string $email
409
-	 * @param \DateTimeInterface $start
410
-	 * @param \DateTimeInterface $end
411
-	 * @param string $ignoreUID
412
-	 * @return bool
413
-	 */
414
-	private function isAvailableAtTime(string $email, \DateTimeInterface $start, \DateTimeInterface $end, string $ignoreUID):bool {
415
-		// This method is heavily inspired by Sabre\CalDAV\Schedule\Plugin::scheduleLocalDelivery
416
-		// and Sabre\CalDAV\Schedule\Plugin::getFreeBusyForEmail
417
-
418
-		$aclPlugin = $this->server->getPlugin('acl');
419
-		$this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
420
-
421
-		$result = $aclPlugin->principalSearch(
422
-			['{http://sabredav.org/ns}email-address' => $this->stripOffMailTo($email)],
423
-			[
424
-				'{DAV:}principal-URL',
425
-				'{' . self::NS_CALDAV . '}calendar-home-set',
426
-				'{' . self::NS_CALDAV . '}schedule-inbox-URL',
427
-				'{http://sabredav.org/ns}email-address',
428
-
429
-			]
430
-		);
431
-		$this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
432
-
433
-
434
-		// Grabbing the calendar list
435
-		$objects = [];
436
-		$calendarTimeZone = new DateTimeZone('UTC');
437
-
438
-		$homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref();
439
-		foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) {
440
-			if (!$node instanceof ICalendar) {
441
-				continue;
442
-			}
443
-
444
-			// Getting the list of object uris within the time-range
445
-			$urls = $node->calendarQuery([
446
-				'name' => 'VCALENDAR',
447
-				'comp-filters' => [
448
-					[
449
-						'name' => 'VEVENT',
450
-						'is-not-defined' => false,
451
-						'time-range' => [
452
-							'start' => $start,
453
-							'end' => $end,
454
-						],
455
-						'comp-filters'   => [],
456
-						'prop-filters'   => [],
457
-					],
458
-					[
459
-						'name' => 'VEVENT',
460
-						'is-not-defined' => false,
461
-						'time-range' => null,
462
-						'comp-filters'   => [],
463
-						'prop-filters'   => [
464
-							[
465
-								'name'           => 'UID',
466
-								'is-not-defined' => false,
467
-								'time-range'     => null,
468
-								'text-match'     => [
469
-									'value' => $ignoreUID,
470
-									'negate-condition' => true,
471
-									'collation' => 'i;octet',
472
-								],
473
-								'param-filters' => [],
474
-							],
475
-						]
476
-					],
477
-				],
478
-				'prop-filters' => [],
479
-				'is-not-defined' => false,
480
-				'time-range' => null,
481
-			]);
482
-
483
-			foreach ($urls as $url) {
484
-				$objects[] = $node->getChild($url)->get();
485
-			}
486
-		}
487
-
488
-		$inboxProps = $this->server->getProperties(
489
-			$result[0][200]['{' . self::NS_CALDAV . '}schedule-inbox-URL']->getHref(),
490
-			['{' . self::NS_CALDAV . '}calendar-availability']
491
-		);
492
-
493
-		$vcalendar = new VCalendar();
494
-		$vcalendar->METHOD = 'REPLY';
495
-
496
-		$generator = new FreeBusyGenerator();
497
-		$generator->setObjects($objects);
498
-		$generator->setTimeRange($start, $end);
499
-		$generator->setBaseObject($vcalendar);
500
-		$generator->setTimeZone($calendarTimeZone);
501
-
502
-		if (isset($inboxProps['{' . self::NS_CALDAV . '}calendar-availability'])) {
503
-			$generator->setVAvailability(
504
-				Reader::read(
505
-					$inboxProps['{' . self::NS_CALDAV . '}calendar-availability']
506
-				)
507
-			);
508
-		}
509
-
510
-		$result = $generator->getResult();
511
-		if (!isset($result->VFREEBUSY)) {
512
-			return false;
513
-		}
514
-
515
-		/** @var Component $freeBusyComponent */
516
-		$freeBusyComponent = $result->VFREEBUSY;
517
-		$freeBusyProperties = $freeBusyComponent->select('FREEBUSY');
518
-		// If there is no Free-busy property at all, the time-range is empty and available
519
-		if (count($freeBusyProperties) === 0) {
520
-			return true;
521
-		}
522
-
523
-		// If more than one Free-Busy property was returned, it means that an event
524
-		// starts or ends inside this time-range, so it's not availabe and we return false
525
-		if (count($freeBusyProperties) > 1) {
526
-			return false;
527
-		}
528
-
529
-		/** @var Property $freeBusyProperty */
530
-		$freeBusyProperty = $freeBusyProperties[0];
531
-		if (!$freeBusyProperty->offsetExists('FBTYPE')) {
532
-			// If there is no FBTYPE, it means it's busy
533
-			return false;
534
-		}
535
-
536
-		$fbTypeParameter = $freeBusyProperty->offsetGet('FBTYPE');
537
-		if (!($fbTypeParameter instanceof Parameter)) {
538
-			return false;
539
-		}
540
-
541
-		return (strcasecmp($fbTypeParameter->getValue(), 'FREE') === 0);
542
-	}
543
-
544
-	/**
545
-	 * @param string $email
546
-	 * @return string
547
-	 */
548
-	private function stripOffMailTo(string $email): string {
549
-		if (stripos($email, 'mailto:')  === 0) {
550
-			return substr($email, 7);
551
-		}
552
-
553
-		return $email;
554
-	}
228
+        if ($this->isAvailableAtTime($attendee->getValue(), $dtstart->getDateTime(), $dtend->getDateTime(), $uid)) {
229
+            $partStat = 'ACCEPTED';
230
+        } else {
231
+            $partStat = 'DECLINED';
232
+        }
233
+
234
+        $vObject = Reader::read(vsprintf($message, [
235
+            $partStat,
236
+            $iTipMessage->recipient,
237
+            $iTipMessage->sender,
238
+            $uid,
239
+            $sequence,
240
+            $recurrenceId
241
+        ]));
242
+
243
+        $responseITipMessage = new ITip\Message();
244
+        $responseITipMessage->uid = $uid;
245
+        $responseITipMessage->component = 'VEVENT';
246
+        $responseITipMessage->method = 'REPLY';
247
+        $responseITipMessage->sequence = $sequence;
248
+        $responseITipMessage->sender = $iTipMessage->recipient;
249
+        $responseITipMessage->recipient = $iTipMessage->sender;
250
+        $responseITipMessage->message = $vObject;
251
+
252
+        // We can't dispatch them now already, because the organizers calendar-object
253
+        // was not yet created. Hence Sabre/DAV won't find a calendar-object, when we
254
+        // send our reply.
255
+        $this->schedulingResponses[] = $responseITipMessage;
256
+    }
257
+
258
+    /**
259
+     * @param string $uri
260
+     */
261
+    public function dispatchSchedulingResponses(string $uri):void {
262
+        if ($uri !== $this->pathOfCalendarObjectChange) {
263
+            return;
264
+        }
265
+
266
+        foreach ($this->schedulingResponses as $schedulingResponse) {
267
+            $this->scheduleLocalDelivery($schedulingResponse);
268
+        }
269
+    }
270
+
271
+    /**
272
+     * Always use the personal calendar as target for scheduled events
273
+     *
274
+     * @param PropFind $propFind
275
+     * @param INode $node
276
+     * @return void
277
+     */
278
+    public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
279
+        if ($node instanceof IPrincipal) {
280
+            $propFind->handle(self::SCHEDULE_DEFAULT_CALENDAR_URL, function () use ($node) {
281
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
282
+                $caldavPlugin = $this->server->getPlugin('caldav');
283
+                $principalUrl = $node->getPrincipalUrl();
284
+
285
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
286
+                if (!$calendarHomePath) {
287
+                    return null;
288
+                }
289
+
290
+                if (strpos($principalUrl, 'principals/users') === 0) {
291
+                    list(, $userId) = split($principalUrl);
292
+                    $uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
293
+                    $displayName = CalDavBackend::PERSONAL_CALENDAR_NAME;
294
+                } elseif (strpos($principalUrl, 'principals/calendar-resources') === 0 ||
295
+                          strpos($principalUrl, 'principals/calendar-rooms') === 0) {
296
+                    $uri = CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI;
297
+                    $displayName = CalDavBackend::RESOURCE_BOOKING_CALENDAR_NAME;
298
+                } else {
299
+                    // How did we end up here?
300
+                    // TODO - throw exception or just ignore?
301
+                    return null;
302
+                }
303
+
304
+                /** @var CalendarHome $calendarHome */
305
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
306
+                if (!$calendarHome->childExists($uri)) {
307
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, $uri, [
308
+                        '{DAV:}displayname' => $displayName,
309
+                    ]);
310
+                }
311
+
312
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
313
+                if (empty($result)) {
314
+                    return null;
315
+                }
316
+
317
+                return new LocalHref($result[0]['href']);
318
+            });
319
+        }
320
+    }
321
+
322
+    /**
323
+     * Returns a list of addresses that are associated with a principal.
324
+     *
325
+     * @param string $principal
326
+     * @return string?
327
+     */
328
+    protected function getCalendarUserTypeForPrincipal($principal):?string {
329
+        $calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
330
+        $properties = $this->server->getProperties(
331
+            $principal,
332
+            [$calendarUserType]
333
+        );
334
+
335
+        // If we can't find this information, we'll stop processing
336
+        if (!isset($properties[$calendarUserType])) {
337
+            return null;
338
+        }
339
+
340
+        return $properties[$calendarUserType];
341
+    }
342
+
343
+    /**
344
+     * @param ITip\Message $iTipMessage
345
+     * @return null|Property
346
+     */
347
+    private function getCurrentAttendee(ITip\Message $iTipMessage):?Property {
348
+        /** @var VEvent $vevent */
349
+        $vevent = $iTipMessage->message->VEVENT;
350
+        $attendees = $vevent->select('ATTENDEE');
351
+        foreach ($attendees as $attendee) {
352
+            /** @var Property $attendee */
353
+            if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
354
+                return $attendee;
355
+            }
356
+        }
357
+        return null;
358
+    }
359
+
360
+    /**
361
+     * @param Property|null $attendee
362
+     * @return bool
363
+     */
364
+    private function getAttendeeRSVP(Property $attendee = null):bool {
365
+        if ($attendee !== null) {
366
+            $rsvp = $attendee->offsetGet('RSVP');
367
+            if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
368
+                return true;
369
+            }
370
+        }
371
+        // RFC 5545 3.2.17: default RSVP is false
372
+        return false;
373
+    }
374
+
375
+    /**
376
+     * @param VEvent $vevent
377
+     * @return Property\ICalendar\DateTime
378
+     */
379
+    private function getDTEndFromVEvent(VEvent $vevent):Property\ICalendar\DateTime {
380
+        if (isset($vevent->DTEND)) {
381
+            return $vevent->DTEND;
382
+        }
383
+
384
+        if (isset($vevent->DURATION)) {
385
+            $isFloating = $vevent->DTSTART->isFloating();
386
+            /** @var Property\ICalendar\DateTime $end */
387
+            $end = clone $vevent->DTSTART;
388
+            $endDateTime = $end->getDateTime();
389
+            $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
390
+            $end->setDateTime($endDateTime, $isFloating);
391
+            return $end;
392
+        }
393
+
394
+        if (!$vevent->DTSTART->hasTime()) {
395
+            $isFloating = $vevent->DTSTART->isFloating();
396
+            /** @var Property\ICalendar\DateTime $end */
397
+            $end = clone $vevent->DTSTART;
398
+            $endDateTime = $end->getDateTime();
399
+            $endDateTime = $endDateTime->modify('+1 day');
400
+            $end->setDateTime($endDateTime, $isFloating);
401
+            return $end;
402
+        }
403
+
404
+        return clone $vevent->DTSTART;
405
+    }
406
+
407
+    /**
408
+     * @param string $email
409
+     * @param \DateTimeInterface $start
410
+     * @param \DateTimeInterface $end
411
+     * @param string $ignoreUID
412
+     * @return bool
413
+     */
414
+    private function isAvailableAtTime(string $email, \DateTimeInterface $start, \DateTimeInterface $end, string $ignoreUID):bool {
415
+        // This method is heavily inspired by Sabre\CalDAV\Schedule\Plugin::scheduleLocalDelivery
416
+        // and Sabre\CalDAV\Schedule\Plugin::getFreeBusyForEmail
417
+
418
+        $aclPlugin = $this->server->getPlugin('acl');
419
+        $this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
420
+
421
+        $result = $aclPlugin->principalSearch(
422
+            ['{http://sabredav.org/ns}email-address' => $this->stripOffMailTo($email)],
423
+            [
424
+                '{DAV:}principal-URL',
425
+                '{' . self::NS_CALDAV . '}calendar-home-set',
426
+                '{' . self::NS_CALDAV . '}schedule-inbox-URL',
427
+                '{http://sabredav.org/ns}email-address',
428
+
429
+            ]
430
+        );
431
+        $this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
432
+
433
+
434
+        // Grabbing the calendar list
435
+        $objects = [];
436
+        $calendarTimeZone = new DateTimeZone('UTC');
437
+
438
+        $homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref();
439
+        foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) {
440
+            if (!$node instanceof ICalendar) {
441
+                continue;
442
+            }
443
+
444
+            // Getting the list of object uris within the time-range
445
+            $urls = $node->calendarQuery([
446
+                'name' => 'VCALENDAR',
447
+                'comp-filters' => [
448
+                    [
449
+                        'name' => 'VEVENT',
450
+                        'is-not-defined' => false,
451
+                        'time-range' => [
452
+                            'start' => $start,
453
+                            'end' => $end,
454
+                        ],
455
+                        'comp-filters'   => [],
456
+                        'prop-filters'   => [],
457
+                    ],
458
+                    [
459
+                        'name' => 'VEVENT',
460
+                        'is-not-defined' => false,
461
+                        'time-range' => null,
462
+                        'comp-filters'   => [],
463
+                        'prop-filters'   => [
464
+                            [
465
+                                'name'           => 'UID',
466
+                                'is-not-defined' => false,
467
+                                'time-range'     => null,
468
+                                'text-match'     => [
469
+                                    'value' => $ignoreUID,
470
+                                    'negate-condition' => true,
471
+                                    'collation' => 'i;octet',
472
+                                ],
473
+                                'param-filters' => [],
474
+                            ],
475
+                        ]
476
+                    ],
477
+                ],
478
+                'prop-filters' => [],
479
+                'is-not-defined' => false,
480
+                'time-range' => null,
481
+            ]);
482
+
483
+            foreach ($urls as $url) {
484
+                $objects[] = $node->getChild($url)->get();
485
+            }
486
+        }
487
+
488
+        $inboxProps = $this->server->getProperties(
489
+            $result[0][200]['{' . self::NS_CALDAV . '}schedule-inbox-URL']->getHref(),
490
+            ['{' . self::NS_CALDAV . '}calendar-availability']
491
+        );
492
+
493
+        $vcalendar = new VCalendar();
494
+        $vcalendar->METHOD = 'REPLY';
495
+
496
+        $generator = new FreeBusyGenerator();
497
+        $generator->setObjects($objects);
498
+        $generator->setTimeRange($start, $end);
499
+        $generator->setBaseObject($vcalendar);
500
+        $generator->setTimeZone($calendarTimeZone);
501
+
502
+        if (isset($inboxProps['{' . self::NS_CALDAV . '}calendar-availability'])) {
503
+            $generator->setVAvailability(
504
+                Reader::read(
505
+                    $inboxProps['{' . self::NS_CALDAV . '}calendar-availability']
506
+                )
507
+            );
508
+        }
509
+
510
+        $result = $generator->getResult();
511
+        if (!isset($result->VFREEBUSY)) {
512
+            return false;
513
+        }
514
+
515
+        /** @var Component $freeBusyComponent */
516
+        $freeBusyComponent = $result->VFREEBUSY;
517
+        $freeBusyProperties = $freeBusyComponent->select('FREEBUSY');
518
+        // If there is no Free-busy property at all, the time-range is empty and available
519
+        if (count($freeBusyProperties) === 0) {
520
+            return true;
521
+        }
522
+
523
+        // If more than one Free-Busy property was returned, it means that an event
524
+        // starts or ends inside this time-range, so it's not availabe and we return false
525
+        if (count($freeBusyProperties) > 1) {
526
+            return false;
527
+        }
528
+
529
+        /** @var Property $freeBusyProperty */
530
+        $freeBusyProperty = $freeBusyProperties[0];
531
+        if (!$freeBusyProperty->offsetExists('FBTYPE')) {
532
+            // If there is no FBTYPE, it means it's busy
533
+            return false;
534
+        }
535
+
536
+        $fbTypeParameter = $freeBusyProperty->offsetGet('FBTYPE');
537
+        if (!($fbTypeParameter instanceof Parameter)) {
538
+            return false;
539
+        }
540
+
541
+        return (strcasecmp($fbTypeParameter->getValue(), 'FREE') === 0);
542
+    }
543
+
544
+    /**
545
+     * @param string $email
546
+     * @return string
547
+     */
548
+    private function stripOffMailTo(string $email): string {
549
+        if (stripos($email, 'mailto:')  === 0) {
550
+            return substr($email, 7);
551
+        }
552
+
553
+        return $email;
554
+    }
555 555
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	/** @var string|null */
64 64
 	private $pathOfCalendarObjectChange = null;
65 65
 
66
-	public const CALENDAR_USER_TYPE = '{' . self::NS_CALDAV . '}calendar-user-type';
67
-	public const SCHEDULE_DEFAULT_CALENDAR_URL = '{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL';
66
+	public const CALENDAR_USER_TYPE = '{'.self::NS_CALDAV.'}calendar-user-type';
67
+	public const SCHEDULE_DEFAULT_CALENDAR_URL = '{'.Plugin::NS_CALDAV.'}schedule-default-calendar-URL';
68 68
 
69 69
 	/**
70 70
 	 * @param IConfig $config
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	public function propFind(PropFind $propFind, INode $node) {
99 99
 		if ($node instanceof IPrincipal) {
100 100
 			// overwrite Sabre/Dav's implementation
101
-			$propFind->handle(self::CALENDAR_USER_TYPE, function () use ($node) {
101
+			$propFind->handle(self::CALENDAR_USER_TYPE, function() use ($node) {
102 102
 				if ($node instanceof IProperties) {
103 103
 					$props = $node->getProperties([self::CALENDAR_USER_TYPE]);
104 104
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 		}
206 206
 
207 207
 		$dtstart = $vevent->DTSTART;
208
-		$dtend =  $this->getDTEndFromVEvent($vevent);
208
+		$dtend = $this->getDTEndFromVEvent($vevent);
209 209
 		$uid = $vevent->UID->getValue();
210 210
 		$sequence = isset($vevent->SEQUENCE) ? $vevent->SEQUENCE->getValue() : 0;
211 211
 		$recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ? $vevent->{'RECURRENCE-ID'}->serialize() : '';
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 */
278 278
 	public function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
279 279
 		if ($node instanceof IPrincipal) {
280
-			$propFind->handle(self::SCHEDULE_DEFAULT_CALENDAR_URL, function () use ($node) {
280
+			$propFind->handle(self::SCHEDULE_DEFAULT_CALENDAR_URL, function() use ($node) {
281 281
 				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
282 282
 				$caldavPlugin = $this->server->getPlugin('caldav');
283 283
 				$principalUrl = $node->getPrincipalUrl();
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 					]);
310 310
 				}
311 311
 
312
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . $uri, [], 1);
312
+				$result = $this->server->getPropertiesForPath($calendarHomePath.'/'.$uri, [], 1);
313 313
 				if (empty($result)) {
314 314
 					return null;
315 315
 				}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	 * @param string $principal
326 326
 	 * @return string?
327 327
 	 */
328
-	protected function getCalendarUserTypeForPrincipal($principal):?string {
329
-		$calendarUserType = '{' . self::NS_CALDAV . '}calendar-user-type';
328
+	protected function getCalendarUserTypeForPrincipal($principal): ?string {
329
+		$calendarUserType = '{'.self::NS_CALDAV.'}calendar-user-type';
330 330
 		$properties = $this->server->getProperties(
331 331
 			$principal,
332 332
 			[$calendarUserType]
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 * @param ITip\Message $iTipMessage
345 345
 	 * @return null|Property
346 346
 	 */
347
-	private function getCurrentAttendee(ITip\Message $iTipMessage):?Property {
347
+	private function getCurrentAttendee(ITip\Message $iTipMessage): ?Property {
348 348
 		/** @var VEvent $vevent */
349 349
 		$vevent = $iTipMessage->message->VEVENT;
350 350
 		$attendees = $vevent->select('ATTENDEE');
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 			['{http://sabredav.org/ns}email-address' => $this->stripOffMailTo($email)],
423 423
 			[
424 424
 				'{DAV:}principal-URL',
425
-				'{' . self::NS_CALDAV . '}calendar-home-set',
426
-				'{' . self::NS_CALDAV . '}schedule-inbox-URL',
425
+				'{'.self::NS_CALDAV.'}calendar-home-set',
426
+				'{'.self::NS_CALDAV.'}schedule-inbox-URL',
427 427
 				'{http://sabredav.org/ns}email-address',
428 428
 
429 429
 			]
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 		$objects = [];
436 436
 		$calendarTimeZone = new DateTimeZone('UTC');
437 437
 
438
-		$homePath = $result[0][200]['{' . self::NS_CALDAV . '}calendar-home-set']->getHref();
438
+		$homePath = $result[0][200]['{'.self::NS_CALDAV.'}calendar-home-set']->getHref();
439 439
 		foreach ($this->server->tree->getNodeForPath($homePath)->getChildren() as $node) {
440 440
 			if (!$node instanceof ICalendar) {
441 441
 				continue;
@@ -486,8 +486,8 @@  discard block
 block discarded – undo
486 486
 		}
487 487
 
488 488
 		$inboxProps = $this->server->getProperties(
489
-			$result[0][200]['{' . self::NS_CALDAV . '}schedule-inbox-URL']->getHref(),
490
-			['{' . self::NS_CALDAV . '}calendar-availability']
489
+			$result[0][200]['{'.self::NS_CALDAV.'}schedule-inbox-URL']->getHref(),
490
+			['{'.self::NS_CALDAV.'}calendar-availability']
491 491
 		);
492 492
 
493 493
 		$vcalendar = new VCalendar();
@@ -499,10 +499,10 @@  discard block
 block discarded – undo
499 499
 		$generator->setBaseObject($vcalendar);
500 500
 		$generator->setTimeZone($calendarTimeZone);
501 501
 
502
-		if (isset($inboxProps['{' . self::NS_CALDAV . '}calendar-availability'])) {
502
+		if (isset($inboxProps['{'.self::NS_CALDAV.'}calendar-availability'])) {
503 503
 			$generator->setVAvailability(
504 504
 				Reader::read(
505
-					$inboxProps['{' . self::NS_CALDAV . '}calendar-availability']
505
+					$inboxProps['{'.self::NS_CALDAV.'}calendar-availability']
506 506
 				)
507 507
 			);
508 508
 		}
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 	 * @return string
547 547
 	 */
548 548
 	private function stripOffMailTo(string $email): string {
549
-		if (stripos($email, 'mailto:')  === 0) {
549
+		if (stripos($email, 'mailto:') === 0) {
550 550
 			return substr($email, 7);
551 551
 		}
552 552
 
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -36,86 +36,86 @@
 block discarded – undo
36 36
 
37 37
 class InvitationResponseServer {
38 38
 
39
-	/** @var \OCA\DAV\Connector\Sabre\Server */
40
-	public $server;
39
+    /** @var \OCA\DAV\Connector\Sabre\Server */
40
+    public $server;
41 41
 
42
-	/**
43
-	 * InvitationResponseServer constructor.
44
-	 */
45
-	public function __construct() {
46
-		$baseUri = \OC::$WEBROOT . '/remote.php/dav/';
47
-		$logger = \OC::$server->getLogger();
48
-		$dispatcher = \OC::$server->getEventDispatcher();
42
+    /**
43
+     * InvitationResponseServer constructor.
44
+     */
45
+    public function __construct() {
46
+        $baseUri = \OC::$WEBROOT . '/remote.php/dav/';
47
+        $logger = \OC::$server->getLogger();
48
+        $dispatcher = \OC::$server->getEventDispatcher();
49 49
 
50
-		$root = new RootCollection();
51
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
50
+        $root = new RootCollection();
51
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
52 52
 
53
-		// Add maintenance plugin
54
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
53
+        // Add maintenance plugin
54
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
55 55
 
56
-		// Set URL explicitly due to reverse-proxy situations
57
-		$this->server->httpRequest->setUrl($baseUri);
58
-		$this->server->setBaseUri($baseUri);
56
+        // Set URL explicitly due to reverse-proxy situations
57
+        $this->server->httpRequest->setUrl($baseUri);
58
+        $this->server->setBaseUri($baseUri);
59 59
 
60
-		$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
61
-		$this->server->addPlugin(new AnonymousOptionsPlugin());
62
-		$this->server->addPlugin(new class() extends Plugin {
63
-			public function getCurrentPrincipal() {
64
-				return 'principals/system/public';
65
-			}
66
-		});
60
+        $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
61
+        $this->server->addPlugin(new AnonymousOptionsPlugin());
62
+        $this->server->addPlugin(new class() extends Plugin {
63
+            public function getCurrentPrincipal() {
64
+                return 'principals/system/public';
65
+            }
66
+        });
67 67
 
68
-		// allow setup of additional auth backends
69
-		$event = new SabrePluginEvent($this->server);
70
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
68
+        // allow setup of additional auth backends
69
+        $event = new SabrePluginEvent($this->server);
70
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
71 71
 
72
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
73
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
74
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
72
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
73
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
74
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
75 75
 
76
-		// acl
77
-		$acl = new DavAclPlugin();
78
-		$acl->principalCollectionSet = [
79
-			'principals/users', 'principals/groups'
80
-		];
81
-		$acl->defaultUsernamePath = 'principals/users';
82
-		$this->server->addPlugin($acl);
76
+        // acl
77
+        $acl = new DavAclPlugin();
78
+        $acl->principalCollectionSet = [
79
+            'principals/users', 'principals/groups'
80
+        ];
81
+        $acl->defaultUsernamePath = 'principals/users';
82
+        $this->server->addPlugin($acl);
83 83
 
84
-		// calendar plugins
85
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
86
-		$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
87
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
88
-		$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
89
-		$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
90
-		//$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
91
-		$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
92
-			\OC::$server->getConfig(),
93
-			\OC::$server->getURLGenerator()
94
-		));
84
+        // calendar plugins
85
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
86
+        $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
87
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
88
+        $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
89
+        $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
90
+        //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
91
+        $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
92
+            \OC::$server->getConfig(),
93
+            \OC::$server->getURLGenerator()
94
+        ));
95 95
 
96
-		// wait with registering these until auth is handled and the filesystem is setup
97
-		$this->server->on('beforeMethod:*', function () use ($root) {
98
-			// register plugins from apps
99
-			$pluginManager = new PluginManager(
100
-				\OC::$server,
101
-				\OC::$server->getAppManager()
102
-			);
103
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
104
-				$this->server->addPlugin($appPlugin);
105
-			}
106
-			foreach ($pluginManager->getAppCollections() as $appCollection) {
107
-				$root->addChild($appCollection);
108
-			}
109
-		});
110
-	}
96
+        // wait with registering these until auth is handled and the filesystem is setup
97
+        $this->server->on('beforeMethod:*', function () use ($root) {
98
+            // register plugins from apps
99
+            $pluginManager = new PluginManager(
100
+                \OC::$server,
101
+                \OC::$server->getAppManager()
102
+            );
103
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
104
+                $this->server->addPlugin($appPlugin);
105
+            }
106
+            foreach ($pluginManager->getAppCollections() as $appCollection) {
107
+                $root->addChild($appCollection);
108
+            }
109
+        });
110
+    }
111 111
 
112
-	/**
113
-	 * @param Message $iTipMessage
114
-	 * @return void
115
-	 */
116
-	public function handleITipMessage(Message $iTipMessage) {
117
-		/** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */
118
-		$schedulingPlugin = $this->server->getPlugin('caldav-schedule');
119
-		$schedulingPlugin->scheduleLocalDelivery($iTipMessage);
120
-	}
112
+    /**
113
+     * @param Message $iTipMessage
114
+     * @return void
115
+     */
116
+    public function handleITipMessage(Message $iTipMessage) {
117
+        /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */
118
+        $schedulingPlugin = $this->server->getPlugin('caldav-schedule');
119
+        $schedulingPlugin->scheduleLocalDelivery($iTipMessage);
120
+    }
121 121
 }
Please login to merge, or discard this patch.
apps/dav/lib/Server.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -72,260 +72,260 @@
 block discarded – undo
72 72
 
73 73
 class Server {
74 74
 
75
-	/** @var IRequest */
76
-	private $request;
77
-
78
-	/** @var  string */
79
-	private $baseUri;
80
-
81
-	/** @var Connector\Sabre\Server  */
82
-	public $server;
83
-
84
-	public function __construct(IRequest $request, $baseUri) {
85
-		$this->request = $request;
86
-		$this->baseUri = $baseUri;
87
-		$logger = \OC::$server->getLogger();
88
-		$dispatcher = \OC::$server->getEventDispatcher();
89
-
90
-		$root = new RootCollection();
91
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
92
-
93
-		// Add maintenance plugin
94
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
95
-
96
-		// Backends
97
-		$authBackend = new Auth(
98
-			\OC::$server->getSession(),
99
-			\OC::$server->getUserSession(),
100
-			\OC::$server->getRequest(),
101
-			\OC::$server->getTwoFactorAuthManager(),
102
-			\OC::$server->getBruteForceThrottler()
103
-		);
104
-
105
-		// Set URL explicitly due to reverse-proxy situations
106
-		$this->server->httpRequest->setUrl($this->request->getRequestUri());
107
-		$this->server->setBaseUri($this->baseUri);
108
-
109
-		$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
110
-		$this->server->addPlugin(new AnonymousOptionsPlugin());
111
-		$authPlugin = new Plugin();
112
-		$authPlugin->addBackend(new PublicAuth());
113
-		$this->server->addPlugin($authPlugin);
114
-
115
-		// allow setup of additional auth backends
116
-		$event = new SabrePluginEvent($this->server);
117
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
118
-
119
-		$bearerAuthBackend = new BearerAuth(
120
-			\OC::$server->getUserSession(),
121
-			\OC::$server->getSession(),
122
-			\OC::$server->getRequest()
123
-		);
124
-		$authPlugin->addBackend($bearerAuthBackend);
125
-		// because we are throwing exceptions this plugin has to be the last one
126
-		$authPlugin->addBackend($authBackend);
127
-
128
-		// debugging
129
-		if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
130
-			$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
131
-		} else {
132
-			$this->server->addPlugin(new DummyGetResponsePlugin());
133
-		}
134
-
135
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
136
-		$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
137
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
138
-
139
-		// acl
140
-		$acl = new DavAclPlugin();
141
-		$acl->principalCollectionSet = [
142
-			'principals/users',
143
-			'principals/groups',
144
-			'principals/calendar-resources',
145
-			'principals/calendar-rooms',
146
-		];
147
-		$acl->defaultUsernamePath = 'principals/users';
148
-		$this->server->addPlugin($acl);
149
-
150
-		// calendar plugins
151
-		if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
152
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
153
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger()));
154
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
155
-			if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
156
-				$this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
157
-			}
158
-
159
-			$this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request));
160
-			$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
161
-
162
-			$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
163
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
164
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
165
-				\OC::$server->getConfig(),
166
-				\OC::$server->getURLGenerator()
167
-			));
168
-		}
169
-
170
-		// addressbook plugins
171
-		if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
172
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
173
-			$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
174
-			$this->server->addPlugin(new VCFExportPlugin());
175
-			$this->server->addPlugin(new MultiGetExportPlugin());
176
-			$this->server->addPlugin(new HasPhotoPlugin());
177
-			$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
178
-				\OC::$server->getAppDataDir('dav-photocache'),
179
-				\OC::$server->getLogger())
180
-			));
181
-		}
182
-
183
-		// system tags plugins
184
-		$this->server->addPlugin(new SystemTagPlugin(
185
-			\OC::$server->getSystemTagManager(),
186
-			\OC::$server->getGroupManager(),
187
-			\OC::$server->getUserSession()
188
-		));
189
-
190
-		// comments plugin
191
-		$this->server->addPlugin(new CommentsPlugin(
192
-			\OC::$server->getCommentsManager(),
193
-			\OC::$server->getUserSession()
194
-		));
195
-
196
-		$this->server->addPlugin(new CopyEtagHeaderPlugin());
197
-		$this->server->addPlugin(new ChunkingPlugin());
198
-
199
-		// allow setup of additional plugins
200
-		$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
201
-
202
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
203
-		// we do not provide locking we emulate it using a fake locking plugin.
204
-		if ($request->isUserAgent([
205
-			'/WebDAVFS/',
206
-			'/OneNote/',
207
-			'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
208
-		])) {
209
-			$this->server->addPlugin(new FakeLockerPlugin());
210
-		}
211
-
212
-		if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
213
-			$this->server->addPlugin(new BrowserErrorPagePlugin());
214
-		}
215
-
216
-		$lazySearchBackend = new LazySearchBackend();
217
-		$this->server->addPlugin(new SearchPlugin($lazySearchBackend));
218
-
219
-		// wait with registering these until auth is handled and the filesystem is setup
220
-		$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) {
221
-			// custom properties plugin must be the last one
222
-			$userSession = \OC::$server->getUserSession();
223
-			$user = $userSession->getUser();
224
-			if ($user !== null) {
225
-				$view = \OC\Files\Filesystem::getView();
226
-				$this->server->addPlugin(
227
-					new FilesPlugin(
228
-						$this->server->tree,
229
-						\OC::$server->getConfig(),
230
-						$this->request,
231
-						\OC::$server->getPreviewManager(),
232
-						false,
233
-						!\OC::$server->getConfig()->getSystemValue('debug', false)
234
-					)
235
-				);
236
-
237
-				$this->server->addPlugin(
238
-					new \Sabre\DAV\PropertyStorage\Plugin(
239
-						new CustomPropertiesBackend(
240
-							$this->server->tree,
241
-							\OC::$server->getDatabaseConnection(),
242
-							\OC::$server->getUserSession()->getUser()
243
-						)
244
-					)
245
-				);
246
-				if ($view !== null) {
247
-					$this->server->addPlugin(
248
-						new QuotaPlugin($view, false));
249
-				}
250
-				$this->server->addPlugin(
251
-					new TagsPlugin(
252
-						$this->server->tree, \OC::$server->getTagManager()
253
-					)
254
-				);
255
-				// TODO: switch to LazyUserFolder
256
-				$userFolder = \OC::$server->getUserFolder();
257
-				$this->server->addPlugin(new SharesPlugin(
258
-					$this->server->tree,
259
-					$userSession,
260
-					$userFolder,
261
-					\OC::$server->getShareManager()
262
-				));
263
-				$this->server->addPlugin(new CommentPropertiesPlugin(
264
-					\OC::$server->getCommentsManager(),
265
-					$userSession
266
-				));
267
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
268
-				if ($view !== null) {
269
-					$this->server->addPlugin(new FilesReportPlugin(
270
-						$this->server->tree,
271
-						$view,
272
-						\OC::$server->getSystemTagManager(),
273
-						\OC::$server->getSystemTagObjectMapper(),
274
-						\OC::$server->getTagManager(),
275
-						$userSession,
276
-						\OC::$server->getGroupManager(),
277
-						$userFolder,
278
-						\OC::$server->getAppManager()
279
-					));
280
-					$lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend(
281
-						$this->server->tree,
282
-						$user,
283
-						\OC::$server->getRootFolder(),
284
-						\OC::$server->getShareManager(),
285
-						$view
286
-					));
287
-				}
288
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
289
-					\OC::$server->getConfig(),
290
-					\OC::$server->query(BirthdayService::class)
291
-				));
292
-				$this->server->addPlugin(new AppleProvisioningPlugin(
293
-					\OC::$server->getUserSession(),
294
-					\OC::$server->getURLGenerator(),
295
-					\OC::$server->getThemingDefaults(),
296
-					\OC::$server->getRequest(),
297
-					\OC::$server->getL10N('dav'),
298
-					function () {
299
-						return UUIDUtil::getUUID();
300
-					}
301
-				));
302
-			}
303
-
304
-			// register plugins from apps
305
-			$pluginManager = new PluginManager(
306
-				\OC::$server,
307
-				\OC::$server->getAppManager()
308
-			);
309
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
310
-				$this->server->addPlugin($appPlugin);
311
-			}
312
-			foreach ($pluginManager->getAppCollections() as $appCollection) {
313
-				$root->addChild($appCollection);
314
-			}
315
-		});
316
-	}
317
-
318
-	public function exec() {
319
-		$this->server->exec();
320
-	}
321
-
322
-	private function requestIsForSubtree(array $subTrees): bool {
323
-		foreach ($subTrees as $subTree) {
324
-			$subTree = trim($subTree, ' /');
325
-			if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
326
-				return true;
327
-			}
328
-		}
329
-		return false;
330
-	}
75
+    /** @var IRequest */
76
+    private $request;
77
+
78
+    /** @var  string */
79
+    private $baseUri;
80
+
81
+    /** @var Connector\Sabre\Server  */
82
+    public $server;
83
+
84
+    public function __construct(IRequest $request, $baseUri) {
85
+        $this->request = $request;
86
+        $this->baseUri = $baseUri;
87
+        $logger = \OC::$server->getLogger();
88
+        $dispatcher = \OC::$server->getEventDispatcher();
89
+
90
+        $root = new RootCollection();
91
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
92
+
93
+        // Add maintenance plugin
94
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
95
+
96
+        // Backends
97
+        $authBackend = new Auth(
98
+            \OC::$server->getSession(),
99
+            \OC::$server->getUserSession(),
100
+            \OC::$server->getRequest(),
101
+            \OC::$server->getTwoFactorAuthManager(),
102
+            \OC::$server->getBruteForceThrottler()
103
+        );
104
+
105
+        // Set URL explicitly due to reverse-proxy situations
106
+        $this->server->httpRequest->setUrl($this->request->getRequestUri());
107
+        $this->server->setBaseUri($this->baseUri);
108
+
109
+        $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
110
+        $this->server->addPlugin(new AnonymousOptionsPlugin());
111
+        $authPlugin = new Plugin();
112
+        $authPlugin->addBackend(new PublicAuth());
113
+        $this->server->addPlugin($authPlugin);
114
+
115
+        // allow setup of additional auth backends
116
+        $event = new SabrePluginEvent($this->server);
117
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
118
+
119
+        $bearerAuthBackend = new BearerAuth(
120
+            \OC::$server->getUserSession(),
121
+            \OC::$server->getSession(),
122
+            \OC::$server->getRequest()
123
+        );
124
+        $authPlugin->addBackend($bearerAuthBackend);
125
+        // because we are throwing exceptions this plugin has to be the last one
126
+        $authPlugin->addBackend($authBackend);
127
+
128
+        // debugging
129
+        if (\OC::$server->getConfig()->getSystemValue('debug', false)) {
130
+            $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
131
+        } else {
132
+            $this->server->addPlugin(new DummyGetResponsePlugin());
133
+        }
134
+
135
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
136
+        $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
137
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
138
+
139
+        // acl
140
+        $acl = new DavAclPlugin();
141
+        $acl->principalCollectionSet = [
142
+            'principals/users',
143
+            'principals/groups',
144
+            'principals/calendar-resources',
145
+            'principals/calendar-rooms',
146
+        ];
147
+        $acl->defaultUsernamePath = 'principals/users';
148
+        $this->server->addPlugin($acl);
149
+
150
+        // calendar plugins
151
+        if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
152
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
153
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger()));
154
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
155
+            if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
156
+                $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
157
+            }
158
+
159
+            $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request));
160
+            $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
161
+
162
+            $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
163
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
164
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
165
+                \OC::$server->getConfig(),
166
+                \OC::$server->getURLGenerator()
167
+            ));
168
+        }
169
+
170
+        // addressbook plugins
171
+        if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
172
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
173
+            $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
174
+            $this->server->addPlugin(new VCFExportPlugin());
175
+            $this->server->addPlugin(new MultiGetExportPlugin());
176
+            $this->server->addPlugin(new HasPhotoPlugin());
177
+            $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
178
+                \OC::$server->getAppDataDir('dav-photocache'),
179
+                \OC::$server->getLogger())
180
+            ));
181
+        }
182
+
183
+        // system tags plugins
184
+        $this->server->addPlugin(new SystemTagPlugin(
185
+            \OC::$server->getSystemTagManager(),
186
+            \OC::$server->getGroupManager(),
187
+            \OC::$server->getUserSession()
188
+        ));
189
+
190
+        // comments plugin
191
+        $this->server->addPlugin(new CommentsPlugin(
192
+            \OC::$server->getCommentsManager(),
193
+            \OC::$server->getUserSession()
194
+        ));
195
+
196
+        $this->server->addPlugin(new CopyEtagHeaderPlugin());
197
+        $this->server->addPlugin(new ChunkingPlugin());
198
+
199
+        // allow setup of additional plugins
200
+        $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
201
+
202
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
203
+        // we do not provide locking we emulate it using a fake locking plugin.
204
+        if ($request->isUserAgent([
205
+            '/WebDAVFS/',
206
+            '/OneNote/',
207
+            '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
208
+        ])) {
209
+            $this->server->addPlugin(new FakeLockerPlugin());
210
+        }
211
+
212
+        if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
213
+            $this->server->addPlugin(new BrowserErrorPagePlugin());
214
+        }
215
+
216
+        $lazySearchBackend = new LazySearchBackend();
217
+        $this->server->addPlugin(new SearchPlugin($lazySearchBackend));
218
+
219
+        // wait with registering these until auth is handled and the filesystem is setup
220
+        $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) {
221
+            // custom properties plugin must be the last one
222
+            $userSession = \OC::$server->getUserSession();
223
+            $user = $userSession->getUser();
224
+            if ($user !== null) {
225
+                $view = \OC\Files\Filesystem::getView();
226
+                $this->server->addPlugin(
227
+                    new FilesPlugin(
228
+                        $this->server->tree,
229
+                        \OC::$server->getConfig(),
230
+                        $this->request,
231
+                        \OC::$server->getPreviewManager(),
232
+                        false,
233
+                        !\OC::$server->getConfig()->getSystemValue('debug', false)
234
+                    )
235
+                );
236
+
237
+                $this->server->addPlugin(
238
+                    new \Sabre\DAV\PropertyStorage\Plugin(
239
+                        new CustomPropertiesBackend(
240
+                            $this->server->tree,
241
+                            \OC::$server->getDatabaseConnection(),
242
+                            \OC::$server->getUserSession()->getUser()
243
+                        )
244
+                    )
245
+                );
246
+                if ($view !== null) {
247
+                    $this->server->addPlugin(
248
+                        new QuotaPlugin($view, false));
249
+                }
250
+                $this->server->addPlugin(
251
+                    new TagsPlugin(
252
+                        $this->server->tree, \OC::$server->getTagManager()
253
+                    )
254
+                );
255
+                // TODO: switch to LazyUserFolder
256
+                $userFolder = \OC::$server->getUserFolder();
257
+                $this->server->addPlugin(new SharesPlugin(
258
+                    $this->server->tree,
259
+                    $userSession,
260
+                    $userFolder,
261
+                    \OC::$server->getShareManager()
262
+                ));
263
+                $this->server->addPlugin(new CommentPropertiesPlugin(
264
+                    \OC::$server->getCommentsManager(),
265
+                    $userSession
266
+                ));
267
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
268
+                if ($view !== null) {
269
+                    $this->server->addPlugin(new FilesReportPlugin(
270
+                        $this->server->tree,
271
+                        $view,
272
+                        \OC::$server->getSystemTagManager(),
273
+                        \OC::$server->getSystemTagObjectMapper(),
274
+                        \OC::$server->getTagManager(),
275
+                        $userSession,
276
+                        \OC::$server->getGroupManager(),
277
+                        $userFolder,
278
+                        \OC::$server->getAppManager()
279
+                    ));
280
+                    $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend(
281
+                        $this->server->tree,
282
+                        $user,
283
+                        \OC::$server->getRootFolder(),
284
+                        \OC::$server->getShareManager(),
285
+                        $view
286
+                    ));
287
+                }
288
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin(
289
+                    \OC::$server->getConfig(),
290
+                    \OC::$server->query(BirthdayService::class)
291
+                ));
292
+                $this->server->addPlugin(new AppleProvisioningPlugin(
293
+                    \OC::$server->getUserSession(),
294
+                    \OC::$server->getURLGenerator(),
295
+                    \OC::$server->getThemingDefaults(),
296
+                    \OC::$server->getRequest(),
297
+                    \OC::$server->getL10N('dav'),
298
+                    function () {
299
+                        return UUIDUtil::getUUID();
300
+                    }
301
+                ));
302
+            }
303
+
304
+            // register plugins from apps
305
+            $pluginManager = new PluginManager(
306
+                \OC::$server,
307
+                \OC::$server->getAppManager()
308
+            );
309
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
310
+                $this->server->addPlugin($appPlugin);
311
+            }
312
+            foreach ($pluginManager->getAppCollections() as $appCollection) {
313
+                $root->addChild($appCollection);
314
+            }
315
+        });
316
+    }
317
+
318
+    public function exec() {
319
+        $this->server->exec();
320
+    }
321
+
322
+    private function requestIsForSubtree(array $subTrees): bool {
323
+        foreach ($subTrees as $subTree) {
324
+            $subTree = trim($subTree, ' /');
325
+            if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
326
+                return true;
327
+            }
328
+        }
329
+        return false;
330
+    }
331 331
 }
Please login to merge, or discard this patch.