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