public function testMatchingGetPermissionsForView()
 {
     $permissionsNames = ModulePermissionsEditViewUtil::getPermissionNamesForView();
     $permissions = ModulePermissionsEditViewUtil::getPermissionsForView();
     $this->assertEquals(count($permissionsNames), count($permissions));
     $this->assertEquals(3, count($permissionsNames));
 }
예제 #2
0
 public function actionEditModulePermissions($id)
 {
     $group = Group::getById(intval($id));
     $title = Zurmo::t('ZurmoModule', 'Record Permissions');
     $breadCrumbLinks = array(strval($group) => array('group/' . static::resolveBreadCrumbActionByGroup($group), 'id' => $id), $title);
     $data = PermissionsUtil::getAllModulePermissionsDataByPermitable($group);
     $permissionsForm = ModulePermissionsFormUtil::makeFormFromPermissionsData($data);
     $postVariableName = get_class($permissionsForm);
     if (isset($_POST[$postVariableName])) {
         $this->clearCaches();
         $castedPostData = ModulePermissionsFormUtil::typeCastPostData($_POST[$postVariableName]);
         $readyToSetPostData = ModulePermissionsEditViewUtil::resolveWritePermissionsFromArray($castedPostData);
         if (ModulePermissionsFormUtil::setPermissionsFromCastedPost($readyToSetPostData, $group)) {
             Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'Record Permissions Saved Successfully.'));
             $action = $this->resolveActionToGoToAfterSave($group);
             $this->redirect(array($this->getId() . '/' . $action, 'id' => $group->id));
             Yii::app()->end(0, false);
         }
     }
     $permissionsData = GroupModulePermissionsDataToEditViewAdapater::resolveData($data);
     $metadata = ModulePermissionsEditViewUtil::resolveMetadataFromData($permissionsData, ModulePermissionsEditAndDetailsView::getMetadata());
     $titleBarAndEditView = new GroupActionBarAndSecurityEditView($this->getId(), $this->getModule()->getId(), $permissionsForm, $group, $this->getModule()->getPluralCamelCasedName(), $metadata, 'ModulePermissionsEditAndDetailsView', 'GroupModulePermissionsEditMenu');
     $view = new GroupsPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $titleBarAndEditView, $breadCrumbLinks, 'GroupBreadCrumbView'));
     echo $view->render();
 }
 /**
  * @depends testSettingChangeOwnerChangePermissionFromPost
  */
 public function testModulePermissionsFormUtilSetRightsFromPost()
 {
     $group = Group::getByName('modulePermissionsGroup');
     $data = PermissionsUtil::getAllModulePermissionsDataByPermitable($group);
     $form = ModulePermissionsFormUtil::makeFormFromPermissionsData($data);
     $compareData = array('AccountsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => Permission::ALLOW, 'inherited' => null, 'actual' => Permission::ALLOW), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'ContactsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => Permission::ALLOW, 'actual' => Permission::ALLOW), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'LeadsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'MeetingsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'NotesModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'OpportunitiesModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'ContractsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'TasksModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'UsersModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)));
     $this->assertEquals($compareData['AccountsModule'], $form->data['AccountsModule']);
     $this->assertEquals($compareData['ContactsModule'], $form->data['ContactsModule']);
     $this->assertEquals($compareData['LeadsModule'], $form->data['LeadsModule']);
     $this->assertEquals($compareData['OpportunitiesModule'], $form->data['OpportunitiesModule']);
     $this->assertEquals($compareData['ContractsModule'], $form->data['ContractsModule']);
     $this->assertEquals($compareData['TasksModule'], $data['TasksModule']);
     $this->assertEquals($compareData['NotesModule'], $data['NotesModule']);
     $this->assertEquals($compareData['MeetingsModule'], $data['MeetingsModule']);
     $this->assertEquals($compareData['UsersModule'], $form->data['UsersModule']);
     $fakePost = array('LeadsModule__' . Permission::READ => strval(Permission::ALLOW), 'LeadsModule__' . Permission::WRITE => strval(Permission::ALLOW), 'AccountsModule__' . Permission::READ => '', 'OpportunitiesModule__' . Permission::DELETE => strval(Permission::DENY), 'ContractsModule__' . Permission::DELETE => strval(Permission::DENY));
     $validatedPost = ModulePermissionsFormUtil::typeCastPostData($fakePost);
     $readyToSetPostData = ModulePermissionsEditViewUtil::resolveWritePermissionsFromArray($validatedPost);
     $readyToSetPostDataCompare = array('LeadsModule__' . Permission::READ => strval(Permission::ALLOW), 'LeadsModule__' . Permission::CHANGE_OWNER => strval(Permission::ALLOW), 'LeadsModule__' . Permission::WRITE => strval(Permission::ALLOW), 'LeadsModule__' . Permission::CHANGE_PERMISSIONS => strval(Permission::ALLOW), 'AccountsModule__' . Permission::READ => '', 'OpportunitiesModule__' . Permission::DELETE => strval(Permission::DENY), 'ContractsModule__' . Permission::DELETE => strval(Permission::DENY));
     $this->assertEquals($readyToSetPostDataCompare, $readyToSetPostData);
     $saved = ModulePermissionsFormUtil::setPermissionsFromCastedPost($readyToSetPostData, $group);
     $this->assertTrue($saved);
     $group->forget();
     $group = Group::getByName('modulePermissionsGroup');
     $newItem = NamedSecurableItem::getByName('LeadsModule');
     $this->assertEquals(array(Permission::READ | Permission::WRITE | Permission::CHANGE_OWNER | Permission::CHANGE_PERMISSIONS, Permission::NONE), $newItem->getExplicitActualPermissions($group));
     $newItem->forget();
     $compareData = array('AccountsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'ContactsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => Permission::ALLOW, 'actual' => Permission::ALLOW), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'LeadsModule' => array(Permission::CHANGE_OWNER => array('explicit' => Permission::ALLOW, 'inherited' => null, 'actual' => Permission::ALLOW), Permission::CHANGE_PERMISSIONS => array('explicit' => Permission::ALLOW, 'inherited' => null, 'actual' => Permission::ALLOW), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => Permission::ALLOW, 'inherited' => null, 'actual' => Permission::ALLOW), Permission::WRITE => array('explicit' => Permission::ALLOW, 'inherited' => null, 'actual' => Permission::ALLOW)), 'MeetingsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'NotesModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'OpportunitiesModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => Permission::DENY, 'inherited' => null, 'actual' => Permission::DENY), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'ContractsModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => Permission::DENY, 'inherited' => null, 'actual' => Permission::DENY), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'TasksModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)), 'UsersModule' => array(Permission::CHANGE_OWNER => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::CHANGE_PERMISSIONS => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::DELETE => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::READ => array('explicit' => null, 'inherited' => null, 'actual' => null), Permission::WRITE => array('explicit' => null, 'inherited' => null, 'actual' => null)));
     $data = PermissionsUtil::getAllModulePermissionsDataByPermitable($group);
     $this->assertEquals($compareData['AccountsModule'], $data['AccountsModule']);
     $this->assertEquals($compareData['ContactsModule'], $data['ContactsModule']);
     $this->assertEquals($compareData['LeadsModule'], $data['LeadsModule']);
     $this->assertEquals($compareData['OpportunitiesModule'], $data['OpportunitiesModule']);
     $this->assertEquals($compareData['ContractsModule'], $data['ContractsModule']);
     $this->assertEquals($compareData['TasksModule'], $data['TasksModule']);
     $this->assertEquals($compareData['NotesModule'], $data['NotesModule']);
     $this->assertEquals($compareData['MeetingsModule'], $data['MeetingsModule']);
     $this->assertEquals($compareData['UsersModule'], $data['UsersModule']);
     $group->forget();
 }
 /**
  * Override to produce a form layout that does not follow the
  * standard form layout for EditView.
  */
 protected function renderFormLayout($form = null)
 {
     $content = '';
     $metadata = $this->getFormLayoutMetadata();
     $permissions = ModulePermissionsEditViewUtil::getPermissionsForView();
     assert('count($permissions) > 0');
     foreach ($metadata['global']['panels'] as $panel) {
         if (!empty($panel['title'])) {
             $content .= '<div class="panelTitle">' . $panel['title'] . '</div>';
         }
         $content .= '<table>';
         $content .= '<colgroup>';
         $content .= '<col style="width:20%" />';
         $width = 80 / count($permissions);
         foreach ($permissions as $permission) {
             $content .= '<col style="width:' . $width . '%" />';
         }
         $content .= '</colgroup>';
         $content .= '<tbody>';
         $content .= '<tr>';
         $content .= '<th>&#160;</th>';
         $permissionNames = ModulePermissionsEditViewUtil::getPermissionNamesForView();
         $permissionLabels = ModulePermissionsEditViewUtil::getPermissionLabelsForView();
         foreach ($permissionNames as $permission) {
             $content .= '<th>' . $permissionLabels[$permission] . '</th>';
         }
         $content .= '</tr>';
         foreach ($panel['rows'] as $row) {
             assert('!empty($row["title"])');
             $title = Zurmo::t('ZurmoModule', $row['title']);
             $rowTitlesAndContent[$title] = '<th>' . $title . '</th>';
             foreach ($row['cells'] as $cell) {
                 if (is_array($cell['elements']) && $this->shouldDisplayCell(ArrayUtil::getArrayValue($cell, 'detailViewOnly'))) {
                     foreach ($cell['elements'] as $elementInformation) {
                         $editableTemplate = '<td colspan="{colspan}">{content}{error}</td>';
                         $this->resolveElementInformationDuringFormLayoutRender($elementInformation);
                         $elementclassname = $elementInformation['type'] . 'Element';
                         $element = new $elementclassname($this->model, $elementInformation['attributeName'], $form, array_slice($elementInformation, 2));
                         $element->editableTemplate = $editableTemplate;
                         $rowTitlesAndContent[$title] .= $element->render();
                     }
                 }
             }
         }
         ksort($rowTitlesAndContent);
         foreach ($rowTitlesAndContent as $rowcontent) {
             if (!empty($rowcontent)) {
                 $content .= '<tr>';
                 $content .= $rowcontent;
                 $content .= '</tr>';
             }
         }
         $content .= '</tbody>';
         $content .= '</table>';
     }
     return $content;
 }