/**
  * testInvitationExternalReply
  */
 public function testInvitationExternalReply()
 {
     $email = $email = $this->_getEmailAddress();
     $ics = file_get_contents(dirname(__FILE__) . '/files/invitation_reply_external_accepted.ics');
     $ics = preg_replace('/unittest@tine20\\.org/', $email, $ics);
     $iMIP = new Calendar_Model_iMIP(array('id' => Tinebase_Record_Abstract::generateUID(), 'ics' => $ics, 'method' => 'REPLY', 'originator' => '*****@*****.**'));
     $this->assertEquals(1, $iMIP->getEvent()->seq);
     $this->assertTrue(!empty($iMIP->getEvent()->last_modified_time));
     // force creation of external attendee
     $externalAttendee = new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $iMIP->getEvent()->attendee->getFirstRecord()->user_id, 'status' => Calendar_Model_Attender::STATUS_NEEDSACTION));
     // create matching event
     $event = new Calendar_Model_Event(array('summary' => 'TEST7', 'dtstart' => '2011-11-30 14:00:00', 'dtend' => '2011-11-30 15:00:00', 'description' => 'Early to bed and early to rise, makes a men healthy, wealthy and wise ...', 'attendee' => $this->_getAttendee(), 'organizer' => Tinebase_Core::getUser()->contact_id, 'uid' => 'a8d10369e051094ae9322bd65e8afecac010bfc8'));
     $event->attendee->addRecord($externalAttendee);
     $event = Calendar_Controller_Event::getInstance()->create($event);
     $this->_eventIdsToDelete[] = $event->getId();
     // TEST NORMAL REPLY
     try {
         $this->_iMIPFrontend->autoProcess($iMIP);
     } catch (Exception $e) {
         $this->fail('TEST NORMAL REPLY autoProcess throws Exception: ' . $e);
     }
     unset($iMIP->existing_event);
     $updatedEvent = Calendar_Controller_Event::getInstance()->get($event->getId());
     $updatedExternalAttendee = Calendar_Model_Attender::getAttendee($updatedEvent->attendee, $externalAttendee);
     $this->assertEquals(3, count($updatedEvent->attendee));
     $this->assertEquals(Calendar_Model_Attender::STATUS_ACCEPTED, $updatedExternalAttendee->status, 'status not updated');
     // TEST ACCEPTABLE NON RECENT REPLY
     $updatedExternalAttendee->status = Calendar_Model_Attender::STATUS_NEEDSACTION;
     Calendar_Controller_Event::getInstance()->attenderStatusUpdate($updatedEvent, $updatedExternalAttendee, $updatedExternalAttendee->status_authkey);
     try {
         $iMIP->preconditionsChecked = false;
         $this->_iMIPFrontend->autoProcess($iMIP);
     } catch (Exception $e) {
         $this->fail('TEST ACCEPTABLE NON RECENT REPLY autoProcess throws Exception: ' . $e);
     }
     unset($iMIP->existing_event);
     $updatedEvent = Calendar_Controller_Event::getInstance()->get($event->getId());
     $updatedExternalAttendee = Calendar_Model_Attender::getAttendee($updatedEvent->attendee, $externalAttendee);
     $this->assertEquals(3, count($updatedEvent->attendee));
     $this->assertEquals(Calendar_Model_Attender::STATUS_ACCEPTED, $updatedExternalAttendee->status, 'status not updated');
     // check if attendee are resolved
     $existingEvent = $this->_iMIPFrontend->getExistingEvent($iMIP);
     $this->assertTrue($iMIP->existing_event->attendee instanceof Tinebase_Record_RecordSet);
     $this->assertEquals(3, count($iMIP->existing_event->attendee));
     // TEST NON ACCEPTABLE NON RECENT REPLY
     $iMIP->preconditionsChecked = false;
     try {
         $this->_iMIPFrontend->autoProcess($iMIP);
         $this->fail('autoProcess should throw Calendar_Exception_iMIP');
     } catch (Calendar_Exception_iMIP $cei) {
         $this->assertContains('iMIP preconditions failed: RECENT', $cei->getMessage());
     }
 }
Exemple #2
0
 /**
  * reply precondition
  *
  * @TODO an internal reply should trigge a RECENT precondition
  * @TODO distinguish RECENT and PROCESSED preconditions?
  * 
  * @param  Calendar_Model_iMIP   $_iMIP
  * @return boolean
  */
 protected function _checkReplyPreconditions($_iMIP)
 {
     $result = TRUE;
     $existingEvent = $_iMIP->getExistingEvent();
     if (!$existingEvent) {
         $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_EVENTEXISTS, "cannot process REPLY to non existent/invisible event");
         $result = FALSE;
     }
     $iMIPAttenderIdx = $_iMIP->getEvent()->attendee instanceof Tinebase_Record_RecordSet ? array_search($_iMIP->originator, $_iMIP->getEvent()->attendee->getEmail()) : FALSE;
     $iMIPAttender = $iMIPAttenderIdx !== FALSE ? $_iMIP->getEvent()->attendee[$iMIPAttenderIdx] : NULL;
     $iMIPAttenderStatus = $iMIPAttender ? $iMIPAttender->status : NULL;
     $eventAttenderIdx = $existingEvent->attendee instanceof Tinebase_Record_RecordSet ? array_search($_iMIP->originator, $existingEvent->attendee->getEmail()) : FALSE;
     $eventAttender = $eventAttenderIdx !== FALSE ? $existingEvent->attendee[$eventAttenderIdx] : NULL;
     $eventAttenderStatus = $eventAttender ? $eventAttender->status : NULL;
     if ($_iMIP->getEvent()->isObsoletedBy($existingEvent)) {
         // allow non RECENT replies if no reschedule and STATUS_NEEDSACTION
         if ($eventAttenderStatus != Calendar_Model_Attender::STATUS_NEEDSACTION || $existingEvent->isRescheduled($_iMIP->getEvent())) {
             $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_RECENT, "old iMIP message");
             $result = FALSE;
         }
     }
     if (!is_null($iMIPAttenderStatus) && $iMIPAttenderStatus == $eventAttenderStatus) {
         $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_TOPROCESS, "this REPLY was already processed");
         $result = FALSE;
     }
     if (!$eventAttender) {
         $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_ORIGINATOR, "originator is not attendee in existing event -> party crusher?");
         $result = FALSE;
     }
     if (!$iMIPAttender) {
         $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_ORIGINATOR, "originator is not attendee in iMIP transaction -> spoofing attempt?");
         $result = FALSE;
     }
     if (!$this->_assertOrganizer($_iMIP, TRUE, FALSE, TRUE)) {
         $result = FALSE;
     }
     return $result;
 }