|
48 | 48 | use OCP\IConfig; |
49 | 49 | use OCP\IDBConnection; |
50 | 50 | use OCP\IUserManager; |
| 51 | +use OCP\IUserSession; |
51 | 52 | use OCP\Security\ISecureRandom; |
52 | 53 | use Psr\Log\LoggerInterface; |
53 | 54 | use RuntimeException; |
@@ -152,6 +153,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription |
152 | 153 | '{http://apple.com/ns/ical/}calendar-color' => ['calendarcolor', 'string'], |
153 | 154 | '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}deleted-at' => ['deleted_at', 'int'], |
154 | 155 | '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}default-alarm' => ['default_alarm', 'int'], |
| 156 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}ignore-reminders' => ['ignore_reminders', 'bool'], |
155 | 157 | ]; |
156 | 158 |
|
157 | 159 | /** |
@@ -219,6 +221,7 @@ public function __construct( |
219 | 221 | private FederatedCalendarMapper $federatedCalendarMapper, |
220 | 222 | ICacheFactory $cacheFactory, |
221 | 223 | private bool $legacyEndpoint = false, |
| 224 | + private ?IUserSession $userSession = null, |
222 | 225 | ) { |
223 | 226 | $this->publishStatusCache = $cacheFactory->createInMemory(); |
224 | 227 | } |
@@ -381,6 +384,9 @@ public function getCalendarsForUser($principalUri) { |
381 | 384 |
|
382 | 385 | $fields = array_column($this->propertyMap, 0); |
383 | 386 | $fields = array_map(function (string $field) { |
| 387 | + if ($field === 'ignore_reminders') { |
| 388 | + return 's.ignore_reminders'; |
| 389 | + } |
384 | 390 | return 'a.' . $field; |
385 | 391 | }, $fields); |
386 | 392 | $fields[] = 'a.id'; |
@@ -512,6 +518,12 @@ public function getUsersOwnCalendars($principalUri) { |
512 | 518 | */ |
513 | 519 | public function getPublicCalendars() { |
514 | 520 | $fields = array_column($this->propertyMap, 0); |
| 521 | + $fields = array_map(function (string $field) { |
| 522 | + if ($field === 'ignore_reminders') { |
| 523 | + return 's.ignore_reminders'; |
| 524 | + } |
| 525 | + return 'a.' . $field; |
| 526 | + }, $fields); |
515 | 527 | $fields[] = 'a.id'; |
516 | 528 | $fields[] = 'a.uri'; |
517 | 529 | $fields[] = 'a.synctoken'; |
@@ -570,6 +582,12 @@ public function getPublicCalendars() { |
570 | 582 | */ |
571 | 583 | public function getPublicCalendar($uri) { |
572 | 584 | $fields = array_column($this->propertyMap, 0); |
| 585 | + $fields = array_map(function (string $field) { |
| 586 | + if ($field === 'ignore_reminders') { |
| 587 | + return 's.ignore_reminders'; |
| 588 | + } |
| 589 | + return 'a.' . $field; |
| 590 | + }, $fields); |
573 | 591 | $fields[] = 'a.id'; |
574 | 592 | $fields[] = 'a.uri'; |
575 | 593 | $fields[] = 'a.synctoken'; |
@@ -901,14 +919,55 @@ public function updateCalendar($calendarId, PropPatch $propPatch) { |
901 | 919 | break; |
902 | 920 | } |
903 | 921 | } |
904 | | - [$calendarData, $shares] = $this->atomic(function () use ($calendarId, $newValues) { |
905 | | - $query = $this->db->getQueryBuilder(); |
906 | | - $query->update('calendars'); |
907 | | - foreach ($newValues as $fieldName => $value) { |
908 | | - $query->set($fieldName, $query->createNamedParameter($value)); |
| 922 | + [$calendarData, $shares] = $this->atomic(function () use ($calendarId, &$newValues) { |
| 923 | + if (isset($newValues['ignore_reminders'])) { |
| 924 | + $rawVal = $newValues['ignore_reminders']; |
| 925 | + if (\is_bool($rawVal)) { |
| 926 | + $ignoreRemindersVal = $rawVal ? 1 : 0; |
| 927 | + } elseif (\is_string($rawVal)) { |
| 928 | + $ignoreRemindersVal = \in_array(strtolower(trim($rawVal)), ['1', 'true', 'yes'], true) ? 1 : 0; |
| 929 | + } else { |
| 930 | + $ignoreRemindersVal = (int)(bool)$rawVal; |
| 931 | + } |
| 932 | + |
| 933 | + $user = $this->userSession?->getUser(); |
| 934 | + if ($user !== null) { |
| 935 | + $principalUri = 'principals/users/' . $user->getUID(); |
| 936 | + $principals = $this->principalBackend->getGroupMembership($principalUri, true); |
| 937 | + $principals = array_merge($principals, $this->principalBackend->getCircleMembership($principalUri)); |
| 938 | + $principals[] = $principalUri; |
| 939 | + |
| 940 | + $qbCheck = $this->db->getQueryBuilder(); |
| 941 | + $qbCheck->select('id') |
| 942 | + ->from('dav_shares') |
| 943 | + ->where($qbCheck->expr()->eq('resourceid', $qbCheck->createNamedParameter($calendarId))) |
| 944 | + ->andWhere($qbCheck->expr()->in('principaluri', $qbCheck->createNamedParameter($principals, IQueryBuilder::PARAM_STR_ARRAY))) |
| 945 | + ->andWhere($qbCheck->expr()->eq('type', $qbCheck->createNamedParameter('calendar'))); |
| 946 | + $shareId = $qbCheck->executeQuery()->fetchOne(); |
| 947 | + if ($shareId !== false) { |
| 948 | + $qbUpdate = $this->db->getQueryBuilder(); |
| 949 | + $qbUpdate->update('dav_shares') |
| 950 | + ->set('ignore_reminders', $qbUpdate->createNamedParameter($ignoreRemindersVal)) |
| 951 | + ->where($qbUpdate->expr()->eq('id', $qbUpdate->createNamedParameter($shareId))); |
| 952 | + $qbUpdate->executeStatement(); |
| 953 | + unset($newValues['ignore_reminders']); |
| 954 | + } else { |
| 955 | + $newValues['ignore_reminders'] = $ignoreRemindersVal; |
| 956 | + } |
| 957 | + } else { |
| 958 | + $newValues['ignore_reminders'] = $ignoreRemindersVal; |
| 959 | + } |
| 960 | + } |
| 961 | + |
| 962 | + if (!empty($newValues)) { |
| 963 | + $query = $this->db->getQueryBuilder(); |
| 964 | + $query->update('calendars'); |
| 965 | + foreach ($newValues as $fieldName => $value) { |
| 966 | + $query->set($fieldName, $query->createNamedParameter($value)); |
| 967 | + } |
| 968 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
| 969 | + $query->executeStatement(); |
909 | 970 | } |
910 | | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
911 | | - $query->executeStatement(); |
912 | 971 |
|
913 | 972 | $this->addChanges($calendarId, [''], 2); |
914 | 973 |
|
|
0 commit comments