Permalink
Browse files

Fix optional path parameter

  • Loading branch information...
1 parent ede79b8 commit f0d097f24a4a06cb915d34ea4f2bc6115a9f5f7c @cdujeu cdujeu committed Jul 14, 2016
Oops, something went wrong.
@@ -63,9 +63,14 @@ public function configureRoutes(\FastRoute\RouteCollector &$r){
$configObject = json_decode(file_get_contents(AJXP_INSTALL_PATH . "/" . AJXP_DOCS_FOLDER . "/api2.json"), true);
foreach ($configObject["paths"] as $path => $methods){
foreach($methods as $method => $apiData){
- $path = str_replace("{path}", "{path:.+}", $path);
+ if(preg_match('/\{path\}/', $path)){
+ if(isset($apiData["parameters"]["0"]['$ref']) && preg_match('/Optional$/', $apiData["parameters"]["0"]['$ref'])){
+ $path = str_replace("{path}", "{path:.*}", $path);
+ }else{
+ $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);
}
}
@@ -469,6 +469,12 @@
<serverCallback methodName="searchUsersAction" restParams="/query/dir+" developerComment="Remote search implementation, currently only supporting users search."/>
</processing>
</action>
+ <action name="people-create-resource">
+ <processing><serverCallback methodName="usersAction"/></processing>
+ </action>
+ <action name="people-delete-resource">
+ <processing><serverCallback methodName="usersAction"/></processing>
+ </action>
<!-- ROLES ACTIONS -->
<action name="create_role">
@@ -213,7 +213,7 @@ public function listAction(ServerRequestInterface $requestInterface, ResponseInt
if(isSet($vars["path"]) && !empty($vars["path"]) && $vars["path"] !== "/"){
$crtPath = $vars["path"];
}
- $vars["dir"] = "/data/users".$crtPath;
+ $vars["dir"] = "/data/users/".ltrim($crtPath, "/");
$requestInterface = $requestInterface->withParsedBody($vars);
}
@@ -251,7 +251,12 @@ public function rolesAction(ServerRequestInterface $requestInterface, ResponseIn
*/
public function usersAction(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface){
$pluginManager = new UsersManager($requestInterface->getAttribute("ctx"), $this->getName());
- $responseInterface = $pluginManager->usersActions($requestInterface, $responseInterface);
+ $action = $requestInterface->getAttribute("action");
+ if(strpos($action, "people-") === 0){
+ $responseInterface = $pluginManager->peopleApiActions($requestInterface, $responseInterface);
+ }else{
+ $responseInterface = $pluginManager->usersActions($requestInterface, $responseInterface);
+ }
}
/**
@@ -60,6 +60,54 @@ class UsersManager extends AbstractManager
* @param ServerRequestInterface $requestInterface
* @param ResponseInterface $responseInterface
* @return ResponseInterface
+ */
+ public function peopleApiActions(ServerRequestInterface $requestInterface, ResponseInterface $responseInterface){
+
+ $a = $requestInterface->getAttribute("action");
+ $vars = $requestInterface->getParsedBody();
+ $path = $vars["path"];
+ if($a === "people-create-resource"){
+ if($vars["resourceType"] === "user"){
+ // Create a user
+ $uLogin = basename($path);
+ $gPath = dirname($path);
+ $requestInterface = $requestInterface
+ ->withAttribute("action", "create_user")
+ ->withParsedBody([
+ "new_user_login" => $uLogin,
+ "new_user_pwd" => $vars["userPass"],
+ "group_path" => $gPath
+ ]);
+ }else{
+ // Create a group
+ $requestInterface = $requestInterface
+ ->withAttribute("action", "create_group")
+ ->withParsedBody([
+ "group_path" => $path,
+ "group_label" => $vars["groupLabel"]
+ ]);
+ }
+ return $this->usersActions($requestInterface, $responseInterface);
+
+ }else if($a === "people-delete-resource"){
+
+ $baseName = basename($path);
+ $vars = [];
+ if(UsersService::userExists($baseName)){
+ $vars["user_id"] = $baseName;
+ }else{
+ $vars["group"] = $path;
+ }
+ return $this->delete($requestInterface->withParsedBody($vars), $responseInterface);
+
+ }
+ return $responseInterface;
+ }
+
+ /**
+ * @param ServerRequestInterface $requestInterface
+ * @param ResponseInterface $responseInterface
+ * @return ResponseInterface
* @throws \Exception
* @throws \Pydio\Core\Exception\UserNotFoundException
*/
@@ -541,7 +589,8 @@ public function delete(ServerRequestInterface $requestInterface, ResponseInterfa
if (isSet($httpVars["group"])) {
$groupPath = $httpVars["group"];
- $basePath = substr(PathUtils::forwardSlashDirname($groupPath), strlen("/data/users"));
+ $groupPath = preg_replace('/^\/data\/users/', '', $groupPath);
+ $basePath = PathUtils::forwardSlashDirname($groupPath);
$basePath = ($ctx->hasUser() ? $ctx->getUser()->getRealGroupPath($basePath) : $basePath);
$gName = basename($groupPath);
UsersService::deleteGroup($basePath, $gName);

0 comments on commit f0d097f

Please sign in to comment.