protected function renderContent()
 {
     $url = $this->getCreateMeetingUrl();
     $content = ZurmoHtml::openTag('div', array('class' => $this->getIconName()));
     $content .= $this->getMessageContent();
     if (RightsUtil::doesUserHaveAllowByRightName('MeetingsModule', MeetingsModule::getCreateRight(), Yii::app()->user->userModel)) {
         $content .= ZurmoHtml::link(ZurmoHtml::wrapLabel($this->getCreateLinkDisplayLabel()), $url, array('class' => 'z-button green-button'));
     }
     $content .= ZurmoHtml::closeTag('div');
     return $content;
 }
Beispiel #2
0
 /**
  * @depends testListMeetings
  */
 public function testUnprivilegedUserViewUpdateDeleteMeetings()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notAllowedUser = UserTestHelper::createBasicUser('Steven');
     $notAllowedUser->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $saved = $notAllowedUser->save();
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $this->assertTrue($everyoneGroup->save());
     $meetings = Meeting::getByName('Michael Meeting');
     $this->assertEquals(1, count($meetings));
     $data['description'] = "Some new description 2";
     // Test with unprivileged user to view, edit and delete account.
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/read/' . $meetings[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/update/' . $meetings[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/delete/' . $meetings[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     //now check if user have rights, but no permissions.
     $notAllowedUser->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $notAllowedUser->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $notAllowedUser->setRight('MeetingsModule', MeetingsModule::getDeleteRight());
     $saved = $notAllowedUser->save();
     $this->assertTrue($saved);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/read/' . $meetings[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/update/' . $meetings[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/delete/' . $meetings[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     // Allow everyone group to read/write meeting
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     unset($data);
     $data['explicitReadWriteModelPermissions'] = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/update/' . $meetings[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/read/' . $meetings[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     unset($data);
     $data['description'] = "Some new description 3";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/update/' . $meetings[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals("Some new description 3", $response['data']['description']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/delete/' . $meetings[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     // Test with privileged user
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Test Delete
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/delete/' . $meetings[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/meetings/meeting/api/read/' . $meetings[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
 }
 /**
  * @depends testRegularUserAllDefaultControllerActions
  */
 public function testRegularUserCreateActionForWorkflow()
 {
     // TODO: @Shoaibi/@Jason: Medium: Even if a user doesn't have module permission he can sent that modelClassName in POST
     // nobody needs access to meetings ans contact to have that in ddl.
     $this->user->setRight('ContactsModule', ContactsModule::getAccessRight());
     $this->user->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $this->assertTrue($this->user->save());
     // Create a new emailTemplate and test validator.
     $this->setGetArray(array('type' => EmailTemplate::TYPE_WORKFLOW));
     $this->setPostArray(array('EmailTemplate' => array('type' => EmailTemplate::TYPE_WORKFLOW, 'name' => 'New Test Workflow EmailTemplate', 'subject' => 'New Test Subject')));
     $content = $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/create');
     $this->assertTrue(strpos($content, 'Create Email Template') !== false);
     $this->assertFalse(strpos($content, '<select name="EmailTemplate[type]" id="EmailTemplate_type">') !== false);
     $this->assertTrue(strpos($content, '<select name="EmailTemplate[modelClassName]" id="EmailTemplate_modelClassName_value"') !== false);
     $this->assertTrue(strpos($content, 'Please provide at least one of the contents field.') !== false);
     $this->assertTrue(strpos($content, 'Module cannot be blank.') !== false);
     // Create a new emailTemplate and test merge tags validator.
     $this->setPostArray(array('EmailTemplate' => array('type' => EmailTemplate::TYPE_WORKFLOW, 'modelClassName' => 'Meeting', 'name' => 'New Test Workflow EmailTemplate', 'subject' => 'New Test Subject', 'textContent' => 'This is text content [[INVALID^TAG]]', 'htmlContent' => 'This is Html content [[INVALIDTAG]]')));
     $content = $this->runControllerWithNoExceptionsAndGetContent('emailTemplates/default/create');
     $this->assertTrue(strpos($content, 'Create Email Template') !== false);
     $this->assertFalse(strpos($content, '<select name="EmailTemplate[type]" id="EmailTemplate_type">') !== false);
     $this->assertTrue(strpos($content, '<select name="EmailTemplate[modelClassName]" id="EmailTemplate_modelClassName_value">') !== false);
     $this->assertTrue(strpos($content, '<option value="Meeting" selected="selected">Meetings</option>') !== false);
     $this->assertTrue(strpos($content, 'INVALID^TAG') !== false);
     $this->assertTrue(strpos($content, 'INVALIDTAG') !== false);
     $this->assertEquals(2, substr_count($content, 'INVALID^TAG'));
     $this->assertEquals(2, substr_count($content, 'INVALIDTAG'));
     // Create a new emailTemplate and save it.
     $this->setPostArray(array('EmailTemplate' => array('type' => EmailTemplate::TYPE_WORKFLOW, 'name' => 'New Test Workflow EmailTemplate', 'modelClassName' => 'Contact', 'subject' => 'New Test Subject [[FIRST^NAME]]', 'textContent' => 'New Text Content [[FIRST^NAME]]')));
     $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('emailTemplates/default/create');
     $emailTemplateId = self::getModelIdByModelNameAndName('EmailTemplate', 'New Test Workflow EmailTemplate');
     $emailTemplate = EmailTemplate::getById($emailTemplateId);
     $this->assertTrue($emailTemplate->id > 0);
     $this->assertEquals('New Test Subject [[FIRST^NAME]]', $emailTemplate->subject);
     $this->assertEquals('New Text Content [[FIRST^NAME]]', $emailTemplate->textContent);
     $this->assertTrue($emailTemplate->owner == $this->user);
     $compareRedirectUrl = Yii::app()->createUrl('emailTemplates/default/details', array('id' => $emailTemplate->id));
     $this->assertEquals($compareRedirectUrl, $redirectUrl);
     $emailTemplates = EmailTemplate::getAll();
     $this->assertEquals(1, count($emailTemplates));
 }
 /**
  * Override to add link for meeting creation
  */
 protected function renderContent()
 {
     $content = '';
     if (RightsUtil::doesUserHaveAllowByRightName('MeetingsModule', MeetingsModule::getCreateRight(), Yii::app()->user->userModel)) {
         $spanContent = ZurmoHtml::tag('span', array('class' => 'z-label'), Zurmo::t('MeetingsModule', 'Create Meeting'));
         $linkContent = ZurmoHtml::link($spanContent, $this->getCreateMeetingUrl(), array('class' => 'secondary-button'));
         $divContent = ZurmoHtml::tag('div', array('class' => 'portlet-toolbar'), $linkContent);
         $content = ZurmoHtml::tag('div', array('class' => 'view-toolbar-container clearfix'), $divContent);
     }
     $content .= parent::renderContent();
     return $content;
 }
 public function testSuperUserMeetingDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Load AttributesList for Meeting module.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');
     //Load ModuleLayoutsList for Meeting module.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');
     //Load ModuleEdit view for each applicable module.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleEdit');
     //Now validate save with failed validation.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'MeetingsModuleForm' => $this->createModuleEditBadValidationPostData()));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertTrue(strlen($content) > 50);
     //approximate, but should definetely be larger than 50.
     //Now validate save with successful validation.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'MeetingsModuleForm' => $this->createModuleEditGoodValidationPostData('meeting new name')));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertEquals('[]', $content);
     //Now save successfully.
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule'));
     $this->setPostArray(array('save' => 'Save', 'MeetingsModuleForm' => $this->createModuleEditGoodValidationPostData('meeting new name')));
     $this->runControllerWithRedirectExceptionAndGetContent('designer/default/moduleEdit');
     //Now confirm everything did in fact save correctly.
     $this->assertEquals('Meeting New Name', MeetingsModule::getModuleLabelByTypeAndLanguage('Singular'));
     $this->assertEquals('Meeting New Names', MeetingsModule::getModuleLabelByTypeAndLanguage('Plural'));
     $this->assertEquals('meeting new name', MeetingsModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
     $this->assertEquals('meeting new names', MeetingsModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
     //Load LayoutEdit for each applicable module and applicable layout.
     $this->resetPostArray();
     $this->setGetArray(array('moduleClassName' => 'MeetingsModule', 'viewClassName' => 'MeetingEditAndDetailsView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
 }
 /**
  * Test if all newly created items was pulled from read permission tables via API.
  * Please note that here we do not test if data are inserted in read permission tables correctly, that is
  * part of read permission subscription tests
  * @throws NotFoundException
  * @throws NotImplementedException
  * @throws NotSupportedException
  */
 public function testGetCreatedMeetings()
 {
     $timestamp = time();
     sleep(1);
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $lisa = UserTestHelper::createBasicUser('Lisa');
     $lisa->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $lisa->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $this->assertTrue($lisa->save());
     $this->deleteAllModelsAndRecordsFromReadPermissionTable('Meeting');
     $job = new ReadPermissionSubscriptionUpdateJob();
     ReadPermissionsOptimizationUtil::rebuild();
     $meeting1 = MeetingTestHelper::createMeetingByNameForOwner('Meeting1', $super);
     sleep(1);
     $meeting2 = MeetingTestHelper::createMeetingByNameForOwner('Meeting2', $super);
     sleep(1);
     $meeting3 = MeetingTestHelper::createMeetingByNameForOwner('Meeting3', $super);
     sleep(1);
     $this->assertTrue($job->run());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($meeting1->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($meeting1->name, $response['data']['items'][0]['name']);
     $this->assertEquals($meeting2->id, $response['data']['items'][1]['id']);
     $this->assertEquals($super->id, $response['data']['items'][1]['owner']['id']);
     $this->assertEquals($meeting2->name, $response['data']['items'][1]['name']);
     $data = array('sinceTimestamp' => 0, 'pagination' => array('pageSize' => 2, 'page' => 2));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(2, $response['data']['currentPage']);
     $this->assertEquals($meeting3->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($meeting3->name, $response['data']['items'][0]['name']);
     // Change owner of $contact1, it should appear in Lisa's created contacts
     $meeting1->owner = $lisa;
     $this->assertTrue($meeting1->save());
     sleep(1);
     $this->assertTrue($job->run());
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(2, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($meeting2->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($meeting2->name, $response['data']['items'][0]['name']);
     $this->assertEquals($meeting3->id, $response['data']['items'][1]['id']);
     $this->assertEquals($super->id, $response['data']['items'][1]['owner']['id']);
     $this->assertEquals($meeting3->name, $response['data']['items'][1]['name']);
     $authenticationData = $this->login('lisa', 'lisa');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(1, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($meeting1->id, $response['data']['items'][0]['id']);
     $this->assertEquals($lisa->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($meeting1->name, $response['data']['items'][0]['name']);
 }
Beispiel #7
0
 public function testGetModelClassNames()
 {
     $modelClassNames = MeetingsModule::getModelClassNames();
     $this->assertEquals(1, count($modelClassNames));
     $this->assertEquals('Meeting', $modelClassNames[0]);
 }
 /**
  * For each dupeModel add total ammount of Notes, Tasks, Emails and Meetings
  * @param $chart
  */
 protected function resolveDataForChart(&$chart)
 {
     $notes = array('category' => NotesModule::getModuleLabelByTypeAndLanguage('Plural'));
     $tasks = array('category' => TasksModule::getModuleLabelByTypeAndLanguage('Plural'));
     $emails = array('category' => EmailMessagesModule::getModuleLabelByTypeAndLanguage('Plural'));
     $meetings = array('category' => MeetingsModule::getModuleLabelByTypeAndLanguage('Plural'));
     foreach ($this->dupeModels as $dupeModel) {
         $itemId = $dupeModel->getClassId('Item');
         $notes['model-' . $dupeModel->id] = LatestActivitiesUtil::getCountByModelClassName('Note', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
         $tasks['model-' . $dupeModel->id] = LatestActivitiesUtil::getCountByModelClassName('Task', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
         $emails['model-' . $dupeModel->id] = LatestActivitiesUtil::getCountByModelClassName('EmailMessage', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
         $meetings['model-' . $dupeModel->id] = LatestActivitiesUtil::getCountByModelClassName('Meeting', array($itemId), LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL);
     }
     $chart->data = array($notes, $tasks, $emails, $meetings);
 }
 protected function resolveConfirmAlertInHtmlOptions($htmlOptions)
 {
     $htmlOptions['confirm'] = Zurmo::t('Core', 'Are you sure you want to delete this {modelLabel}?', array('{modelLabel}' => MeetingsModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')));
     return $htmlOptions;
 }
 public function testGetMeetingWithAttendees()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $evelina = UserTestHelper::createBasicUser('Evelina');
     $amelia = UserTestHelper::createBasicUser('Amelia');
     $amelia->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($amelia->save());
     $contact1 = ContactTestHelper::createContactByNameForOwner('TestContact3', $super);
     $contact2 = ContactTestHelper::createContactByNameForOwner('TestContact4', $super);
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $meeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 2 With User Attendees', $super);
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertTrue(isset($response['data']['attendees']));
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertFalse(isset($response['data']['attendees']['Organizer']['email']));
     $meeting->activityItems->add($contact1);
     $meeting->activityItems->add($contact2);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals($contact2->primaryEmail->emailAddress, $response['data']['attendees']['Contact'][1]['email']);
     $meeting->userAttendees->add($evelina);
     $meeting->userAttendees->add($amelia);
     $this->assertTrue($meeting->save());
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $meeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(2, count($response['data']['attendees']['Contact']));
     $this->assertEquals($contact1->id, $response['data']['attendees']['Contact'][0]['id']);
     $this->assertEquals($contact1->firstName, $response['data']['attendees']['Contact'][0]['firstName']);
     $this->assertEquals($contact1->lastName, $response['data']['attendees']['Contact'][0]['lastName']);
     $this->assertEquals($contact2->id, $response['data']['attendees']['Contact'][1]['id']);
     $this->assertEquals($contact2->firstName, $response['data']['attendees']['Contact'][1]['firstName']);
     $this->assertEquals($contact2->lastName, $response['data']['attendees']['Contact'][1]['lastName']);
     $this->assertEquals(2, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertEquals($amelia->id, $response['data']['attendees']['User'][1]['id']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['attendees']['User'][1]['email']);
     $this->assertEquals($amelia->firstName, $response['data']['attendees']['User'][1]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['attendees']['User'][1]['lastName']);
     $this->assertEquals($amelia->username, $response['data']['attendees']['User'][1]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($super->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($super->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($super->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($super->username, $response['data']['attendees']['Organizer']['username']);
     // Test with opportunity and account activity items
     $account = AccountTestHelper::createAccountByNameForOwner('Account 2', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('TestOpportunity 2', $super);
     $meeting2 = MeetingTestHelper::createMeetingByNameForOwner('Meeting 3 With Account and Opportunity', $super);
     $meeting2->activityItems->add($account);
     $meeting2->activityItems->add($opportunity);
     $this->assertTrue($meeting2->save());
     $searchParams = array('pagination' => array('page' => 1, 'pageSize' => 3), 'search' => array('name' => 'Meeting 3 With Account and Opportunity'), 'sort' => 'name');
     $searchParamsQuery = http_build_query($searchParams);
     $response = $this->createApiCallWithRelativeUrl('list/filter/' . $searchParamsQuery, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(1, count($response['data']['items']));
     $this->assertEquals($account->id, $response['data']['items'][0]['attendees']['Account'][0]['id']);
     $this->assertEquals($account->name, $response['data']['items'][0]['attendees']['Account'][0]['name']);
     $this->assertEquals($opportunity->id, $response['data']['items'][0]['attendees']['Opportunity'][0]['id']);
     $this->assertEquals($opportunity->name, $response['data']['items'][0]['attendees']['Opportunity'][0]['name']);
     // Test with regular user if he can get user attendees
     $michael = UserTestHelper::createBasicUser('Michael');
     $michael->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($michael->save());
     $michael->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $michael->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $michael->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $saved = $michael->save();
     $this->assertTrue($saved);
     $michaelMeeting = MeetingTestHelper::createMeetingByNameForOwner('Meeting 4 With User', $michael);
     $michaelMeeting->userAttendees->add($evelina);
     $this->assertTrue($michaelMeeting->save());
     $authenticationData = $this->login('michael', 'michael');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('read/?id=' . $michaelMeeting->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals(1, count($response['data']['attendees']['User']));
     $this->assertEquals($evelina->id, $response['data']['attendees']['User'][0]['id']);
     $this->assertEquals($evelina->firstName, $response['data']['attendees']['User'][0]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['attendees']['User'][0]['lastName']);
     $this->assertEquals($evelina->username, $response['data']['attendees']['User'][0]['username']);
     $this->assertTrue(isset($response['data']['attendees']['Organizer']));
     $this->assertEquals($michael->id, $response['data']['attendees']['Organizer']['id']);
     $this->assertEquals($michael->firstName, $response['data']['attendees']['Organizer']['firstName']);
     $this->assertEquals($michael->lastName, $response['data']['attendees']['Organizer']['lastName']);
     $this->assertEquals($michael->username, $response['data']['attendees']['Organizer']['username']);
     $this->assertEquals($michael->primaryEmail->emailAddress, $response['data']['attendees']['Organizer']['email']);
 }
 public function testSearchUsersByEmails()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $evelina = UserTestHelper::createBasicUser('Evelina');
     $evelina->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($evelina->save());
     $amelia = UserTestHelper::createBasicUser('Amelia');
     $amelia->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($amelia->save());
     $samantha = UserTestHelper::createBasicUser('Samantha');
     $samantha->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($samantha->save());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('searchUsersByEmails/', 'POST', $headers, array());
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('Please provide data.', $response['message']);
     $data['email'] = array('*****@*****.**');
     $response = $this->createApiCallWithRelativeUrl('searchUsersByEmails/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('Emails parameters must exist, must be an array and must contain at least one email address.', $response['message']);
     $data['emails'] = array('*****@*****.**');
     $response = $this->createApiCallWithRelativeUrl('searchUsersByEmails/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertNotEmpty($response['data']);
     $this->assertEmpty($response['data']['users']);
     $data['emails'] = array('*****@*****.**');
     $response = $this->createApiCallWithRelativeUrl('searchUsersByEmails/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertNotEmpty($response['data']);
     $this->assertNotEmpty($response['data']['users']);
     $this->assertEquals(1, count($response['data']['users']));
     $this->assertEquals($amelia->id, $response['data']['users'][0]['id']);
     $this->assertEquals($amelia->username, $response['data']['users'][0]['username']);
     $this->assertEquals($amelia->firstName, $response['data']['users'][0]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['users'][0]['lastName']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['users'][0]['email']);
     // Now test with regular user
     $michael = UserTestHelper::createBasicUser('Michael');
     $michael->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $michael->setRight('MeetingsModule', MeetingsModule::getAccessRight());
     $michael->setRight('MeetingsModule', MeetingsModule::getCreateRight());
     $saved = $michael->save();
     $this->assertTrue($saved);
     $authenticationData = $this->login('michael', 'michael');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data['emails'] = array('*****@*****.**', '*****@*****.**');
     $response = $this->createApiCallWithRelativeUrl('searchUsersByEmails/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertNotEmpty($response['data']);
     $this->assertNotEmpty($response['data']['users']);
     $this->assertEquals(2, count($response['data']['users']));
     $this->assertEquals($amelia->id, $response['data']['users'][0]['id']);
     $this->assertEquals($amelia->username, $response['data']['users'][0]['username']);
     $this->assertEquals($amelia->firstName, $response['data']['users'][0]['firstName']);
     $this->assertEquals($amelia->lastName, $response['data']['users'][0]['lastName']);
     $this->assertEquals($amelia->primaryEmail->emailAddress, $response['data']['users'][0]['email']);
     $this->assertEquals($evelina->id, $response['data']['users'][1]['id']);
     $this->assertEquals($evelina->username, $response['data']['users'][1]['username']);
     $this->assertEquals($evelina->firstName, $response['data']['users'][1]['firstName']);
     $this->assertEquals($evelina->lastName, $response['data']['users'][1]['lastName']);
     $this->assertEquals($evelina->primaryEmail->emailAddress, $response['data']['users'][1]['email']);
 }