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']);
 }
 /**
  * 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 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']);
 }