All Data Structures Functions Variables Pages
ApiRestPermissionTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  public function testListDefault()
43  {
44  $super = User::getByUsername('super');
45  Yii::app()->user->userModel = $super;
46  ZurmoConfigurationUtil::setByUserAndModuleName($super, 'ZurmoModule', 'defaultPermissionSetting', null);
47  ZurmoConfigurationUtil::setByUserAndModuleName($super, 'ZurmoModule', 'defaultPermissionGroupSetting', null);
48  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting',
49  false));
51  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
52 
53  $authenticationData = $this->login();
54  $headers = array(
55  'Accept: application/json',
56  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
57  'ZURMO_TOKEN: ' . $authenticationData['token'],
58  'ZURMO_API_REQUEST_TYPE: REST',
59  );
60  $response = $this->listDefaultPermissionsForCurrentUser($headers);
61  $response = json_decode($response, true);
62  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
63  $this->assertArrayHasKey('data', $response);
64  $this->assertCount(2, $response['data']);
65  $this->assertArrayHasKey('owner', $response['data']);
66  $this->assertCount(1, $response['data']['owner']);
67  $this->assertArrayHasKey('id', $response['data']['owner']);
68  $this->assertEquals($super->id, $response['data']['owner']['id']);
69 
70  $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']);
71  $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']);
72  $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']);
73  $this->assertEquals(1, $response['data']['explicitReadWriteModelPermissions']['type']);
74  $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']);
75  $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']);
76  }
77 
81  public function testListDefaultAfterChange()
82  {
83  $super = User::getByUsername('super');
84  Yii::app()->user->userModel = $super;
85  $authenticationData = $this->login();
86  $headers = array(
87  'Accept: application/json',
88  'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'],
89  'ZURMO_TOKEN: ' . $authenticationData['token'],
90  'ZURMO_API_REQUEST_TYPE: REST',
91  );
92 
93  // change default permissions to a specific group, doesn't matter if it does not exist.
95  $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP;
96  $form->defaultPermissionGroupSetting = 6;
98  unset($form);
99  // validate that settings were saved.
101  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
102  $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($super,
103  'defaultPermissionGroupSetting', false), 6);
104 
105  $response = $this->listDefaultPermissionsForCurrentUser($headers);
106  $response = json_decode($response, true);
107  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
108  $this->assertArrayHasKey('data', $response);
109  $this->assertCount(2, $response['data']);
110  $this->assertArrayHasKey('owner', $response['data']);
111  $this->assertCount(1, $response['data']['owner']);
112  $this->assertArrayHasKey('id', $response['data']['owner']);
113  $this->assertEquals($super->id, $response['data']['owner']['id']);
114 
115  $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']);
116  $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']);
117  $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']);
118  $this->assertEquals(2, $response['data']['explicitReadWriteModelPermissions']['type']);
119  $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']);
120  $this->assertEquals(6, $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']);
121 
122  // change default permissions to owner only.
124  $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER;
126  unset($form);
127  // validate that settings were saved.
129  UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER);
130  $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($super, 'defaultPermissionGroupSetting',
131  false));
132 
133  $response = $this->listDefaultPermissionsForCurrentUser($headers);
134  $response = json_decode($response, true);
135  $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
136  $this->assertArrayHasKey('data', $response);
137  $this->assertCount(2, $response['data']);
138  $this->assertArrayHasKey('owner', $response['data']);
139  $this->assertCount(1, $response['data']['owner']);
140  $this->assertArrayHasKey('id', $response['data']['owner']);
141  $this->assertEquals($super->id, $response['data']['owner']['id']);
142 
143  $this->assertArrayHasKey('explicitReadWriteModelPermissions', $response['data']);
144  $this->assertCount(2, $response['data']['explicitReadWriteModelPermissions']);
145  $this->assertArrayHasKey('type', $response['data']['explicitReadWriteModelPermissions']);
146  $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['type']);
147  $this->assertArrayHasKey('nonEveryoneGroup', $response['data']['explicitReadWriteModelPermissions']);
148  $this->assertEquals('', $response['data']['explicitReadWriteModelPermissions']['nonEveryoneGroup']);
149  }
150 
151  protected function listDefaultPermissionsForCurrentUser($headers)
152  {
153  $response = $this->createApiCallWithRelativeUrl('listDefault/', 'GET', $headers);
154  return $response;
155  }
156 
157  protected function getModuleBaseApiUrl()
158  {
159  return 'zurmo/permission/api/';
160  }
161 
162  protected function getApiControllerClassName()
163  {
164  }
165  }
166 ?>
static resolveAndGetDefaultPermissionSetting(User $user)
static getByUsername($username)
Definition: User.php:49
static setConfigurationFromForm(UserConfigurationForm $form, User $user)
static setByUserAndModuleName($user, $moduleName, $key, $value, $cache=true)
static makeFormFromUserConfigurationByUser(User $user)
static resolveAndGetValue(User $user, $key, $returnBoolean=true)
Generated on Sat Feb 22 2020 07:10:28