Ejemplo n.º 1
0
 public function testStrongerIntegerNotSavingAsInteger()
 {
     SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = User::getByUsername('super');
     $user = UserTestHelper::createBasicUser('arrry');
     $userId = $user->id;
     $user2 = UserTestHelper::createBasicUser('brrry');
     $user2Id = $user2->id;
     $a = new Group();
     $a->name = 'RRRRRA';
     $this->assertTrue($a->save());
     $a->users->add($user);
     $a->users->add($user2);
     $a->save();
     $user->forget();
     $user2->forget();
     $a->forget();
     unset($a);
     unset($user);
     unset($user2);
     $a = Group::getByName('RRRRRA');
     $data = PoliciesUtil::getAllModulePoliciesDataByPermitable($a);
     $policiesForm = PoliciesFormUtil::makeFormFromPoliciesData($data);
     $fakePost = array('UsersModule__POLICY_ENFORCE_STRONG_PASSWORDS' => '', 'UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH__helper' => '1', 'UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH' => '5', 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH__helper' => '1', 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH' => '5', 'UsersModule__POLICY_PASSWORD_EXPIRES' => '');
     $validatedAndCastedPostData = PoliciesFormUtil::typeCastPostData($fakePost);
     $policiesForm = PoliciesFormUtil::loadFormFromCastedPost($policiesForm, $validatedAndCastedPostData);
     $this->assertTrue($policiesForm->validate());
     $saved = PoliciesFormUtil::setPoliciesFromCastedPost($validatedAndCastedPostData, $a);
     $this->assertTrue($saved);
     $a->forget();
     $user = User::getById($userId);
     $user2 = User::getById($user2Id);
     $data = PoliciesUtil::getAllModulePoliciesDataByPermitable($user);
     $data = PoliciesUtil::getAllModulePoliciesDataByPermitable($user2);
     $user->forget();
     $user2->forget();
 }
Ejemplo n.º 2
0
 public function actionEditPolicies($id)
 {
     $group = Group::getById(intval($id));
     $title = Zurmo::t('ZurmoModule', 'Policies');
     $breadCrumbLinks = array(strval($group) => array('group/' . static::resolveBreadCrumbActionByGroup($group), 'id' => $id), $title);
     $data = PoliciesUtil::getAllModulePoliciesDataByPermitable($group);
     $policiesForm = PoliciesFormUtil::makeFormFromPoliciesData($data);
     $postVariableName = get_class($policiesForm);
     if (isset($_POST[$postVariableName])) {
         $castedPostData = PoliciesFormUtil::typeCastPostData($_POST[$postVariableName]);
         $policiesForm = PoliciesFormUtil::loadFormFromCastedPost($policiesForm, $castedPostData);
         if ($policiesForm->validate()) {
             if (PoliciesFormUtil::setPoliciesFromCastedPost($castedPostData, $group)) {
                 $this->clearCaches();
                 Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'Policies Saved Successfully.'));
                 $action = $this->resolveActionToGoToAfterSave($group);
                 $this->redirect(array($this->getId() . '/' . $action, 'id' => $group->id));
                 Yii::app()->end(0, false);
             }
         }
     }
     $metadata = PoliciesEditViewUtil::resolveMetadataFromData($policiesForm->data, PoliciesEditAndDetailsView::getMetadata());
     $titleBarAndEditView = new GroupActionBarAndSecurityEditView($this->getId(), $this->getModule()->getId(), $policiesForm, $group, $this->getModule()->getPluralCamelCasedName(), $metadata, 'PoliciesEditAndDetailsView', 'GroupPoliciesEditMenu');
     $view = new GroupsPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $titleBarAndEditView, $breadCrumbLinks, 'GroupBreadCrumbView'));
     echo $view->render();
 }
Ejemplo n.º 3
0
 public function actionSecurityDetails($id)
 {
     UserAccessUtil::resolveCanCurrentUserAccessAction(intval($id));
     $user = User::getById(intval($id));
     UserAccessUtil::resolveCanCurrentUserAccessRootUser($user);
     UserAccessUtil::resolveAccessingASystemUser($user);
     $title = Zurmo::t('UsersModule', 'Security Overview');
     $breadCrumbLinks = array(strval($user) => array('default/details', 'id' => $id), $title);
     $modulePermissionsData = PermissionsUtil::getAllModulePermissionsDataByPermitable($user);
     $modulePermissionsForm = ModulePermissionsFormUtil::makeFormFromPermissionsData($modulePermissionsData);
     $viewReadyModulePermissionsData = GroupModulePermissionsDataToEditViewAdapater::resolveData($modulePermissionsData);
     $modulePermissionsViewMetadata = ModulePermissionsActualDetailsViewUtil::resolveMetadataFromData($viewReadyModulePermissionsData, ModulePermissionsEditAndDetailsView::getMetadata());
     $rightsData = RightsUtil::getAllModuleRightsDataByPermitable($user);
     $rightsForm = RightsFormUtil::makeFormFromRightsData($rightsData);
     $rightsViewMetadata = RightsEffectiveDetailsViewUtil::resolveMetadataFromData($rightsData, RightsEditAndDetailsView::getMetadata());
     $policiesData = PoliciesUtil::getAllModulePoliciesDataByPermitable($user);
     $policiesForm = PoliciesFormUtil::makeFormFromPoliciesData($policiesData);
     $policiesViewMetadata = PoliciesEffectiveDetailsViewUtil::resolveMetadataFromData($policiesData, PoliciesEditAndDetailsView::getMetadata());
     $groupMembershipAdapter = new UserGroupMembershipToViewAdapter($user);
     $groupMembershipViewData = $groupMembershipAdapter->getViewData();
     $securityDetailsView = new UserActionBarAndSecurityDetailsView($this->getId(), $this->getModule()->getId(), $user, $modulePermissionsForm, $rightsForm, $policiesForm, $modulePermissionsViewMetadata, $rightsViewMetadata, $policiesViewMetadata, $groupMembershipViewData);
     $view = new UsersPageView($this->resolveZurmoDefaultOrAdminView($securityDetailsView, $breadCrumbLinks, 'UserBreadCrumbView'));
     echo $view->render();
 }
 /**
  * @depends testPoliciesFormUtilSetPoliciesFromPost
  */
 public function testPoliciesFormValidate()
 {
     $fakePostData = array('UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH__helper' => '', 'UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH' => strval(10), 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH__helper' => strval(PolicyIntegerAndStaticDropDownElement::HELPER_DROPDOWN_VALUE_YES), 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH' => strval(5), 'UsersModule__POLICY_PASSWORD_EXPIRES' => strval(Policy::NO));
     $group = Group::getByName('viewGroup');
     $data = PoliciesUtil::getAllModulePoliciesDataByPermitable($group);
     $policiesForm = PoliciesFormUtil::makeFormFromPoliciesData($data);
     $validatedPost = PoliciesFormUtil::typeCastPostData($fakePostData);
     $policiesForm = PoliciesFormUtil::loadFormFromCastedPost($policiesForm, $validatedPost);
     $validated = $policiesForm->validate();
     $this->assertTrue($validated);
     $fakePostData = array('UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH__helper' => strval(PolicyIntegerAndStaticDropDownElement::HELPER_DROPDOWN_VALUE_YES), 'UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH' => '', 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH__helper' => strval(PolicyIntegerAndStaticDropDownElement::HELPER_DROPDOWN_VALUE_YES), 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH' => '', 'UsersModule__POLICY_PASSWORD_EXPIRES' => strval(Policy::YES), 'UsersModule__POLICY_PASSWORD_EXPIRY_DAYS' => '');
     $validatedPost = PoliciesFormUtil::typeCastPostData($fakePostData);
     $policiesForm = PoliciesFormUtil::loadFormFromCastedPost($policiesForm, $validatedPost);
     $validated = $policiesForm->validate();
     $this->assertFalse($validated);
     $compareData = array('UsersModule__POLICY_MINIMUM_PASSWORD_LENGTH' => array('You must specify a value.'), 'UsersModule__POLICY_MINIMUM_USERNAME_LENGTH' => array('You must specify a value.'), 'UsersModule__POLICY_PASSWORD_EXPIRY_DAYS' => array('You must specify a value.'));
     $this->assertEquals($compareData, $policiesForm->getErrors());
 }