diff options
Diffstat (limited to 'apps/dav')
26 files changed, 1076 insertions, 50 deletions
diff --git a/apps/dav/appinfo/info.xml b/apps/dav/appinfo/info.xml index 0ef960b0173..5cc374a566d 100644 --- a/apps/dav/appinfo/info.xml +++ b/apps/dav/appinfo/info.xml @@ -5,7 +5,7 @@ <name>WebDAV</name> <summary>WebDAV endpoint</summary> <description>WebDAV endpoint</description> - <version>1.9.1</version> + <version>1.9.2</version> <licence>agpl</licence> <author>owncloud.org</author> <namespace>DAV</namespace> @@ -31,6 +31,7 @@ <step>OCA\DAV\Migration\CalDAVRemoveEmptyValue</step> <step>OCA\DAV\Migration\BuildCalendarSearchIndex</step> <step>OCA\DAV\Migration\RefreshWebcalJobRegistrar</step> + <step>OCA\DAV\Migration\RemoveOrphanEventsAndContacts</step> <step>OCA\DAV\Migration\RemoveClassifiedEventActivity</step> </post-migration> <live-migration> @@ -41,6 +42,8 @@ <commands> <command>OCA\DAV\Command\CreateAddressBook</command> <command>OCA\DAV\Command\CreateCalendar</command> + <command>OCA\DAV\Command\MoveCalendar</command> + <command>OCA\DAV\Command\ListCalendars</command> <command>OCA\DAV\Command\SyncBirthdayCalendar</command> <command>OCA\DAV\Command\SyncSystemAddressBook</command> <command>OCA\DAV\Command\RemoveInvalidShares</command> diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 6e2f6ba72ed..94e371037cb 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -79,6 +79,8 @@ return array( 'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php', 'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php', 'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php', + 'OCA\\DAV\\Command\\ListCalendars' => $baseDir . '/../lib/Command/ListCalendars.php', + 'OCA\\DAV\\Command\\MoveCalendar' => $baseDir . '/../lib/Command/MoveCalendar.php', 'OCA\\DAV\\Command\\RemoveInvalidShares' => $baseDir . '/../lib/Command/RemoveInvalidShares.php', 'OCA\\DAV\\Command\\SyncBirthdayCalendar' => $baseDir . '/../lib/Command/SyncBirthdayCalendar.php', 'OCA\\DAV\\Command\\SyncSystemAddressBook' => $baseDir . '/../lib/Command/SyncSystemAddressBook.php', @@ -158,6 +160,7 @@ return array( 'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => $baseDir . '/../lib/Migration/FixBirthdayCalendarComponent.php', 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => $baseDir . '/../lib/Migration/RefreshWebcalJobRegistrar.php', 'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => $baseDir . '/../lib/Migration/RemoveClassifiedEventActivity.php', + 'OCA\\DAV\\Migration\\RemoveOrphanEventsAndContacts' => $baseDir . '/../lib/Migration/RemoveOrphanEventsAndContacts.php', 'OCA\\DAV\\Migration\\Version1004Date20170825134824' => $baseDir . '/../lib/Migration/Version1004Date20170825134824.php', 'OCA\\DAV\\Migration\\Version1004Date20170919104507' => $baseDir . '/../lib/Migration/Version1004Date20170919104507.php', 'OCA\\DAV\\Migration\\Version1004Date20170924124212' => $baseDir . '/../lib/Migration/Version1004Date20170924124212.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 8a038801ab3..fb3de390d65 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -94,6 +94,8 @@ class ComposerStaticInitDAV 'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php', 'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php', 'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php', + 'OCA\\DAV\\Command\\ListCalendars' => __DIR__ . '/..' . '/../lib/Command/ListCalendars.php', + 'OCA\\DAV\\Command\\MoveCalendar' => __DIR__ . '/..' . '/../lib/Command/MoveCalendar.php', 'OCA\\DAV\\Command\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Command/RemoveInvalidShares.php', 'OCA\\DAV\\Command\\SyncBirthdayCalendar' => __DIR__ . '/..' . '/../lib/Command/SyncBirthdayCalendar.php', 'OCA\\DAV\\Command\\SyncSystemAddressBook' => __DIR__ . '/..' . '/../lib/Command/SyncSystemAddressBook.php', @@ -173,6 +175,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\FixBirthdayCalendarComponent' => __DIR__ . '/..' . '/../lib/Migration/FixBirthdayCalendarComponent.php', 'OCA\\DAV\\Migration\\RefreshWebcalJobRegistrar' => __DIR__ . '/..' . '/../lib/Migration/RefreshWebcalJobRegistrar.php', 'OCA\\DAV\\Migration\\RemoveClassifiedEventActivity' => __DIR__ . '/..' . '/../lib/Migration/RemoveClassifiedEventActivity.php', + 'OCA\\DAV\\Migration\\RemoveOrphanEventsAndContacts' => __DIR__ . '/..' . '/../lib/Migration/RemoveOrphanEventsAndContacts.php', 'OCA\\DAV\\Migration\\Version1004Date20170825134824' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170825134824.php', 'OCA\\DAV\\Migration\\Version1004Date20170919104507' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170919104507.php', 'OCA\\DAV\\Migration\\Version1004Date20170924124212' => __DIR__ . '/..' . '/../lib/Migration/Version1004Date20170924124212.php', diff --git a/apps/dav/l10n/ca.js b/apps/dav/l10n/ca.js index f4cc6d25aab..fddbb26a3ba 100644 --- a/apps/dav/l10n/ca.js +++ b/apps/dav/l10n/ca.js @@ -44,6 +44,7 @@ OC.L10N.register( "Contacts" : "Contactes", "Technical details" : "Detalls tècnics", "Remote Address: %s" : "Adreça remota: %s", - "Request ID: %s" : "Sol·licitud ID: %s " + "Request ID: %s" : "Sol·licitud ID: %s ", + "Save" : "Desa" }, "nplurals=2; plural=(n != 1);"); diff --git a/apps/dav/l10n/ca.json b/apps/dav/l10n/ca.json index 5479a8d69bd..db041f6ebf2 100644 --- a/apps/dav/l10n/ca.json +++ b/apps/dav/l10n/ca.json @@ -42,6 +42,7 @@ "Contacts" : "Contactes", "Technical details" : "Detalls tècnics", "Remote Address: %s" : "Adreça remota: %s", - "Request ID: %s" : "Sol·licitud ID: %s " + "Request ID: %s" : "Sol·licitud ID: %s ", + "Save" : "Desa" },"pluralForm" :"nplurals=2; plural=(n != 1);" }
\ No newline at end of file diff --git a/apps/dav/l10n/el.js b/apps/dav/l10n/el.js index 7b27d2dbcb7..8f44cd5dfed 100644 --- a/apps/dav/l10n/el.js +++ b/apps/dav/l10n/el.js @@ -43,6 +43,7 @@ OC.L10N.register( "A calendar <strong>event</strong> was modified" : "Τροποποιήθηκε ένα <strong>γεγονός</strong> του ημερολογίου", "A calendar <strong>todo</strong> was modified" : "Ενός ημερολογίου η <strong>εκκρεμότητα</strong> τροποποιήθηκε", "Contact birthdays" : "Γενέθλια επαφών", + "%1$s via %2$s" : "%1$s μέσω %2$s", "Invitation canceled" : "Η πρόσκληση ακυρώθηκε.", "Hello %s," : "Γεια σου %s,", "Invitation updated" : "Ενημερώθηκε η πρόσκληση.", diff --git a/apps/dav/l10n/el.json b/apps/dav/l10n/el.json index 3a9046b559a..97115b4f7e3 100644 --- a/apps/dav/l10n/el.json +++ b/apps/dav/l10n/el.json @@ -41,6 +41,7 @@ "A calendar <strong>event</strong> was modified" : "Τροποποιήθηκε ένα <strong>γεγονός</strong> του ημερολογίου", "A calendar <strong>todo</strong> was modified" : "Ενός ημερολογίου η <strong>εκκρεμότητα</strong> τροποποιήθηκε", "Contact birthdays" : "Γενέθλια επαφών", + "%1$s via %2$s" : "%1$s μέσω %2$s", "Invitation canceled" : "Η πρόσκληση ακυρώθηκε.", "Hello %s," : "Γεια σου %s,", "Invitation updated" : "Ενημερώθηκε η πρόσκληση.", diff --git a/apps/dav/l10n/gl.js b/apps/dav/l10n/gl.js index 76b330a1274..8548121dd2e 100644 --- a/apps/dav/l10n/gl.js +++ b/apps/dav/l10n/gl.js @@ -44,7 +44,7 @@ OC.L10N.register( "A calendar <strong>event</strong> was modified" : "Foi modificado un <strong>evento</strong> do calendario", "A calendar <strong>todo</strong> was modified" : "Foi modificado un <strong>asunto pendente</strong> do calendario", "Contact birthdays" : "Aniversario do contacto", - "%1$s via %2$s" : "%1$s a través de %2$s", + "%1$s via %2$s" : "%1$s mediante %2$s", "Invitation canceled" : "Convite cancelado", "Hello %s," : "Ola %s,", "The meeting »%1$s« with %2$s was canceled." : "A xuntanza «%1$s» con %2$s foi cancelada.", @@ -77,7 +77,7 @@ OC.L10N.register( "Automatically generate a birthday calendar" : "Xerar automaticamente o calendario de aniversarios", "Birthday calendars will be generated by a background job." : "O calendario de aniversarios xerase cun traballo en segundo plano", "Hence they will not be available immediately after enabling but will show up after some time." : "Por isto, non estarán dispoñíbeis inmediatamente tras activalos, senón que aparecerán após certo tempo", - "%s via %s" : "%s vía %s", + "%s via %s" : "%s mediante %s", "The meeting »%s« with %s was canceled." : "A xuntanza «%s» con %s foi cancelada.", "The meeting »%s« with %s was updated." : "A xuntanza «%s» con %s foi actualizada.", "%s invited you to »%s«" : "%s convidouno a «%s»", diff --git a/apps/dav/l10n/gl.json b/apps/dav/l10n/gl.json index d7b30145adb..ad6db03d8b2 100644 --- a/apps/dav/l10n/gl.json +++ b/apps/dav/l10n/gl.json @@ -42,7 +42,7 @@ "A calendar <strong>event</strong> was modified" : "Foi modificado un <strong>evento</strong> do calendario", "A calendar <strong>todo</strong> was modified" : "Foi modificado un <strong>asunto pendente</strong> do calendario", "Contact birthdays" : "Aniversario do contacto", - "%1$s via %2$s" : "%1$s a través de %2$s", + "%1$s via %2$s" : "%1$s mediante %2$s", "Invitation canceled" : "Convite cancelado", "Hello %s," : "Ola %s,", "The meeting »%1$s« with %2$s was canceled." : "A xuntanza «%1$s» con %2$s foi cancelada.", @@ -75,7 +75,7 @@ "Automatically generate a birthday calendar" : "Xerar automaticamente o calendario de aniversarios", "Birthday calendars will be generated by a background job." : "O calendario de aniversarios xerase cun traballo en segundo plano", "Hence they will not be available immediately after enabling but will show up after some time." : "Por isto, non estarán dispoñíbeis inmediatamente tras activalos, senón que aparecerán após certo tempo", - "%s via %s" : "%s vía %s", + "%s via %s" : "%s mediante %s", "The meeting »%s« with %s was canceled." : "A xuntanza «%s» con %s foi cancelada.", "The meeting »%s« with %s was updated." : "A xuntanza «%s» con %s foi actualizada.", "%s invited you to »%s«" : "%s convidouno a «%s»", diff --git a/apps/dav/l10n/nl.js b/apps/dav/l10n/nl.js index 91df26e7acc..96d9b370731 100644 --- a/apps/dav/l10n/nl.js +++ b/apps/dav/l10n/nl.js @@ -29,6 +29,7 @@ OC.L10N.register( "You deleted event {event} from calendar {calendar}" : "Je verwijderde afspraak {event} uit agenda {calendar}", "{actor} updated event {event} in calendar {calendar}" : "{actor} heeft afspraak {event} in agenda {calendar} bijgewerkt", "You updated event {event} in calendar {calendar}" : "Je hebt afspraak {event} in agenda {calendar} bijgewerkt", + "Busy" : "Bezig", "{actor} created todo {todo} in list {calendar}" : "{actor} creëerde taak {todo} in lijst {calendar}", "You created todo {todo} in list {calendar}" : "Jij creëerde taak {todo} in lijst {calendar}", "{actor} deleted todo {todo} from list {calendar}" : "{actor} heeft de taak {todo} uit lijst {calendar} verwijderd", diff --git a/apps/dav/l10n/nl.json b/apps/dav/l10n/nl.json index edc8640ab1c..196a523633b 100644 --- a/apps/dav/l10n/nl.json +++ b/apps/dav/l10n/nl.json @@ -27,6 +27,7 @@ "You deleted event {event} from calendar {calendar}" : "Je verwijderde afspraak {event} uit agenda {calendar}", "{actor} updated event {event} in calendar {calendar}" : "{actor} heeft afspraak {event} in agenda {calendar} bijgewerkt", "You updated event {event} in calendar {calendar}" : "Je hebt afspraak {event} in agenda {calendar} bijgewerkt", + "Busy" : "Bezig", "{actor} created todo {todo} in list {calendar}" : "{actor} creëerde taak {todo} in lijst {calendar}", "You created todo {todo} in list {calendar}" : "Jij creëerde taak {todo} in lijst {calendar}", "{actor} deleted todo {todo} from list {calendar}" : "{actor} heeft de taak {todo} uit lijst {calendar} verwijderd", diff --git a/apps/dav/l10n/tr.js b/apps/dav/l10n/tr.js index 95ac4daf8d7..4a29d057e18 100644 --- a/apps/dav/l10n/tr.js +++ b/apps/dav/l10n/tr.js @@ -29,6 +29,7 @@ OC.L10N.register( "You deleted event {event} from calendar {calendar}" : "{calendar} takviminden {event} etkinliğini sildiniz", "{actor} updated event {event} in calendar {calendar}" : "{actor}, {calendar} takvimindeki {event} etkinliğini güncelledi", "You updated event {event} in calendar {calendar}" : "{calendar} takvimindeki {event} etkinliğini güncellediniz", + "Busy" : "Meşgul", "{actor} created todo {todo} in list {calendar}" : "{actor}, {calendar} takvimi listesine {todo} yapılacak işini ekledi", "You created todo {todo} in list {calendar}" : "{calendar} takvimi listesine {todo} yapılacak işini eklediniz", "{actor} deleted todo {todo} from list {calendar}" : "{actor}, {calendar} takvimi listesinden {todo} yapılacak işini sildi", diff --git a/apps/dav/l10n/tr.json b/apps/dav/l10n/tr.json index 90fd06867fc..7763b0ebfa1 100644 --- a/apps/dav/l10n/tr.json +++ b/apps/dav/l10n/tr.json @@ -27,6 +27,7 @@ "You deleted event {event} from calendar {calendar}" : "{calendar} takviminden {event} etkinliğini sildiniz", "{actor} updated event {event} in calendar {calendar}" : "{actor}, {calendar} takvimindeki {event} etkinliğini güncelledi", "You updated event {event} in calendar {calendar}" : "{calendar} takvimindeki {event} etkinliğini güncellediniz", + "Busy" : "Meşgul", "{actor} created todo {todo} in list {calendar}" : "{actor}, {calendar} takvimi listesine {todo} yapılacak işini ekledi", "You created todo {todo} in list {calendar}" : "{calendar} takvimi listesine {todo} yapılacak işini eklediniz", "{actor} deleted todo {todo} from list {calendar}" : "{actor}, {calendar} takvimi listesinden {todo} yapılacak işini sildi", diff --git a/apps/dav/l10n/zh_CN.js b/apps/dav/l10n/zh_CN.js index 700db581385..1b16925a5ce 100644 --- a/apps/dav/l10n/zh_CN.js +++ b/apps/dav/l10n/zh_CN.js @@ -10,8 +10,8 @@ OC.L10N.register( "You deleted calendar {calendar}" : "您删除的日历 {calendar}", "{actor} updated calendar {calendar}" : "{actor} 更新了日历 {calendar}", "You updated calendar {calendar}" : "您更新了日历 {calendar}", - "You shared calendar {calendar} as public link" : "您已将日历{calendar}共享为公开链接", - "You removed public link for calendar {calendar}" : "您移除了日历{calendar}的公开链接", + "You shared calendar {calendar} as public link" : "您已将日历 {calendar} 共享为公开链接", + "You removed public link for calendar {calendar}" : "您移除了日历 {calendar} 的公开链接", "{actor} shared calendar {calendar} with you" : "{actor} 收到的日历共享 {calendar}", "You shared calendar {calendar} with {user}" : "您与 {user} 共享了日历 {calendar}", "{actor} shared calendar {calendar} with {user}" : "{actor} 与 {user} 共享了日历 {calendar}", @@ -29,6 +29,7 @@ OC.L10N.register( "You deleted event {event} from calendar {calendar}" : "您在日历 {calendar} 中删除了事件 {event}", "{actor} updated event {event} in calendar {calendar}" : "{actor} 在日历 {calendar} 中更新了事件 {event}", "You updated event {event} in calendar {calendar}" : "您在日历 {calendar} 中更新了事件 {event}", + "Busy" : "忙碌", "{actor} created todo {todo} in list {calendar}" : "{actor} 在列表 {calendar} 中创建了待办事项 {todo}", "You created todo {todo} in list {calendar}" : "您在列表 {calendar} 中创建了待办事项 {todo}", "{actor} deleted todo {todo} from list {calendar}" : "{actor} 在列表 {calendar} 中删除了待办事项 {todo}", @@ -44,16 +45,20 @@ OC.L10N.register( "A calendar <strong>todo</strong> was modified" : "列表中<strong>待办事项</strong>已经修改", "Contact birthdays" : "联系人生日", "Invitation canceled" : "邀请已取消", - "Hello %s," : "%s你好,", + "Hello %s," : "您好,%s,", "Invitation updated" : "邀请已更新", "When:" : "时间:", "Where:" : "地点:", "Description:" : "描述:", "Link:" : "链接:", "Contacts" : "联系人", + "WebDAV" : "WebDAV", "Technical details" : "技术细节", - "Remote Address: %s" : "远程地址: %s", - "Request ID: %s" : "请求 ID: %s", + "Remote Address: %s" : "远程地址:%s", + "Request ID: %s" : "请求 ID:%s", + "Save" : "保存", + "Send invitations to attendees" : "向参与者发送邀请", + "Please make sure to properly set up the email settings above." : "请确保正确设置上面的电子邮件设置。", "Automatically generate a birthday calendar" : "自动生成生日日历", "Birthday calendars will be generated by a background job." : "生日日历将由后台作业生成。", "CalDAV server" : "日历服务" diff --git a/apps/dav/l10n/zh_CN.json b/apps/dav/l10n/zh_CN.json index 8493d72c541..8b16aa2e41c 100644 --- a/apps/dav/l10n/zh_CN.json +++ b/apps/dav/l10n/zh_CN.json @@ -8,8 +8,8 @@ "You deleted calendar {calendar}" : "您删除的日历 {calendar}", "{actor} updated calendar {calendar}" : "{actor} 更新了日历 {calendar}", "You updated calendar {calendar}" : "您更新了日历 {calendar}", - "You shared calendar {calendar} as public link" : "您已将日历{calendar}共享为公开链接", - "You removed public link for calendar {calendar}" : "您移除了日历{calendar}的公开链接", + "You shared calendar {calendar} as public link" : "您已将日历 {calendar} 共享为公开链接", + "You removed public link for calendar {calendar}" : "您移除了日历 {calendar} 的公开链接", "{actor} shared calendar {calendar} with you" : "{actor} 收到的日历共享 {calendar}", "You shared calendar {calendar} with {user}" : "您与 {user} 共享了日历 {calendar}", "{actor} shared calendar {calendar} with {user}" : "{actor} 与 {user} 共享了日历 {calendar}", @@ -27,6 +27,7 @@ "You deleted event {event} from calendar {calendar}" : "您在日历 {calendar} 中删除了事件 {event}", "{actor} updated event {event} in calendar {calendar}" : "{actor} 在日历 {calendar} 中更新了事件 {event}", "You updated event {event} in calendar {calendar}" : "您在日历 {calendar} 中更新了事件 {event}", + "Busy" : "忙碌", "{actor} created todo {todo} in list {calendar}" : "{actor} 在列表 {calendar} 中创建了待办事项 {todo}", "You created todo {todo} in list {calendar}" : "您在列表 {calendar} 中创建了待办事项 {todo}", "{actor} deleted todo {todo} from list {calendar}" : "{actor} 在列表 {calendar} 中删除了待办事项 {todo}", @@ -42,16 +43,20 @@ "A calendar <strong>todo</strong> was modified" : "列表中<strong>待办事项</strong>已经修改", "Contact birthdays" : "联系人生日", "Invitation canceled" : "邀请已取消", - "Hello %s," : "%s你好,", + "Hello %s," : "您好,%s,", "Invitation updated" : "邀请已更新", "When:" : "时间:", "Where:" : "地点:", "Description:" : "描述:", "Link:" : "链接:", "Contacts" : "联系人", + "WebDAV" : "WebDAV", "Technical details" : "技术细节", - "Remote Address: %s" : "远程地址: %s", - "Request ID: %s" : "请求 ID: %s", + "Remote Address: %s" : "远程地址:%s", + "Request ID: %s" : "请求 ID:%s", + "Save" : "保存", + "Send invitations to attendees" : "向参与者发送邀请", + "Please make sure to properly set up the email settings above." : "请确保正确设置上面的电子邮件设置。", "Automatically generate a birthday calendar" : "自动生成生日日历", "Birthday calendars will be generated by a background job." : "生日日历将由后台作业生成。", "CalDAV server" : "日历服务" diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 187ba4ecdcf..88ee778e82c 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -2522,6 +2522,23 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } /** + * Move a calendar from one user to another + * + * @param string $uriName + * @param string $uriOrigin + * @param string $uriDestination + */ + public function moveCalendar($uriName, $uriOrigin, $uriDestination) + { + $query = $this->db->getQueryBuilder(); + $query->update('calendars') + ->set('principaluri', $query->createNamedParameter($uriDestination)) + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($uriOrigin))) + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($uriName))) + ->execute(); + } + + /** * read VCalendar data into a VCalendar object * * @param string $objectData diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 1aedd5d5643..ae727b8544f 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -76,6 +76,15 @@ class AddressBookImpl implements IAddressBook { } /** + * @return string defining the unique uri + * @since 16.0.0 + * @return string + */ + public function getUri(): string { + return $this->addressBookInfo['uri']; + } + + /** * In comparison to getKey() this function returns a human readable (maybe translated) name * * @return mixed diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index fa244857e39..eed11f1e939 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -35,6 +35,14 @@ use Sabre\VObject\Reader; class PhotoCache { + /** @var array */ + protected const ALLOWED_CONTENT_TYPES = [ + 'image/png' => 'png', + 'image/jpeg' => 'jpg', + 'image/gif' => 'gif', + 'image/vnd.microsoft.icon' => 'ico', + ]; + /** @var IAppData */ protected $appData; @@ -90,27 +98,26 @@ class PhotoCache { /** * @param ISimpleFolder $folder * @param Card $card + * @throws NotPermittedException */ - private function init(ISimpleFolder $folder, Card $card) { + private function init(ISimpleFolder $folder, Card $card): void { $data = $this->getPhoto($card); - if ($data === false) { + if ($data === false || !isset($data['Content-Type'])) { $folder->newFile('nophoto'); - } else { - switch ($data['Content-Type']) { - case 'image/png': - $ext = 'png'; - break; - case 'image/jpeg': - $ext = 'jpg'; - break; - case 'image/gif': - $ext = 'gif'; - break; - } - $file = $folder->newFile('photo.' . $ext); - $file->putContent($data['body']); + return; + } + + $contentType = $data['Content-Type']; + $extension = self::ALLOWED_CONTENT_TYPES[$contentType] ?? null; + + if ($extension === null) { + $folder->newFile('nophoto'); + return; } + + $file = $folder->newFile('photo.' . $extension); + $file->putContent($data['body']); } private function hasPhoto(ISimpleFolder $folder) { @@ -147,7 +154,7 @@ class PhotoCache { if ($size !== -1) { $photo->resize($size); } - + try { $file = $folder->newFile($path); $file->putContent($photo->data()); @@ -180,15 +187,14 @@ class PhotoCache { * @return string * @throws NotFoundException */ - private function getExtension(ISimpleFolder $folder) { - if ($folder->fileExists('photo.jpg')) { - return 'jpg'; - } elseif ($folder->fileExists('photo.png')) { - return 'png'; - } elseif ($folder->fileExists('photo.gif')) { - return 'gif'; + private function getExtension(ISimpleFolder $folder): string { + foreach (self::ALLOWED_CONTENT_TYPES as $extension) { + if ($folder->fileExists('photo.' . $extension)) { + return $extension; + } } - throw new NotFoundException; + + throw new NotFoundException('Avatar not found'); } private function getPhoto(Card $node) { @@ -218,13 +224,7 @@ class PhotoCache { $type = $this->getBinaryType($photo); } - $allowedContentTypes = [ - 'image/png', - 'image/jpeg', - 'image/gif', - ]; - - if (!in_array($type, $allowedContentTypes, true)) { + if (empty($type) || !isset(self::ALLOWED_CONTENT_TYPES[$type])) { $type = 'application/octet-stream'; } diff --git a/apps/dav/lib/Command/ListCalendars.php b/apps/dav/lib/Command/ListCalendars.php new file mode 100644 index 00000000000..6c2f5bdb506 --- /dev/null +++ b/apps/dav/lib/Command/ListCalendars.php @@ -0,0 +1,108 @@ +<?php +/** + * @copyright Copyright (c) 2018, Georg Ehrke + * + * @author Georg Ehrke <oc.list@georgehrke.com> + * @author Thomas Citharel <tcit@tcit.fr> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CalDAV\BirthdayService; +use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\Connector\Sabre\Principal; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Share\IManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class ListCalendars extends Command { + + /** @var IUserManager */ + protected $userManager; + + /** @var CalDavBackend */ + private $caldav; + + /** + * @param IUserManager $userManager + * @param CalDavBackend $caldav + */ + function __construct(IUserManager $userManager, CalDavBackend $caldav) { + parent::__construct(); + $this->userManager = $userManager; + $this->caldav = $caldav; + } + + protected function configure() { + $this + ->setName('dav:list-calendars') + ->setDescription('List all calendars of a user') + ->addArgument('uid', + InputArgument::REQUIRED, + 'User for whom all calendars will be listed'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $user = $input->getArgument('uid'); + if (!$this->userManager->userExists($user)) { + throw new \InvalidArgumentException("User <$user> is unknown."); + } + + $calendars = $this->caldav->getCalendarsForUser("principals/users/$user"); + + $calendarTableData = []; + foreach($calendars as $calendar) { + // skip birthday calendar + if ($calendar['uri'] === BirthdayService::BIRTHDAY_CALENDAR_URI) { + continue; + } + + $readOnly = false; + $readOnlyIndex = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; + if (isset($calendar[$readOnlyIndex])) { + $readOnly = $calendar[$readOnlyIndex]; + } + + $calendarTableData[] = [ + $calendar['uri'], + $calendar['{DAV:}displayname'], + $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'], + $calendar['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'], + $readOnly ? ' x ' : ' ✓ ', + ]; + } + + if (count($calendarTableData) > 0) { + $table = new Table($output); + $table->setHeaders(['uri', 'displayname', 'owner\'s userid', 'owner\'s displayname', 'writable']) + ->setRows($calendarTableData); + + $table->render(); + } else { + $output->writeln("<info>User <$user> has no calendars</info>"); + } + } + +} diff --git a/apps/dav/lib/Command/MoveCalendar.php b/apps/dav/lib/Command/MoveCalendar.php new file mode 100644 index 00000000000..a2c7ca8c4d8 --- /dev/null +++ b/apps/dav/lib/Command/MoveCalendar.php @@ -0,0 +1,185 @@ +<?php +/** + * @author Thomas Citharel <tcit@tcit.fr> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\CalDAV\Calendar; +use OCA\DAV\Connector\Sabre\Principal; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\Share\IManager as IShareManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; + +class MoveCalendar extends Command { + + /** @var IUserManager */ + private $userManager; + + /** @var IGroupManager */ + private $groupManager; + + /** @var IShareManager */ + private $shareManager; + + /** @var IConfig $config */ + private $config; + + /** @var IL10N */ + private $l10n; + + /** @var SymfonyStyle */ + private $io; + + /** @var CalDavBackend */ + private $calDav; + + const URI_USERS = 'principals/users/'; + + /** + * @param IUserManager $userManager + * @param IGroupManager $groupManager + * @param IShareManager $shareManager + * @param IConfig $config + * @param IL10N $l10n + * @param CalDavBackend $calDav + */ + function __construct( + IUserManager $userManager, + IGroupManager $groupManager, + IShareManager $shareManager, + IConfig $config, + IL10N $l10n, + CalDavBackend $calDav + ) { + parent::__construct(); + $this->userManager = $userManager; + $this->groupManager = $groupManager; + $this->shareManager = $shareManager; + $this->config = $config; + $this->l10n = $l10n; + $this->calDav = $calDav; + } + + protected function configure() { + $this + ->setName('dav:move-calendar') + ->setDescription('Move a calendar from an user to another') + ->addArgument('name', + InputArgument::REQUIRED, + 'Name of the calendar to move') + ->addArgument('sourceuid', + InputArgument::REQUIRED, + 'User who currently owns the calendar') + ->addArgument('destinationuid', + InputArgument::REQUIRED, + 'User who will receive the calendar') + ->addOption('force', 'f', InputOption::VALUE_NONE, "Force the migration by removing existing shares"); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $userOrigin = $input->getArgument('sourceuid'); + $userDestination = $input->getArgument('destinationuid'); + + $this->io = new SymfonyStyle($input, $output); + + if (!$this->userManager->userExists($userOrigin)) { + throw new \InvalidArgumentException("User <$userOrigin> is unknown."); + } + + if (!$this->userManager->userExists($userDestination)) { + throw new \InvalidArgumentException("User <$userDestination> is unknown."); + } + + $name = $input->getArgument('name'); + + $calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); + + if (null === $calendar) { + throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user."); + } + + if (null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { + throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>."); + } + + $this->checkShares($calendar, $userOrigin, $userDestination, $input->getOption('force')); + + $this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); + + $this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>"); + } + + /** + * Check that moving the calendar won't break shares + * + * @param array $calendar + * @param string $userOrigin + * @param string $userDestination + * @param bool $force + */ + private function checkShares(array $calendar, string $userOrigin, string $userDestination, bool $force = false) + { + $shares = $this->calDav->getShares($calendar['id']); + foreach ($shares as $share) { + list(, $prefix, $userOrGroup) = explode('/', $share['href'], 3); + + /** + * Check that user destination is member of the groups which whom the calendar was shared + * If we ask to force the migration, the share with the group is dropped + */ + if ($this->shareManager->shareWithGroupMembersOnly() === true && 'groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) { + if ($force) { + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $userOrGroup]); + } else { + throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); + } + } + + /** + * Check that calendar isn't already shared with user destination + */ + if ($userOrGroup === $userDestination) { + if ($force) { + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/' . $userOrGroup]); + } else { + throw new \InvalidArgumentException("The calendar <" . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share."); + } + } + } + /** + * Warn that share links have changed if there are shares + */ + if (count($shares) > 0) { + $this->io->note([ + "Please note that moving calendar " . $calendar['uri'] . " from user <$userOrigin> to <$userDestination> has caused share links to change.", + "Sharees will need to change \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userDestination\"" + ]); + } + } +} diff --git a/apps/dav/lib/Migration/RemoveClassifiedEventActivity.php b/apps/dav/lib/Migration/RemoveClassifiedEventActivity.php index ad840d8100e..1829f57237a 100644 --- a/apps/dav/lib/Migration/RemoveClassifiedEventActivity.php +++ b/apps/dav/lib/Migration/RemoveClassifiedEventActivity.php @@ -127,6 +127,6 @@ class RemoveClassifiedEventActivity implements IRepairStep { protected function getPrincipal(string $principalUri): string { $uri = explode('/', $principalUri); - return $uri[2]; + return array_pop($uri); } } diff --git a/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php b/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php new file mode 100644 index 00000000000..17643587904 --- /dev/null +++ b/apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php @@ -0,0 +1,94 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Migration; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class RemoveOrphanEventsAndContacts implements IRepairStep { + + /** @var IDBConnection */ + private $connection; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + /** + * @inheritdoc + */ + public function getName(): string { + return 'Clean up orphan event and contact data'; + } + + /** + * @inheritdoc + */ + public function run(IOutput $output) { + $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars', 'calendarid'); + $output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems)); + $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects', 'objectid'); + $output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems)); + $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid'); + $output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems)); + + $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid'); + $output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems)); + $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid'); + $output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems)); + $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks', 'addressbookid'); + $output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems)); + } + + protected function removeOrphanChildren($childTable, $parentTable, $parentId): int { + $qb = $this->connection->getQueryBuilder(); + + $qb->select('c.id') + ->from($childTable, 'c') + ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id')) + ->where($qb->expr()->isNull('p.id')); + $result = $qb->execute(); + + $orphanItems = array(); + while ($row = $result->fetch()) { + $orphanItems[] = (int) $row['id']; + } + $result->closeCursor(); + + if (!empty($orphanItems)) { + $qb->delete($childTable) + ->where($qb->expr()->in('id', $qb->createParameter('ids'))); + + $orphanItemsBatch = array_chunk($orphanItems, 200); + foreach ($orphanItemsBatch as $items) { + $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); + $qb->execute(); + } + } + + return count($orphanItems); + } +} diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php index 8f495698d02..4d5bcea9966 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php @@ -28,6 +28,9 @@ use OCA\DAV\CalDAV\Activity\Filter\Todo; use OCP\Activity\IFilter; use Test\TestCase; +/** + * @group DB + */ class GenericTest extends TestCase { public function dataFilters() { diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 44609f2ca6c..1b2169b6675 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -983,4 +983,21 @@ EOD; $this->assertEquals(null, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)); } + + public function testCalendarMovement() + { + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); + + $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); + + $calendarInfoUser = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; + + $this->backend->moveCalendar('Example', self::UNIT_TEST_USER, self::UNIT_TEST_USER1); + $this->assertCount(0, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)); + $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)); + + $calendarInfoUser1 = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)[0]; + $this->assertEquals($calendarInfoUser['id'], $calendarInfoUser1['id']); + $this->assertEquals($calendarInfoUser['uri'], $calendarInfoUser1['uri']); + } } diff --git a/apps/dav/tests/unit/Command/ListCalendarsTest.php b/apps/dav/tests/unit/Command/ListCalendarsTest.php new file mode 100644 index 00000000000..1a0ca8c7954 --- /dev/null +++ b/apps/dav/tests/unit/Command/ListCalendarsTest.php @@ -0,0 +1,139 @@ +<?php +/** + * @author Thomas Citharel <tcit@tcit.fr> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\DAV\Tests\Command; + +use InvalidArgumentException; +use OCA\DAV\CalDAV\BirthdayService; +use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\Command\ListCalendars; +use OCP\IUserManager; +use Symfony\Component\Console\Tester\CommandTester; +use Test\TestCase; + + +/** + * Class ListCalendarsTest + * + * @package OCA\DAV\Tests\Command + */ +class ListCalendarsTest extends TestCase { + + /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */ + private $userManager; + + /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */ + private $calDav; + + /** @var ListCalendars */ + private $command; + + const USERNAME = 'username'; + + protected function setUp() { + parent::setUp(); + + $this->userManager = $this->createMock(IUserManager::class); + $this->calDav = $this->createMock(CalDavBackend::class); + + $this->command = new ListCalendars( + $this->userManager, + $this->calDav + ); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testWithBadUser() + { + $this->userManager->expects($this->once()) + ->method('userExists') + ->with(self::USERNAME) + ->willReturn(false); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'uid' => self::USERNAME, + ]); + $this->assertContains("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay()); + } + + public function testWithCorrectUserWithNoCalendars() + { + $this->userManager->expects($this->once()) + ->method('userExists') + ->with(self::USERNAME) + ->willReturn(true); + + $this->calDav->expects($this->once()) + ->method('getCalendarsForUser') + ->with('principals/users/' . self::USERNAME) + ->willReturn([]); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'uid' => self::USERNAME, + ]); + $this->assertContains("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay()); + } + + public function dataExecute() + { + return [ + [false, '✓'], + [true, 'x'] + ]; + } + + /** + * @dataProvider dataExecute + */ + public function testWithCorrectUser(bool $readOnly, string $output) + { + $this->userManager->expects($this->once()) + ->method('userExists') + ->with(self::USERNAME) + ->willReturn(true); + + $this->calDav->expects($this->once()) + ->method('getCalendarsForUser') + ->with('principals/users/' . self::USERNAME) + ->willReturn([ + [ + 'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI, + ], + [ + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly, + 'uri' => 'test', + '{DAV:}displayname' => 'dp', + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal', + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp', + ] + ]); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'uid' => self::USERNAME, + ]); + $this->assertContains($output, $commandTester->getDisplay()); + $this->assertNotContains(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay()); + } +} diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php new file mode 100644 index 00000000000..07d789dbfb2 --- /dev/null +++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php @@ -0,0 +1,427 @@ +<?php +/** + * @author Thomas Citharel <tcit@tcit.fr> + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\DAV\Tests\Command; + +use InvalidArgumentException; +use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\Command\MoveCalendar; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IUserManager; +use OCP\Share\IManager; +use Symfony\Component\Console\Tester\CommandTester; +use Test\TestCase; + + +/** + * Class MoveCalendarTest + * + * @package OCA\DAV\Tests\Command + */ +class MoveCalendarTest extends TestCase { + + /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */ + private $userManager; + + /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject $groupManager */ + private $groupManager; + + /** @var \OCP\Share\IManager|\PHPUnit_Framework_MockObject_MockObject $shareManager */ + private $shareManager; + + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $l10n */ + private $config; + + /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */ + private $l10n; + + /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject $l10n */ + private $calDav; + + /** @var MoveCalendar */ + private $command; + + protected function setUp() { + parent::setUp(); + + $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->shareManager = $this->createMock(IManager::class); + $this->config = $this->createMock(IConfig::class); + $this->l10n = $this->createMock(IL10N::class); + $this->calDav = $this->createMock(CalDavBackend::class); + + $this->command = new MoveCalendar( + $this->userManager, + $this->groupManager, + $this->shareManager, + $this->config, + $this->l10n, + $this->calDav + ); + } + + public function dataExecute() { + return [ + [false, true], + [true, false] + ]; + } + + /** + * @dataProvider dataExecute + * + * @expectedException InvalidArgumentException + * @param $userOriginExists + * @param $userDestinationExists + */ + public function testWithBadUserOrigin($userOriginExists, $userDestinationExists) + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn($userOriginExists); + + if (!$userDestinationExists) { + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn($userDestinationExists); + } + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => $this->command->getName(), + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user. + */ + public function testMoveWithInexistantCalendar() + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->once())->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn(null); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage User <user2> already has a calendar named <personal>. + */ + public function testMoveWithExistingDestinationCalendar() + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn([ + 'id' => 1234, + ]); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + } + + public function testMove() + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn(null); + + $this->calDav->expects($this->once())->method('getShares') + ->with(1234) + ->willReturn([]); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + + $this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); + } + + public function dataTestMoveWithDestinationNotPartOfGroup(): array + { + return [ + [true], + [false] + ]; + } + + /** + * @dataProvider dataTestMoveWithDestinationNotPartOfGroup + */ + public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly) + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + 'uri' => 'personal' + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn(null); + + $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') + ->willReturn($shareWithGroupMembersOnly); + + $this->calDav->expects($this->once())->method('getShares') + ->with(1234) + ->willReturn([ + ['href' => 'principal:principals/groups/nextclouders'] + ]); + if ($shareWithGroupMembersOnly === true) { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("User <user2> is not part of the group <nextclouders> with whom the calendar <personal> was shared. You may use -f to move the calendar while deleting this share."); + } + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + } + + public function testMoveWithDestinationPartOfGroup() + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + 'uri' => 'personal' + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn(null); + + $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') + ->willReturn(true); + + $this->calDav->expects($this->once())->method('getShares') + ->with(1234) + ->willReturn([ + ['href' => 'principal:principals/groups/nextclouders'] + ]); + + $this->groupManager->expects($this->once())->method('isInGroup') + ->with('user2', 'nextclouders') + ->willReturn(true); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + ]); + + $this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); + } + + public function testMoveWithDestinationNotPartOfGroupAndForce() + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + 'uri' => 'personal', + '{DAV:}displayname' => 'Personal' + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn(null); + + $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly') + ->willReturn(true); + + $this->calDav->expects($this->once())->method('getShares') + ->with(1234) + ->willReturn([ + [ + 'href' => 'principal:principals/groups/nextclouders', + '{DAV:}displayname' => 'Personal' + ] + ]); + $this->calDav->expects($this->once())->method('updateShares'); + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + '--force' => true + ]); + + $this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay()); + } + + public function dataTestMoveWithCalendarAlreadySharedToDestination(): array + { + return [ + [true], + [false] + ]; + } + + /** + * @dataProvider dataTestMoveWithCalendarAlreadySharedToDestination + */ + public function testMoveWithCalendarAlreadySharedToDestination(bool $force) + { + $this->userManager->expects($this->at(0)) + ->method('userExists') + ->with('user') + ->willReturn(true); + + $this->userManager->expects($this->at(1)) + ->method('userExists') + ->with('user2') + ->willReturn(true); + + $this->calDav->expects($this->at(0))->method('getCalendarByUri') + ->with('principals/users/user', 'personal') + ->willReturn([ + 'id' => 1234, + 'uri' => 'personal', + '{DAV:}displayname' => 'Personal', + ]); + + $this->calDav->expects($this->at(1))->method('getCalendarByUri') + ->with('principals/users/user2', 'personal') + ->willReturn(null); + + $this->calDav->expects($this->once())->method('getShares') + ->with(1234) + ->willReturn([ + [ + 'href' => 'principal:principals/users/user2', + '{DAV:}displayname' => 'Personal' + ] + ]); + + if ($force === false) { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("The calendar <personal> is already shared to user <user2>.You may use -f to move the calendar while deleting this share."); + } else { + $this->calDav->expects($this->once())->method('updateShares'); + } + + $commandTester = new CommandTester($this->command); + $commandTester->execute([ + 'name' => 'personal', + 'sourceuid' => 'user', + 'destinationuid' => 'user2', + '--force' => $force, + ]); + } +} |