Permalink
Browse files

Fix various cases, add new containers (exceptions, bgActionTrigger)

  • Loading branch information...
1 parent 44620ba commit 6f597929d24fbd6e7e2ecd68286f0212c3df03c2 @cdujeu cdujeu committed May 12, 2016
@@ -0,0 +1,32 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Exception;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+
+class ActionNotFoundException extends PydioException
+{
+ public function __construct($action)
+ {
+ parent::__construct("Could not find action ".$action, null);
+ }
+}
@@ -0,0 +1,32 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Exception;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+
+class NoActiveWorkspaceException extends PydioException
+{
+ public function __construct()
+ {
+ parent::__construct("No active workspace found for user!", false, 423);
+ }
+}
@@ -30,7 +30,9 @@
*/
class PydioException extends \Exception
{
- public function __construct($messageString, $messageId = false)
+ private $errorCode;
+
+ public function __construct($messageString, $messageId = false, $errorCode = null)
{
if ($messageId !== false && class_exists("ConfService")) {
$messages = ConfService::getMessages();
@@ -40,6 +42,9 @@ public function __construct($messageString, $messageId = false)
$messageString = $messageId;
}
}
+ if(isSet($errorCode)){
+ $this->errorCode = $errorCode;
+ }
parent::__construct($messageString);
}
@@ -51,4 +56,12 @@ public function errorToXml($mixed)
throw new PydioException($mixed);
}
}
+
+ public function hasErrorCode(){
+ return isSet($this->errorCode);
+ }
+
+ public function getErrorCode(){
+ return $this->errorCode;
+ }
}
@@ -0,0 +1,32 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Exception;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+
+class WorkspaceNotFoundException extends PydioException
+{
+ public function __construct($wsId)
+ {
+ parent::__construct("Could not find workspace with id/alias ".$wsId, null);
+ }
+}
@@ -0,0 +1,68 @@
+<?php
+/*
+ * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+namespace Pydio\Core\Http\Message;
+
+use Pydio\Core\Controller\XMLWriter;
+use Pydio\Core\Http\Response\XMLSerializableResponseChunk;
+
+defined('AJXP_EXEC') or die('Access not allowed');
+
+class BgActionTrigger implements XMLSerializableResponseChunk
+{
+ private $actionName;
+ private $parameters;
+ private $messageId;
+ private $delay;
+
+ private $javascriptCode;
+
+ /**
+ * @param string $actionName
+ * @param array $parameters
+ * @param string $messageId
+ * @param int $delay
+ */
+ public function __construct($actionName, $parameters, $messageId, $delay = 0)
+ {
+ $this->actionName = $actionName;
+ $this->parameters = $parameters;
+ $this->messageId = $messageId;
+ $this->delay = $delay;
+ }
+
+ public static function createForJsAction($jsCode, $messageId, $delay = 0){
+ $newOne = new BgActionTrigger("javascript_action", [], $messageId, $delay);
+ $newOne->javascriptCode = $jsCode;
+ return $newOne;
+ }
+
+ /**
+ * @return string
+ */
+ public function toXML()
+ {
+ if(isSet($this->javascriptCode)){
+ return XMLWriter::triggerBgJSAction($this->javascriptCode, false, $this->delay);
+ }else{
+ return XMLWriter::triggerBgAction($this->actionName, $this->parameters, $this->messageId, false, $this->delay);
+ }
+ }
+}
@@ -22,6 +22,8 @@
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Authfront\Core\AbstractAuthFrontend;
+use Pydio\Core\Exception\AuthRequiredException;
+use Pydio\Core\Exception\NoActiveWorkspaceException;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Exception\WorkspaceNotFoundException;
use Pydio\Core\Http\Server;
@@ -41,7 +43,7 @@ class AuthMiddleware
* @param \Psr\Http\Message\ResponseInterface $responseInterface
* @return \Psr\Http\Message\ResponseInterface
* @param callable|null $next
- * @throws WorkspaceNotFoundException
+ * @throws PydioException
*/
public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface, callable $next = null){
@@ -80,7 +82,16 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface &$
self::bootRestServer($requestInterface);
}
- ConfService::reloadServicesAndActivePlugins();
+ try{
+ ConfService::reloadServicesAndActivePlugins();
+ }catch (NoActiveWorkspaceException $ex){
+ if(Server::$mode != Server::MODE_SESSION) throw $ex;
+ $logged = AuthService::getLoggedUser();
+ if($logged !== null) $lock = $logged->getLock();
+ if(empty($lock)){
+ throw new AuthRequiredException();
+ }
+ }
return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);
@@ -29,6 +29,7 @@
use Pydio\Conf\Core\AbstractConfDriver;
use Pydio\Conf\Core\CoreConfLoader;
use Pydio\Core\Controller\Controller;
+use Pydio\Core\Exception\NoActiveWorkspaceException;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Exception\PydioUserAlertException;
use Pydio\Core\Utils\Utils;
@@ -1687,7 +1688,7 @@ private function loadRepositoryDriverInst(&$repository = null)
$this->switchRootDirInst();
$repository = $this->getRepositoryInst();
if($repository == null){
- throw new \Exception("No active repository found for user!");
+ throw new NoActiveWorkspaceException();
}
}else{
$rest = true;

0 comments on commit 6f59792

Please sign in to comment.