0012220: creating event exceptions with group attendee loose groupitself
authorCornelius Weiß <c.weiss@metaways.de>
Tue, 20 Sep 2016 16:25:00 +0000 (18:25 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 27 Sep 2016 12:40:42 +0000 (14:40 +0200)
Change-Id: Iaf5da9217d0d35892cbdafd4a92b038e5c3e53f7
Reviewed-on: http://gerrit.tine20.com/customers/3597
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Frontend/ActiveSyncTest.php
tests/tine20/Calendar/Frontend/files/event_with_group_attendee.xml [new file with mode: 0644]
tine20/ActiveSync/Frontend/Abstract.php
tine20/Calendar/Frontend/ActiveSync.php
tine20/Calendar/Model/Attender.php

index 1cf7f5b..5bed457 100644 (file)
@@ -1291,4 +1291,37 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMA
         $this->assertEquals($syncrotonEventtoUpdate->exceptions[0]->startTime->toString(), $updatedSyncrotonEvent->exceptions[0]->startTime->toString());
         $this->assertEquals(2, count($updatedSyncrotonEvent->attendees), 'event: ' . var_export($updatedSyncrotonEvent->attendees, TRUE));
     }
+
+    public function testCreateUpdateGroupEvents()
+    {
+        $syncrotonFolder = $this->testCreateFolder();
+        Tinebase_Core::getPreference('Calendar')->setValue(Calendar_Preference::DEFAULTCALENDAR, $syncrotonFolder->serverId);
+
+        $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup();
+        $defaultUserGroupMembers = Tinebase_Group::getInstance()->getGroupMembers($defaultUserGroup->getId());
+
+        // create event with default user group (without explicit groupmembers)
+        $xml = new SimpleXMLElement(str_replace(array(
+            'usersgroupid',
+        ), $defaultUserGroup->getId(), file_get_contents(__DIR__ . '/files/event_with_group_attendee.xml')));
+        $syncrotonEvent = new Syncroton_Model_Event($xml->Collections->Collection->Commands->Change[0]->ApplicationData);
+        $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), Tinebase_DateTime::now());
+        $serverId = $controller->createEntry($syncrotonFolder->serverId, $syncrotonEvent);
+
+        // assert created group & groupmembers
+        $syncrotonEventtoUpdate = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder->serverId)), $serverId);
+        $this->assertCount(count($defaultUserGroupMembers) + 1, $syncrotonEventtoUpdate->attendees, 'groupmembers not resolved');
+        $this->assertCount(count($defaultUserGroupMembers) + 1, $syncrotonEventtoUpdate->exceptions[0]->attendees, 'groupmembers not resolved');
+
+        // update event
+        $syncrotonEventtoUpdate->exceptions[0]->subject = 'update';
+        $syncTimestamp = Calendar_Controller_Event::getInstance()->get($serverId)->last_modified_time;
+        $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), $syncTimestamp);
+        $serverId = $controller->updateEntry($syncrotonFolder->serverId, $serverId, $syncrotonEventtoUpdate);
+
+        // assert updated group & groupmembers
+        $updatedSyncrotonEvent = $controller->getEntry(new Syncroton_Model_SyncCollection(array('collectionId' => $syncrotonFolder->serverId)), $serverId);
+        $this->assertCount(count($defaultUserGroupMembers) + 1, $updatedSyncrotonEvent->attendees, 'groupmembers not resolved');
+        $this->assertCount(count($defaultUserGroupMembers) + 1, $updatedSyncrotonEvent->exceptions[0]->attendees, 'groupmembers not resolved');
+    }
 }
diff --git a/tests/tine20/Calendar/Frontend/files/event_with_group_attendee.xml b/tests/tine20/Calendar/Frontend/files/event_with_group_attendee.xml
new file mode 100644 (file)
index 0000000..b7bbaa2
--- /dev/null
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?><!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
+<Sync xmlns="uri:AirSync" xmlns:Calendar="uri:Calendar">
+    <Collections>
+        <Collection>
+            <Class>Calendar</Class>
+            <SyncKey>9</SyncKey>
+            <CollectionId>41</CollectionId>
+            <DeletesAsMoves/>
+            <GetChanges/>
+            <WindowSize>50</WindowSize>
+            <Options><FilterType>5</FilterType></Options>
+            <Commands>
+                <Change>
+                    <ServerId>6de7cb687964dc6eea109cd81750177979362217</ServerId>
+                    <ApplicationData>
+                        <Calendar:Timezone>xP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAFAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAIAAAAAAAAAxP///w==</Calendar:Timezone>
+                        <Calendar:AllDayEvent>0</Calendar:AllDayEvent>
+                        <Calendar:BusyStatus>2</Calendar:BusyStatus>
+                        <Calendar:DtStamp>20121125T150537Z</Calendar:DtStamp>
+                        <Calendar:EndTime>20121123T160000Z</Calendar:EndTime>
+                        <Calendar:Sensitivity>2</Calendar:Sensitivity>
+                        <Calendar:Subject>Repeat</Calendar:Subject>
+                        <Calendar:StartTime>20121123T130000Z</Calendar:StartTime>
+                        <Calendar:UID>6de7cb687964dc6eea109cd81750177979362217</Calendar:UID>
+                        <Calendar:MeetingStatus>1</Calendar:MeetingStatus>
+                        <Calendar:Attendees>
+                            <Calendar:Attendee>
+                                <Calendar:Name>Users</Calendar:Name>
+                                <Calendar:Email>usersgroupid</Calendar:Email>
+                            </Calendar:Attendee>
+                        </Calendar:Attendees>
+                        <Calendar:Recurrence>
+                            <Calendar:Type>0</Calendar:Type><Calendar:Interval>1</Calendar:Interval><Calendar:Until>20121128T225959Z</Calendar:Until>
+                        </Calendar:Recurrence>
+                        <Calendar:Exceptions>
+                            <Calendar:Exception>
+                                <Calendar:Deleted>0</Calendar:Deleted>
+                                <Calendar:ExceptionStartTime>20121125T130000Z</Calendar:ExceptionStartTime>
+                                <Calendar:StartTime>20121125T140000Z</Calendar:StartTime>
+                                <Calendar:EndTime>20121125T170000Z</Calendar:EndTime>
+                                <Calendar:Subject>Repeat mal anders</Calendar:Subject>
+                                <Calendar:BusyStatus>2</Calendar:BusyStatus>
+                                <Calendar:AllDayEvent>0</Calendar:AllDayEvent>
+                                <Calendar:Attendees>
+                                    <Calendar:Attendee>
+                                        <Calendar:Name>Users</Calendar:Name>
+                                        <Calendar:Email>usersgroupid</Calendar:Email>
+                                    </Calendar:Attendee>
+                                </Calendar:Attendees>
+                            </Calendar:Exception>
+                            <Calendar:Exception>
+                                <Calendar:Deleted>1</Calendar:Deleted><Calendar:ExceptionStartTime>20121124T130000Z</Calendar:ExceptionStartTime></Calendar:Exception>
+                        </Calendar:Exceptions>
+                        <Calendar:Reminder>15</Calendar:Reminder>
+                        <Body xmlns="uri:AirSyncBase"><Type>1</Type><Data>Hello</Data></Body>
+                    </ApplicationData>
+                </Change>
+            </Commands>
+        </Collection>
+    </Collections>
+</Sync>
\ No newline at end of file
index bb40fe2..69af485 100644 (file)
@@ -265,7 +265,8 @@ abstract class ActiveSync_Frontend_Abstract implements Syncroton_Data_IData
     {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) 
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " create entry");
-        
+
+        $this->_assertContentControllerParams($folderId);
         $entry = $this->toTineModel($entry);
         
         // container_id gets set to personal folder in application specific controller if missing
index 9504dbc..6a7fac0 100644 (file)
@@ -605,7 +605,6 @@ class Calendar_Frontend_ActiveSync extends ActiveSync_Frontend_Abstract implemen
                             $lastName  = $attendee->name;
                         }
                         
-                        // @todo handle resources
                         $newAttendees[] = array(
                             'userType'  => Calendar_Model_Attender::USERTYPE_USER,
                             'firstName' => $firstName,
index c462f98..9f45791 100644 (file)
@@ -369,8 +369,21 @@ class Calendar_Model_Attender extends Tinebase_Record_Abstract
                         $newAttendee['userType'] = Calendar_Model_Attender::USERTYPE_GROUP;
                         $attendeeId = $lists->getFirstRecord()->group_id;
                     }
-                } 
-                
+                }
+
+                // does a list with this id exist?
+                if (! $attendeeId) {
+                    try {
+                        $group = Tinebase_Group::getInstance()->getGroupById($newAttendee['email']);
+                        if ($group) {
+                            $newAttendee['userType'] = Calendar_Model_Attender::USERTYPE_GROUP;
+                            $attendeeId = $group->getId();
+                        }
+                    } catch (Exception $e) {
+                        // do nothing
+                    }
+                    }
+
                 if (! $attendeeId) {
                     // autocreate a contact if allowed
                     $contact = self::resolveEmailToContact($newAttendee, $_implicitAddMissingContacts);