]> source.dussan.org Git - nextcloud-server.git/commitdiff
Deleting a shared calendar results in unshare
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 2 Feb 2016 12:07:14 +0000 (13:07 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 3 Feb 2016 16:18:22 +0000 (17:18 +0100)
apps/dav/lib/caldav/calendar.php
apps/dav/tests/travis/caldavtest/tests/CalDAV/sharing-calendars.xml
apps/dav/tests/unit/caldav/calendartest.php [new file with mode: 0644]

index 7822c703e919eb580c06f47e21a7760875e51569..f34ecfd5791e7a71653fa321acdb724eb8070cfa 100644 (file)
@@ -72,9 +72,21 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
        }
 
        function getOwner() {
-               if (isset($this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'])) {
-                       return $this->calendarInfo['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'];
+               if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
+                       return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
                }
                return parent::getOwner();
        }
+
+       function delete() {
+               if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
+                       /** @var CalDavBackend $calDavBackend */
+                       $calDavBackend = $this->caldavBackend;
+                       $calDavBackend->updateShares($this, [], [
+                               'href' => "principal:" . parent::getOwner()
+                       ]);
+                       return;
+               }
+               parent::delete();
+       }
 }
index 2204ca3af6986ae22b9f2ad47c2328af9636e2ac..a5fabcf6e8257282c546f507362f0126abee1254 100644 (file)
                                </verify>
                        </request>
                </test>
+               <test name='14'>
+                       <description>Un-share by delete</description>
+                       <request user="$userid2:" pswd="$pswd2:">
+                               <method>DELETE</method>
+                               <ruri>$calendarhome2:/shared_shared_by_user01/</ruri>
+                               <verify>
+                                       <callback>statusCode</callback>
+                               </verify>
+                       </request>
+               </test>
+               <test name='15'>
+                       <description>Original calendar still exists</description>
+                       <request>
+                               <method>PROPFIND</method>
+                               <ruri>$calendarhome1:/shared/</ruri>
+                               <header>
+                                       <name>Depth</name>
+                                       <value>0</value>
+                               </header>
+                               <data>
+                                       <content-type>text/xml; charset=utf-8</content-type>
+                                       <filepath>Resource/CalDAV/sharing/calendars/read-write/4.xml</filepath>
+                               </data>
+                               <verify>
+                                       <callback>xmlElementMatch</callback>
+                                       <arg>
+                                               <name>exists</name>
+                                               <value>$verify-property-prefix:/{DAV:}owner/{DAV:}href[=$principaluri1:]</value>
+                                               <value>$verify-property-prefix:/{DAV:}resourcetype/{DAV:}collection</value>
+                                               <value>$verify-property-prefix:/{DAV:}resourcetype/{urn:ietf:params:xml:ns:caldav}calendar</value>
+                                               <!-- value>$verify-property-prefix:/{DAV:}resourcetype/{http://calendarserver.org/ns/}shared</value -->
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}read</value>
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}write</value>
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}bind</value>
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}unbind</value>
+                                               <!-- value>$verify-property-prefix:/{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp/{urn:ietf:params:xml:ns:caldav}transparent</value -->
+                                       </arg>
+                                       <arg>
+                                               <name>notexists</name>
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}admin</value>
+                                               <value>$verify-property-prefix:/{DAV:}current-user-privilege-set/{DAV:}privilege/{DAV:}all</value>
+                                       </arg>
+                               </verify>
+                       </request>
+               </test>
+               <test name='16'>
+                       <description>Shared calendar no longer exists Depth:1</description>
+                       <request user="$userid2:" pswd="$pswd2:">
+                               <method>PROPFIND</method>
+                               <ruri>$calendarhome2:</ruri>
+                               <header>
+                                       <name>Depth</name>
+                                       <value>1</value>
+                               </header>
+                               <data>
+                                       <content-type>text/xml; charset=utf-8</content-type>
+                                       <filepath>Resource/CalDAV/sharing/calendars/read-write/4.xml</filepath>
+                               </data>
+                               <verify>
+                                       <callback>xmlElementMatch</callback>
+                                       <arg>
+                                               <name>notexists</name>
+                                               <value>$multistatus-response-prefix:[^{DAV:}href=$calendarhome2:/shared_shared_by_user01/]</value>
+                                       </arg>
+                               </verify>
+                       </request>
+               </test>
        </test-suite>
 
        <!--
diff --git a/apps/dav/tests/unit/caldav/calendartest.php b/apps/dav/tests/unit/caldav/calendartest.php
new file mode 100644 (file)
index 0000000..561ce6c
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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\Unit\CalDAV;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\Calendar;
+use Test\TestCase;
+
+class CalendarTest extends TestCase {
+
+       public function testDelete() {
+               /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */
+               $backend = $this->getMockBuilder('OCA\DAV\CalDAV\CalDavBackend')->disableOriginalConstructor()->getMock();
+               $backend->expects($this->once())->method('updateShares');
+               $calendarInfo = [
+                       '{http://owncloud.org/ns}owner-principal' => 'user1',
+                       'principaluri' => 'user2',
+               ];
+               $c = new Calendar($backend, $calendarInfo);
+               $c->delete();
+       }
+}