public function executeHtml(AgaviRequestDataHolder $rd)
 {
     $customViewFields = array("cr_base" => false, "sortField" => false, "sortDir" => false, "groupField" => false, "groupDir" => false, "template" => false, "crname" => false, "filter" => false, "title" => false);
     $requiredViewFields = array("template", "crname", "title");
     $rd->setParameter("isURLView", true);
     foreach ($customViewFields as $name => $val) {
         $val = $rd->getParameter($name, null);
         if ($val == null) {
             if (in_array($name, $requiredViewFields)) {
                 $rd->setParameter("isURLView", false);
                 break;
             } else {
                 unset($customViewFields[$name]);
             }
         } else {
             $customViewFields[$name] = $val;
         }
     }
     if ($rd->getParameter("isURLView")) {
         if (isset($customViewFields["cr_base"]) and trim($customViewFields["cr_base"]) !== "") {
             $this->formatFields($customViewFields);
         }
         $rd->setParameter("URLData", json_encode($customViewFields));
     }
     $this->setupHtml($rd);
     $this->setAttribute('_title', 'Icinga.Cronks.CronkPortal');
 }
 /**
  * @group Validators
  */
 public function runValidator($f, $in)
 {
     $req = new AgaviRequestDataHolder();
     $req->setParameter("input", $in);
     $exec = AgaviContext::getInstance()->getController()->createExecutionContainer();
     $val = $exec->getValidationManager()->createValidator('TestValidator', array("input"), array("invalid_json" => "Invalid json provided", "invalid_format" => "Invalid format"), array("format" => $f, "name" => "test_filter", "base" => NULL, "export" => "test", "source" => "parameters"));
     $val->setValidationParameters($req);
     return $val->validate();
 }
 public function executeWrite(AgaviRequestDataHolder $rd)
 {
     $params = $rd->getParameters();
     foreach ($params as $key => $param) {
         if (!is_string($param)) {
             continue;
         }
         $json = json_decode($param, true);
         if ($json) {
             $rd->setParameter($key, $json);
         }
     }
     $model = $this->getDataStoreForTarget($params["target"], $rd);
     if (!$model) {
         return "Error";
     }
     $result = $model->execRead();
     $r = $this->getContext()->getModel("Store.DataStoreResult", "Api", array("model" => $model));
     $r->parseResult($result, $rd->getParameter("fields", array()));
     $this->setAttribute("result", $r);
     return $this->getDefaultViewName();
 }
 public function executeWrite(AgaviRequestDataHolder $rd)
 {
     $module = $rd->getParameter("module");
     $action = $rd->getParameter("action");
     $output_type = $rd->getParameter("output_type", "json");
     $dispatchParams = json_decode($rd->getParameter("params"), 1);
     $params = new AgaviRequestDataHolder();
     if (is_array($dispatchParams)) {
         foreach ($dispatchParams as $key => $param) {
             if ($param != null && $param != 'null') {
                 $params->setParameter($key, $param);
             }
         }
     }
     $controller = $this->getContext()->getController();
     $actionInstance = $controller->createActionInstance($module, $action);
     if (!$actionInstance instanceof IAppKitDispatchableAction) {
         $this->setAttribute("error", $module . "." . $action . " is not accessible via the dispatcher");
         return "Error";
     }
     $this->setAttribute("execContainer", $controller->createExecutionContainer($module, $action, $params, $output_type));
     return $this->getDefaultViewName();
 }
 public function executeWrite(AgaviRequestDataHolder $rd)
 {
     $user = $this->getContext()->getUser();
     if ($user->hasCredential('appkit.admin') == false && $user->hasCredential('appkit.admin.groups') == false) {
         throw new AgaviSecurityException("Not Authorized", 401);
     }
     try {
         if ($rd->getParameter("role_parent") == -1) {
             $rd->setParameter("role_parent", null);
         }
         $roleadmin = $this->getContext()->getModel('RoleAdmin', 'AppKit');
         $padmin = $this->getContext()->getModel('PrincipalAdmin', 'AppKit');
         if ($rd->getParameter('id') == 'new') {
             $role = new NsmRole();
         } else {
             $role = $roleadmin->getRoleById($rd->getParameter('id'));
         }
         // Update the basics
         AppKitDoctrineUtil::getConnection()->beginTransaction();
         $roleadmin->updateRoleData($role, $rd);
         if (!$rd->getParameter("ignorePrincipals", false)) {
             $padmin->updatePrincipalValueData($role->NsmPrincipal, $rd->getParameter('principal_target', array()), $rd->getParameter('principal_value', array()));
         }
         AppKitDoctrineUtil::getConnection()->commit();
         if (!$rd->getParameter("ignorePrincipals", false)) {
             $useradmin = $this->getContext()->getModel('UserAdmin', 'AppKit');
             $allUsers = $useradmin->getUsersCollection()->toArray();
             $roleUsers = $rd->getParameter("role_users", array());
             $this->updateUserRoles($allUsers, $role, $useradmin, $roleUsers);
         }
     } catch (Exception $e) {
         $this->setAttribute("error", $e->getMessage());
         try {
             AppKitDoctrineUtil::getConnection()->rollback();
         } catch (Doctrine_Transaction_Exception $e) {
         }
     }
     return 'Success';
 }
 /**
  * @depends testRoleAdd
  * @group Database
  */
 public function testRoleRemove()
 {
     $id = self::$idFixture;
     $this->markTestSkipped("Role delete test doesn't work with transactions yet.");
     try {
         info("\tTesting icinga-web action: Removing roles\n");
         $context = AgaviContext::getInstance();
         $params = new AgaviRequestDataHolder();
         $params->setParameter("group_id", array($id => $id));
         $groupRemoveAction = $context->getController()->createExecutionContainer("AppKit", "Admin.Groups.Remove", $params, null, "write");
         $result = $groupRemoveAction->execute();
         $this->assertNotEquals($result->getHttpStatusCode(), "404", "Action for reading groups not found");
         // Check if group is really deleted
         $result = Doctrine_Core::getTable("NsmRole")->findBy("role_id", $id)->getFirst();
         $this->assertNotType("NsmRole", $result, "Group found despite deleting it, something seemed to go wrong");
         success("\tRemoving role suceeded!\n");
     } catch (Exception $e) {
         $this->fail("Selecting roles failed!" . $e->getMessage());
     }
 }
 /**
  * @dataProvider      storeModelProvider
  */
 public function testCombined($model)
 {
     $ctx = AgaviContext::getInstance();
     $req = new AgaviRequestDataHolder();
     $req->setParameter('target', 'IcingaHosts');
     $req->setParameter('fields', 'my.host_object_id,my.display_name,s.display_name');
     $req->setParameter('limit', 5);
     //$req->setParameter('sortfield','my.display_name');
     //$req->setParameter('dir','DESC');
     $req->setParameter('filter_json', array("type" => "OR", "items" => array(array("field" => "my.display_name", "operator" => "=", "value" => "c1-db1"), array("type" => "OR", "items" => array(array("field" => "my.display_name", "operator" => "LIKE", "value" => "%mail%"), array("field" => "display_name", "operator" => "IN", "value" => array("c2-db1")))))));
     $dataStore = $ctx->getModel($model, 'Api', array("request" => $req, "resultType" => "ARRAY"));
     $firstResult = $dataStore->doRead();
     $firstResult = $firstResult["data"];
     $this->assertLessThanOrEqual(5, count($firstResult));
 }
 /**
  * Execute html within a slot layout only without
  * implementing a new layout method in the corresponding
  * views
  *
  * @param AgaviRequestDataHolder $rd
  * @return mixed
  */
 public function executeSimple(AgaviRequestDataHolder $rd)
 {
     $rd->setParameter('is_slot', true);
     return $this->executeHtml($rd);
 }