Permalink
Browse files

Start implementing api v2 for admin features. CRUD Roles.

  • Loading branch information...
1 parent 57bca17 commit 445d2f70d1465f0434ec3f554fb3f23b3e664711 @cdujeu cdujeu committed Jul 14, 2016
Oops, something went wrong.
@@ -64,6 +64,8 @@ public function configureRoutes(\FastRoute\RouteCollector &$r){
foreach ($configObject["paths"] as $path => $methods){
foreach($methods as $method => $apiData){
$path = str_replace("{path}", "{path:.+}", $path);
+ $path = str_replace("{roleId}", "{roleId:.+}", $path);
+ $path = str_replace("{groupPath}", "{groupPath:.+}", $path);
$r->addRoute(strtoupper($method), $this->base . $this->v2Base . $path , $apiData);
}
}
@@ -107,13 +109,18 @@ public function route(ServerRequestInterface &$request, ResponseInterface &$resp
$apiData = $routeInfo[1];
$vars = $routeInfo[2];
if(isSet($apiData["api-v1"])){
+ $apiUri = preg_replace('/^'.preg_quote($this->base.$this->v1Base, '/').'/', '', $uri);
$request = $request
->withAttribute("action", $vars["action"])
->withAttribute("repository_id", $vars["repository_id"])
->withAttribute("rest_base", $this->base.$this->v1Base)
->withAttribute("rest_path", $vars["optional"])
- ->withAttribute("api", "v1");
+ ->withAttribute("api", "v1")
+ ->withAttribute("api_uri", $apiUri)
+ ;
}else{
+ $apiUri = preg_replace('/^'.preg_quote($this->base.$this->v2Base, '/').'/', '', $uri);
+ $request = $request->withAttribute("api_uri", $apiUri);
$repoId = $this->findRepositoryInParameters($request, $vars);
$request = $request
->withAttribute("action", $apiData["x-pydio-action"])
@@ -136,6 +143,8 @@ protected function findRepositoryInParameters(ServerRequestInterface $request, a
return $params["workspaceId"];
}else if(isSet($params["path"]) && strpos($params["path"], "/") !== false){
return array_shift(explode("/", ltrim($params["path"], "/")));
+ }else if (preg_match('/^\/admin\//', $request->getAttribute("api_uri"))) {
+ return "ajxp_conf";
}
// If no repo ID was found, return default repo id "pydio".
return "pydio";
@@ -504,6 +504,16 @@
</serverCallback>
</processing>
</action>
+ <action name="edit_role">
+ <processing>
+ <serverCallback methodName="rolesAction"/>
+ </processing>
+ </action>
+ <action name="post_json_role">
+ <processing>
+ <serverCallback methodName="rolesAction"/>
+ </processing>
+ </action>
<!-- PLUGINS ACTIONS -->
<action name="clear_plugins_cache">
@@ -20,6 +20,7 @@
*/
namespace Pydio\Access\Driver\DataProvider\Provisioning;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Core\Controller\XMLWriter;
use Pydio\Core\Model\ContextInterface;
@@ -187,17 +188,15 @@ protected function getEditableParameters($ctx, $currentUserIsGroupAdmin, $withLa
}
-
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
*/
- public abstract function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition=null, $aliasedDir=null);
+ public abstract function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition=null, $aliasedDir=null);
}
@@ -20,6 +20,7 @@
*/
namespace Pydio\Access\Driver\DataProvider\Provisioning;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Core\PluginFramework\Plugin;
@@ -36,16 +37,16 @@ class ActionsManager extends AbstractManager
{
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
+ * @throws \Pydio\Core\Exception\PydioException
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$nodesList = new NodesList("/$rootPath/$relativePath");
$parts = explode("/",$relativePath);
@@ -171,10 +171,19 @@ public function listAction(ServerRequestInterface $requestInterface, ResponseInt
return;
}
+ if($requestInterface->getAttribute("api") === "v2"){
+ $uri = $requestInterface->getAttribute("api_uri");
+ $vars = $requestInterface->getParsedBody();
+ if($uri === "/admin/roles") {
+ $vars["dir"] = "/data/roles";
+ $requestInterface = $requestInterface->withParsedBody($vars);
+ }
+ }
+
/** @var ContextInterface $ctx */
$ctx = $requestInterface->getAttribute("ctx");
$treeManager = new TreeManager($ctx, $this->getName(), $this->getMainTree($ctx));
- $nodesList = $treeManager->dispatchList($requestInterface->getParsedBody());
+ $nodesList = $treeManager->dispatchList($requestInterface);
$responseInterface = $responseInterface->withBody(new SerializableResponseStream($nodesList));
}
@@ -215,6 +224,7 @@ public function searchUsersAction(ServerRequestInterface $requestInterface, Resp
$pluginManager = new UsersManager($requestInterface->getAttribute("ctx"), $this->getName());
$responseInterface = $pluginManager->search($requestInterface, $responseInterface);
}
+
/**
* @param ServerRequestInterface $requestInterface
* @param ResponseInterface $responseInterface
@@ -273,7 +283,7 @@ public function editAction(ServerRequestInterface $requestInterface, ResponseInt
public function deleteAction(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface){
$httpVars = $requestInterface->getParsedBody();
- // REST API mapping
+ // REST API V1 mapping
if (isSet($httpVars["data_type"])) {
switch ($httpVars["data_type"]) {
case "repository":
@@ -294,6 +304,15 @@ public function deleteAction(ServerRequestInterface $requestInterface, ResponseI
unset($httpVars["data_type"]);
unset($httpVars["data_id"]);
$requestInterface = $requestInterface->withParsedBody($httpVars);
+
+ }else if($requestInterface->getAttribute("api") === "v2"){
+
+ if(isSet($httpVars["roleId"])) {
+ $httpVars["role_id"] = $httpVars["roleId"];
+ unset($httpVars["roleId"]);
+ $requestInterface = $requestInterface->withParsedBody($httpVars);
+ }
+
}
/** @var ContextInterface $ctx */
@@ -20,6 +20,7 @@
*/
namespace Pydio\Access\Driver\DataProvider\Provisioning;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Core\Utils\Reflection\DiagnosticRunner;
@@ -35,16 +36,15 @@ class DiagnosticManager extends AbstractManager
{
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$outputArray = array();
$testedParams = array();
@@ -51,16 +51,15 @@ public function docActions(ServerRequestInterface $requestInterface, ResponseInt
}
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$nodesList = new NodesList("/$rootPath/$relativePath");
$jsonContent = json_decode(file_get_contents(DocsParser::getHooksFile()), true);
@@ -20,6 +20,7 @@
*/
namespace Pydio\Access\Driver\DataProvider\Provisioning;
+use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\NodesList;
use Pydio\Log\Core\Logger;
@@ -34,16 +35,15 @@ class LogsManager extends AbstractManager
{
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$relativePath = "/$relativePath";
$nodesList = new NodesList("/".$rootPath.$relativePath);
@@ -318,16 +318,16 @@ public function pluginsActions(ServerRequestInterface $requestInterface, Respons
}
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
+ * @throws \Pydio\Core\Exception\PydioException
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$relativePath = "/$relativePath";
@@ -95,7 +95,7 @@ public function repositoriesActions(ServerRequestInterface $requestInterface, Re
"isTemplate" => '1'
), $count);
foreach ($repositories as $repo) {
- if(!$repo->isTemplate) continue;
+ if(!$repo->isTemplate()) continue;
$repoId = $repo->getUniqueId();
$repoLabel = TextEncoder::toUTF8($repo->getDisplay());
$repoType = $repo->getAccessType();
@@ -210,7 +210,7 @@ public function repositoriesActions(ServerRequestInterface $requestInterface, Re
$loggedUser->recomputeMergedRole();
$loggedUser->save("superuser");
AuthService::updateUser($loggedUser);
-
+
$message = new UserMessage($mess["ajxp_conf.52"]);
$reload = new ReloadMessage("", $newRep->getUniqueId());
$responseInterface = $responseInterface->withBody(new SerializableResponseStream([$message, $reload]));
@@ -642,16 +642,15 @@ public function delete(ServerRequestInterface $requestInterface, ResponseInterfa
/**
- * @param array $httpVars Full set of query parameters
+ * @param ServerRequestInterface $requestInterface Full set of query parameters
* @param string $rootPath Path to prepend to the resulting nodes
* @param string $relativePath Specific path part for this function
* @param string $paginationHash Number added to url#2 for pagination purpose.
* @param string $findNodePosition Path to a given node to try to find it
* @param string $aliasedDir Aliased path used for alternative url
- *
* @return NodesList A populated NodesList object, eventually recursive.
*/
- public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
+ public function listNodes(ServerRequestInterface $requestInterface, $rootPath, $relativePath, $paginationHash = null, $findNodePosition = null, $aliasedDir = null)
{
$fullBasePath = "/" . $rootPath . "/" . $relativePath;
$REPOS_PER_PAGE = 50;
@@ -674,8 +673,8 @@ public function listNodes($httpVars, $rootPath, $relativePath, $paginationHash =
}else{
$criteria["parent_uuid"] = AJXP_FILTER_EMPTY;
}
- if(isSet($httpVars) && is_array($httpVars) && isSet($httpVars["template_children_id"])){
- $criteria["parent_uuid"] = InputFilter::sanitize($httpVars["template_children_id"], InputFilter::SANITIZE_ALPHANUM);
+ if(isSet($requestInterface) && is_array($requestInterface) && isSet($requestInterface["template_children_id"])){
+ $criteria["parent_uuid"] = InputFilter::sanitize($requestInterface["template_children_id"], InputFilter::SANITIZE_ALPHANUM);
}
$repos = RepositoryService::listRepositoriesWithCriteria($criteria, $count);
Oops, something went wrong.

0 comments on commit 445d2f7

Please sign in to comment.