diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-08-11 16:36:10 +0200 |
---|---|---|
committer | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2024-02-23 08:52:59 +0100 |
commit | dc7f2baf2649df6a0f65a3348346d76d8617cfeb (patch) | |
tree | b8f1111263b678d2957f23e4c0ac475f46164d40 /apps/dav/lib/CalDAV/CalDavBackend.php | |
parent | c942fb5db235908dc380ac31a8668aaa9bedb768 (diff) | |
download | nextcloud-server-dc7f2baf2649df6a0f65a3348346d76d8617cfeb.tar.gz nextcloud-server-dc7f2baf2649df6a0f65a3348346d76d8617cfeb.zip |
fix(dav): Rate limit calendar/subscription creation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib/CalDAV/CalDavBackend.php')
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index c694892089e..23812ff7e10 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -255,6 +255,27 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * Return the number of subscriptions for a principal + */ + public function getSubscriptionsForUserCount(string $principalUri): int { + $principalUri = $this->convertPrincipal($principalUri, true); + $query = $this->db->getQueryBuilder(); + $query->select($query->func()->count('*')) + ->from('calendarsubscriptions'); + + if ($principalUri === '') { + $query->where($query->expr()->emptyString('principaluri')); + } else { + $query->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); + } + + $result = $query->executeQuery(); + $column = (int)$result->fetchOne(); + $result->closeCursor(); + return $column; + } + + /** * @return array{id: int, deleted_at: int}[] */ public function getDeletedCalendars(int $deletedBefore): array { |