From c0490050dd61ed5779f158b0a689a62a5d330997 Mon Sep 17 00:00:00 2001 From: cdujeu Date: Wed, 10 Jun 2015 17:15:29 +0200 Subject: [PATCH] [ajxp_conf] Add some info in the various responses. Add limit & offset parameters on recursiveSearch New method filterFormElementsFromMeta to post data in a different format that standard form parameters. Delete action: grab parameter from window.actionArguments object --- core/src/core/classes/class.AJXP_Utils.php | 30 +++++ .../access.ajxp_conf/ajxp_confActions.xml | 9 +- .../class.ajxp_confAccessDriver.php | 125 ++++++++++++------ 3 files changed, 119 insertions(+), 45 deletions(-) diff --git a/core/src/core/classes/class.AJXP_Utils.php b/core/src/core/classes/class.AJXP_Utils.php index 32848eb343..54a8519259 100644 --- a/core/src/core/classes/class.AJXP_Utils.php +++ b/core/src/core/classes/class.AJXP_Utils.php @@ -1637,6 +1637,36 @@ public static function decypherStandardFormPassword($userId, $password){ return $password; } + public static function filterFormElementsFromMeta($metadata, &$nestedData, $userId=null, $binariesContext=null, $cypheredPassPrefix=""){ + foreach($metadata as $key => $level){ + if(!array_key_exists($key, $nestedData)) continue; + if(!is_array($level)) continue; + if(isSet($level["ajxp_form_element"])){ + // filter now + $type = $level["type"]; + if($type == "binary" && $binariesContext != null){ + $value = $nestedData[$key]; + if ($value == "ajxp-remove-original") { + if (!empty($level["original_binary"])) { + ConfService::getConfStorageImpl()->deleteBinary($binariesContext, $level["original_binary"]); + } + $value = ""; + } else { + $file = AJXP_Utils::getAjxpTmpDir()."/".$value; + if (file_exists($file)) { + $id= !empty($level["original_binary"]) ? $level["original_binary"] : null; + $id=ConfService::getConfStorageImpl()->saveBinary($binariesContext, $file, $id); + $value = $id; + } + } + $nestedData[$key] = $value; + } + }else{ + self::filterFormElementsFromMeta($level, $nestedData[$key], $userId, $binariesContext, $cypheredPassPrefix); + } + } + } + public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null, $cypheredPassPrefix = "") { if ($binariesContext === null) { diff --git a/core/src/plugins/access.ajxp_conf/ajxp_confActions.xml b/core/src/plugins/access.ajxp_conf/ajxp_confActions.xml index 553a6cbd6e..51b32adf4a 100644 --- a/core/src/plugins/access.ajxp_conf/ajxp_confActions.xml +++ b/core/src/plugins/access.ajxp_conf/ajxp_confActions.xml @@ -449,8 +449,13 @@ getGroupPath() != "/"); $query = "//param|//global_param"; if($currentUserIsGroupAdmin){ @@ -59,8 +59,20 @@ private function getEditableParameters($withLabel = false){ if(!is_array($actions[$pId])) $actions[$pId] = array(); $actionName = $node->attributes->getNamedItem("name")->nodeValue; $messId = $node->attributes->getNamedItem("label")->nodeValue; + $attributes = array(); + for( $i = 0; $i < $node->attributes->length; $i ++){ + $att = $node->attributes->item($i); + $value = $att->nodeValue; + if($att->nodeName == "choices") $value = AJXP_XMLWriter::replaceAjxpXmlKeywords($value); + $attributes[$att->nodeName] = $value; + } + $attributes["label"] = AJXP_XMLWriter::replaceAjxpXmlKeywords($messId); if($withLabel){ - $actions[$pId][$actionName] = array( "parameter" => $actionName , "label" => AJXP_XMLWriter::replaceAjxpXmlKeywords($messId)); + $actions[$pId][$actionName] = array( + "parameter" => $actionName , + "label" => $attributes["label"], + "attributes" => $attributes + ); }else{ $actions[$pId][] = $actionName; } @@ -220,7 +232,7 @@ public function preProcessBookmarkAction($action, &$httpVars, $fileVars) } - public function recursiveSearchGroups($baseGroup, $term) + public function recursiveSearchGroups($baseGroup, $term, $offset=-1, $limit=-1) { $groups = AuthService::listChildrenGroups($baseGroup); foreach ($groups as $groupId => $groupLabel) { @@ -231,7 +243,7 @@ public function recursiveSearchGroups($baseGroup, $term) $nodeKey = "/data/users/".$trimmedG.ltrim($groupId,"/"); $meta = array( "icon" => "users-folder.png", - "ajxp_mime" => "group" + "ajxp_mime" => "group_editable" ); if(in_array($nodeKey, $this->currentBookmarks)) $meta = array_merge($meta, array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png")); echo AJXP_XMLWriter::renderNode($nodeKey, $groupLabel, false, $meta, true, false); @@ -240,7 +252,7 @@ public function recursiveSearchGroups($baseGroup, $term) } - $users = AuthService::listUsers($baseGroup, $term); + $users = AuthService::listUsers($baseGroup, $term, $offset, $limit); foreach ($users as $userId => $userObject) { $gPath = $userObject->getGroupPath(); $realGroup = AuthService::filterBaseGroup(AuthService::getLoggedUser()->getGroupPath()); @@ -253,7 +265,7 @@ public function recursiveSearchGroups($baseGroup, $term) $nodeKey = "/data/users/".$trimmedG.$userId; $meta = array( "icon" => "user.png", - "ajxp_mime" => "user" + "ajxp_mime" => "user_editable" ); if(in_array($nodeKey, $this->currentBookmarks)) $meta = array_merge($meta, array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png")); echo AJXP_XMLWriter::renderNode($nodeKey, $userId, true, $meta, true, false); @@ -267,8 +279,11 @@ public function searchAction($action, $httpVars, $fileVars) { if(! AJXP_Utils::decodeSecureMagic($httpVars["dir"]) == "/data/users") return; $query = AJXP_Utils::decodeSecureMagic($httpVars["query"]); + $limit = $offset = -1; + if(isSet($httpVars["limit"])) $limit = intval(AJXP_Utils::sanitize($httpVars["limit"], AJXP_SANITIZE_ALPHANUM)); + if(isSet($httpVars["offset"])) $offset = intval(AJXP_Utils::sanitize($httpVars["offset"], AJXP_SANITIZE_ALPHANUM)); AJXP_XMLWriter::header(); - $this->recursiveSearchGroups("/", $query); + $this->recursiveSearchGroups("/", $query, $offset, $limit); AJXP_XMLWriter::close(); } @@ -566,30 +581,40 @@ public function switchAction($action, $httpVars, $fileVars) $roleData = $role->getDataArray(true); $allReps = ConfService::getRepositoriesList("all", false); $repos = array(); - if(!empty($userObject)){ - // USER - foreach ($allReps as $repositoryId => $repositoryObject) { - if (!AuthService::canAssign($repositoryObject, $userObject) || $repositoryObject->isTemplate + $repoDetailed = array(); + // USER + foreach ($allReps as $repositoryId => $repositoryObject) { + if (!empty($userObject) && + ( + !AuthService::canAssign($repositoryObject, $userObject) || $repositoryObject->isTemplate || ($repositoryObject->getAccessType()=="ajxp_conf" && !$userObject->isAdmin()) || ($repositoryObject->getUniqueUser() != null && $repositoryObject->getUniqueUser() != $userObject->getId()) - ){ - continue; - } - $repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay()); + ) + ){ + continue; + }else if(empty($userObject) && + ( + !AuthService::canAdministrate($repositoryObject) + )){ + continue; } - }else{ - foreach ($allReps as $repositoryId => $repositoryObject) { - if (!AuthService::canAdministrate($repositoryObject)) { - continue; - } - $repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay()); + $repos[$repositoryId] = SystemTextEncoding::toUTF8($repositoryObject->getDisplay()); + $meta = array(); + if($repositoryObject->getOption("META_SOURCES") != null){ + $meta = array_keys($repositoryObject->getOption("META_SOURCES")); } + $repoDetailed[$repositoryId] = array( + "label" => SystemTextEncoding::toUTF8($repositoryObject->getDisplay()), + "driver" => $repositoryObject->getAccessType(), + "meta" => $meta + ); } // Make sure it's utf8 $data = array( "ROLE" => $roleData, "ALL" => array( - "REPOSITORIES" => $repos + "REPOSITORIES" => $repos, + "REPOSITORIES_DETAILS" => $repoDetailed ) ); if (isSet($userObject)) { @@ -599,6 +624,7 @@ public function switchAction($action, $httpVars, $fileVars) $data["ALL"]["PROFILES"] = array("standard|Standard","admin|Administrator","shared|Shared","guest|Guest"); $data["USER"]["ROLES"] = array_keys($userObject->getRoles()); $data["ALL"]["ROLES"] = array_keys(AuthService::getRolesList(array(), true)); + $data["ALL"]["PLUGINS_SCOPES"] = array("GLOBAL_TYPES" => array("conf", "auth", "authfront", "log", "mq", "notifications", "gui")); if (isSet($userObject->parentRole)) { $data["PARENT_ROLE"] = $userObject->parentRole->getDataArray(); } @@ -661,24 +687,34 @@ public function switchAction($action, $httpVars, $fileVars) $jsonData = SystemTextEncoding::magicDequote($httpVars["json_data"]); $data = json_decode($jsonData, true); $roleData = $data["ROLE"]; - $forms = $data["FORMS"]; $binariesContext = array(); if (isset($userObject)) { $binariesContext = array("USER" => $userObject->getId()); } - foreach ($forms as $repoScope => $plugData) { - foreach ($plugData as $plugId => $formsData) { - $parsed = array(); - AJXP_Utils::parseStandardFormParameters( - $formsData, - $parsed, - ($userObject!=null?$usrId:null), - "ROLE_PARAM_", - $binariesContext, - AJXP_Role::$cypheredPassPrefix - ); - $roleData["PARAMETERS"][$repoScope][$plugId] = $parsed; + if(isSet($data["FORMS"])){ + $forms = $data["FORMS"]; + foreach ($forms as $repoScope => $plugData) { + foreach ($plugData as $plugId => $formsData) { + $parsed = array(); + AJXP_Utils::parseStandardFormParameters( + $formsData, + $parsed, + ($userObject!=null?$usrId:null), + "ROLE_PARAM_", + $binariesContext, + AJXP_Role::$cypheredPassPrefix + ); + $roleData["PARAMETERS"][$repoScope][$plugId] = $parsed; + } } + }else{ + AJXP_Utils::filterFormElementsFromMeta( + $data["METADATA"], + $roleData, + ($userObject!=null?$usrId:null), + $binariesContext, + AJXP_Role::$cypheredPassPrefix + ); } $existingParameters = $originalRole->listParameters(true); $this->mergeExistingParameters($roleData["PARAMETERS"], $existingParameters); @@ -1345,13 +1381,13 @@ public function switchAction($action, $httpVars, $fileVars) } $manifest = $plug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); - print("accessType."\">$manifest"); + print("accessType."\" label=\"".AJXP_Utils::xmlEntities($plug->getManifestLabel())."\" description=\"".AJXP_Utils::xmlEntities($plug->getManifestDescription())."\">$manifest"); print(""); $metas = $pServ->getPluginsByType("metastore"); $metas = array_merge($metas, $pServ->getPluginsByType("meta")); $metas = array_merge($metas, $pServ->getPluginsByType("index")); foreach ($metas as $metaPlug) { - print("getId()."\" label=\"".AJXP_Utils::xmlEntities($metaPlug->getManifestLabel())."\">"); + print("getId()."\" label=\"".AJXP_Utils::xmlEntities($metaPlug->getManifestLabel())."\" description=\"".AJXP_Utils::xmlEntities($metaPlug->getManifestDescription())."\">"); $manifest = $metaPlug->getManifestRawContent("server_settings/param"); $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest); print($manifest); @@ -1950,6 +1986,7 @@ public function listUsers($root, $child, $hashValue = null, $returnNodes = false $nodeKey = "/data/".$root."/".ltrim($groupId,"/"); $meta = array( "icon" => "users-folder.png", + "icon_class" => "icon-folder-open-alt", "ajxp_mime" => "group", "object_id" => $groupId ); @@ -2006,11 +2043,13 @@ public function listUsers($root, $child, $hashValue = null, $returnNodes = false $meta = array( "isAdmin" => $mess[($isAdmin?"ajxp_conf.14":"ajxp_conf.15")], "icon" => $icon.".png", + "icon_class" => "icon-user", "object_id" => $userId, "auth_scheme" => ($scheme != null? $scheme : ""), "rights_summary" => $rightsString, "ajxp_roles" => implode(", ", $roles), - "ajxp_mime" => "user".(($userId!="guest"&&$userId!=$loggedUser->getId())?"_editable":"") + "ajxp_mime" => "user".(($userId!="guest"&&$userId!=$loggedUser->getId())?"_editable":""), + "json_merged_role" => json_encode($userObject->mergedRole->getDataArray(true)) ); if(in_array($nodeKey, $this->currentBookmarks)) $meta = array_merge($meta, array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png")); $xml = AJXP_XMLWriter::renderNode($nodeKey, $nodeLabel, true, $meta, true, false); @@ -2106,7 +2145,6 @@ public function listRepositories($root, $child, $hashValue = null, $returnNodes ); } if(!$returnNodes){ - var_dump($count); AJXP_XMLWriter::renderPaginationData($count, $hashValue, ceil($count/$REPOS_PER_PAGE)); AJXP_XMLWriter::sendFilesListComponentConfig(' @@ -2137,7 +2175,8 @@ public function listRepositories($root, $child, $hashValue = null, $returnNodes "openicon" => $icon, "slug" => $repoObject->getSlug(), "parentname" => "/repositories", - "ajxp_mime" => "repository".($editable?"_editable":"") + "ajxp_mime" => "repository".($editable?"_editable":""), + "is_template" => ($repoObject->isTemplate?"true":"false") ); $nodeKey = "/data/repositories/$repoIndex";