Пример #1
0
 /**
  * Validates the passed chunk of data.
  * In most cases, this'll be a string-object.
  *
  * @param string $objValue
  * @return bool
  */
 public function validate($objValue)
 {
     if (!parent::validate($objValue)) {
         return false;
     }
     //check if the user or usergroup exists
     $objUser = new class_module_user_user($objValue);
     $objUserGroup = new class_module_user_group($objValue);
     if ($objUser->getStrUsername() == "" && $objUserGroup->getStrName() == "") {
         return false;
     }
     if ($objUser->getIntDeleted() == 1) {
         return false;
     }
     return true;
 }
 /**
  * Edits or creates a group (displays form)
  *
  * @param string $strMode
  * @param \class_admin_formgenerator|null $objForm
  *
  * @return string
  * @permissions edit
  * @autoTestable
  */
 protected function actionGroupNew($strMode = "new", class_admin_formgenerator $objForm = null)
 {
     $this->setArrModuleEntry("template", "/folderview.tpl");
     $objUsersources = new class_module_user_sourcefactory();
     if ($strMode == "new") {
         if ($this->getParam("usersource") == "" || $objUsersources->getUsersource($this->getParam("usersource")) == null) {
             $arrSubsystems = $objUsersources->getArrUsersources();
             $arrDD = array();
             foreach ($arrSubsystems as $strOneName) {
                 $objConcreteSubsystem = $objUsersources->getUsersource($strOneName);
                 if ($objConcreteSubsystem->getCreationOfGroupsAllowed()) {
                     $arrDD[$strOneName] = $objConcreteSubsystem->getStrReadableName();
                 }
             }
             if (count($arrDD) > 1) {
                 $strReturn = $this->objToolkit->formHeader(class_link::getLinkAdminHref($this->getArrModule("modul"), "groupNew"));
                 $strReturn .= $this->objToolkit->formInputDropdown("usersource", $arrDD, $this->getLang("group_usersource"));
                 $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("commons_save"));
                 $strReturn .= $this->objToolkit->formClose();
                 return $strReturn;
             } else {
                 $arrKeys = array_keys($arrDD);
                 $this->setParam("usersource", array_pop($arrKeys));
             }
         }
         $objSource = $objUsersources->getUsersource($this->getParam("usersource"));
         $objNewGroup = $objSource->getNewGroup();
         if ($objForm == null) {
             $objForm = $this->getGroupForm($objNewGroup);
         }
         $objForm->addField(new class_formentry_hidden("", "usersource"))->setStrValue($this->getParam("usersource"));
         $objForm->addField(new class_formentry_hidden("", "mode"))->setStrValue("new");
         return $objForm->renderForm(class_link::getLinkAdminHref($this->getArrModule("modul"), "groupSave"));
     } else {
         $objNewGroup = new class_module_user_group($this->getSystemid());
         $this->setParam("usersource", $objNewGroup->getStrSubsystem());
         if ($objForm == null) {
             $objForm = $this->getGroupForm($objNewGroup->getObjSourceGroup());
         }
         $objForm->getField("group_name")->setStrValue($objNewGroup->getStrName());
         $objForm->addField(new class_formentry_hidden("", "usersource"))->setStrValue($this->getParam("usersource"));
         $objForm->addField(new class_formentry_hidden("", "mode"))->setStrValue("edit");
         return $objForm->renderForm(class_link::getLinkAdminHref($this->getArrModule("modul"), "groupSave"));
     }
 }
 /**
  * Creates the form to perform the current workflow-step
  *
  * @return string
  * @permissions view
  */
 protected function actionShowUi()
 {
     $strReturn = "";
     $objWorkflow = new class_module_workflows_workflow($this->getSystemid());
     if ($objWorkflow->getIntState() != class_module_workflows_workflow::$INT_STATE_SCHEDULED || !$objWorkflow->getObjWorkflowHandler()->providesUserInterface()) {
         return $this->getLang("commons_error_permissions");
     }
     $arrIdsToCheck = array_merge(array($this->objSession->getUserID()), $this->objSession->getGroupIdsAsArray());
     $arrIdsOfTask = explode(",", $objWorkflow->getStrResponsible());
     //ui given? current user responsible?
     //magic: the difference of the tasks' ids and the users' ids should be less than the count of the task-ids - then at least one id matches
     if ($objWorkflow->getObjWorkflowHandler()->providesUserInterface() && ($objWorkflow->getStrResponsible() == "" || count(array_diff($arrIdsOfTask, $arrIdsToCheck)) < count($arrIdsOfTask))) {
         $strCreator = "";
         if (validateSystemid($objWorkflow->getStrOwner())) {
             $objUser = new class_module_user_user($objWorkflow->getStrOwner(), false);
             $strCreator .= $objUser->getStrUsername();
         }
         $strInfo = $this->objToolkit->getTextRow($this->getLang("workflow_owner") . " " . $strCreator);
         $strResponsible = "";
         foreach (explode(",", $objWorkflow->getStrResponsible()) as $strOneId) {
             if (validateSystemid($strOneId)) {
                 if ($strResponsible != "") {
                     $strResponsible .= ", ";
                 }
                 $objUser = new class_module_user_user($strOneId, false);
                 if ($objUser->getStrUsername() != "") {
                     $strResponsible .= $objUser->getStrUsername();
                 } else {
                     $objGroup = new class_module_user_group($strOneId);
                     $strResponsible .= $objGroup->getStrName();
                 }
             }
         }
         $arrHeader = array($this->getLang("workflow_general"), "");
         $arrRow1 = array($this->getLang("workflow_owner"), $strCreator);
         $arrRow2 = array($this->getLang("workflow_responsible"), $strResponsible);
         $strReturn .= $this->objToolkit->dataTable($arrHeader, array($arrRow1, $arrRow2));
         $strForm = $objWorkflow->getObjWorkflowHandler()->getUserInterface();
         if ($strForm instanceof class_admin_formgenerator) {
             $strForm->addField(new class_formentry_hidden(null, null), "workflowid")->setStrValue($objWorkflow->getSystemid());
             $strReturn .= $strForm->renderForm(class_link::getLinkAdminHref($this->getArrModule("modul"), "saveUI"));
         } else {
             $strReturn .= $this->objToolkit->formHeader(class_link::getLinkAdminHref($this->getArrModule("modul"), "saveUI"));
             $strReturn .= $strForm;
             $strReturn .= $this->objToolkit->formInputHidden("systemid", $objWorkflow->getSystemid());
             $strReturn .= $this->objToolkit->formInputSubmit($this->getLang("commons_save"));
             $strReturn .= $this->objToolkit->formClose();
         }
     } else {
         $strReturn .= $this->getLang("commons_error_permissions");
     }
     return $strReturn;
 }
Пример #4
0
 public function test()
 {
     $objDB = class_carrier::getInstance()->getObjDB();
     echo "\tmodul_user...\n";
     //blank system - one user should have been created
     echo "\tcheck number of users installed...\n";
     $arrUserInstalled = class_module_user_user::getObjectList();
     $intStartUsers = count($arrUserInstalled);
     echo "\t ...found " . $intStartUsers . " users.\n";
     echo "\tcheck number of groups installed...\n";
     $arrGroupsInstalled = class_module_user_group::getObjectList();
     $intStartGroups = count($arrGroupsInstalled);
     echo "\t ...found " . $intStartUsers . " users.\n";
     echo "\tcreate 10 users using the model...\n";
     $arrUsersCreated = array();
     for ($intI = 0; $intI < 10; $intI++) {
         $objUser = new class_module_user_user();
         //$objUser->setStrEmail(generateSystemid()."@".generateSystemid()."de");
         $strUsername = "******" . generateSystemid();
         $objUser->setStrUsername($strUsername);
         $objUser->updateObjectToDb();
         $arrUsersCreated[] = $objUser->getSystemid();
         $strID = $objUser->getSystemid();
         $objDB->flushQueryCache();
         $objUser = new class_module_user_user($strID);
         $this->assertEquals($objUser->getStrUsername(), $strUsername, __FILE__ . " checkNameOfUserCreated");
     }
     $arrUserInstalled = class_module_user_user::getObjectList();
     $this->assertEquals(count($arrUserInstalled), 10 + $intStartUsers, __FILE__ . " checkNrOfUsersCreatedByModel");
     echo "\tcreate 10 groups using the model...\n";
     $arrGroupsCreated = array();
     for ($intI = 0; $intI < 10; $intI++) {
         $objGroup = new class_module_user_group();
         $strName = "name_" . generateSystemid();
         $objGroup->setStrName($strName);
         $objGroup->updateObjectToDb();
         $strID = $objGroup->getSystemid();
         $arrGroupsCreated[] = $objGroup->getSystemid();
         $objDB->flushQueryCache();
         $objGroup = new class_module_user_group($strID);
         $this->assertEquals($objGroup->getStrName(), $strName, __FILE__ . " checkNameOfGroupCreated");
     }
     $arrGroupsInstalled = class_module_user_group::getObjectList();
     $this->assertEquals(count($arrGroupsInstalled), 10 + $intStartGroups, __FILE__ . " checkNrOfGroupsByModel");
     echo "\tdeleting users created...\n";
     foreach ($arrUsersCreated as $strOneUser) {
         echo "\t\tdeleting user " . $strOneUser . "...\n";
         $objUser = new class_module_user_user($strOneUser);
         $objUser->deleteObjectFromDatabase();
     }
     $objDB->flushQueryCache();
     echo "\tcheck number of users installed...\n";
     $arrUserInstalled = class_module_user_user::getObjectList();
     $this->assertEquals(count($arrUserInstalled), $intStartUsers, __FILE__ . " checkNrOfUsers");
     echo "\tdeleting groups created...\n";
     foreach ($arrGroupsCreated as $strOneGroup) {
         $objOneGroup = new class_module_user_group($strOneGroup);
         $objOneGroup->deleteObjectFromDatabase();
     }
     $objDB->flushQueryCache();
     echo "\tcheck number of groups installed...\n";
     $arrGroupsInstalled = class_module_user_group::getObjectList();
     $this->assertEquals(count($arrGroupsInstalled), $intStartGroups, __FILE__ . " checkNrOfGroups");
     echo "\ttest group membership handling...\n";
     $objGroup = new class_module_user_group();
     $objGroup->setStrName("AUTOTESTGROUP");
     $objGroup->updateObjectToDb();
     echo "\tadding 10 members to group...\n";
     for ($intI = 0; $intI <= 10; $intI++) {
         $objUser = new class_module_user_user();
         $objUser->setStrUsername("AUTOTESTUSER_" . $intI);
         //$objUser->setStrEmail("autotest_".$intI."@kajona.de");
         $objUser->updateObjectToDb();
         //add user to group
         $objGroup->getObjSourceGroup()->addMember($objUser->getObjSourceUser());
         $arrUsersInGroup = $objGroup->getObjSourceGroup()->getUserIdsForGroup();
         $this->assertTrue(in_array($objUser->getSystemid(), $arrUsersInGroup), __FILE__ . " checkUserInGroup");
         $this->assertEquals(count($arrUsersInGroup), 1 + $intI, __FILE__ . " checkNrOfUsersInGroup");
         $objDB->flushQueryCache();
     }
     echo "\tdeleting groups & users\n";
     foreach ($objGroup->getObjSourceGroup()->getUserIdsForGroup() as $strOneUser) {
         $objOneUser = new class_module_user_user($strOneUser);
         $objOneUser->deleteObjectFromDatabase();
     }
     $objGroup->deleteObjectFromDatabase();
     $objDB->flushQueryCache();
     echo "\tcheck number of users installed is same as at beginning...\n";
     $arrUserInstalled = class_module_user_user::getObjectList();
     $this->assertEquals(count($arrUserInstalled), $intStartUsers, __FILE__ . " checkNrOfUsersAtEnd");
     echo "\tcheck number of groups installed is same as at beginning...\n";
     $arrGroupsInstalled = class_module_user_group::getObjectList();
     $this->assertEquals(count($arrGroupsInstalled), $intStartGroups, __FILE__ . " checkNrOfGrpupsAtEnd");
 }