Permalink
Browse files

Pass a context when building/parsing registry contributions in plugin…

…s. Still todo in init/initRepository/initMeta methods
  • Loading branch information...
1 parent c4ff2e6 commit 9093ccc1b480e4514e520837462963f109e7466b @cdujeu cdujeu committed Jun 4, 2016
Showing with 124 additions and 151 deletions.
  1. +1 −34 core/src/core/src/pydio/Core/Controller/Controller.php
  2. +26 −11 core/src/core/src/pydio/Core/PluginFramework/Plugin.php
  3. +1 −1 core/src/core/src/pydio/Core/PluginFramework/PluginsService.php
  4. +6 −3 core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
  5. +5 −4 core/src/plugins/access.ajxp_home/class.HomePagePlugin.php
  6. +3 −3 core/src/plugins/access.ajxp_user/class.UserDashboardDriver.php
  7. +3 −3 core/src/plugins/access.fs/class.fsAccessDriver.php
  8. +3 −2 core/src/plugins/access.ftp/class.ftpAccessDriver.php
  9. +4 −3 core/src/plugins/access.imap/class.imapAccessDriver.php
  10. +5 −5 core/src/plugins/access.s3/class.s3AccessDriver.php
  11. +4 −5 core/src/plugins/access.sftp/class.sftpAccessDriver.php
  12. +4 −4 core/src/plugins/access.sftp_psl/class.sftpPSLAccessDriver.php
  13. +4 −4 core/src/plugins/access.smb/class.smbAccessDriver.php
  14. +4 −4 core/src/plugins/access.swift/class.swiftAccessDriver.php
  15. +2 −2 core/src/plugins/action.disclaimer/class.DisclaimerProvider.php
  16. +1 −1 core/src/plugins/action.powerfs/class.PowerFSController.php
  17. +7 −3 core/src/plugins/action.scheduler/class.AjxpScheduler.php
  18. +4 −4 core/src/plugins/action.share/src/ShareCenter.php
  19. +3 −3 core/src/plugins/action.skeleton/class.PluginSkeleton.php
  20. +2 −2 core/src/plugins/action.updater/class.UpdateController.php
  21. +3 −4 core/src/plugins/auth.multi/class.multiAuthDriver.php
  22. +2 −2 core/src/plugins/authfront.multi/class.MultiAuthFrontend.php
  23. +1 −6 core/src/plugins/core.access/src/AbstractAccessDriver.php
  24. +5 −5 core/src/plugins/core.auth/class.AbstractAuthDriver.php
  25. +4 −4 core/src/plugins/core.conf/class.AbstractConfDriver.php
  26. +4 −3 core/src/plugins/core.index/class.AbstractSearchEngineIndexer.php
  27. +2 −2 core/src/plugins/core.notifications/class.AJXP_NotificationCenter.php
  28. +3 −1 core/src/plugins/gui.mobile/class.MobileGuiPlugin.php
  29. +3 −2 core/src/plugins/gui.user/class.UserGuiController.php
  30. +4 −3 core/src/plugins/meta.filehasher/class.FileHasher.php
  31. +0 −1 core/src/plugins/metastore.s3/class.s3MetaStore.php
  32. +0 −1 core/src/plugins/metastore.serial/class.SerialMetaStore.php
  33. +1 −8 core/src/plugins/mq.serial/class.AJXP_SerialMessageExchanger.php
  34. +0 −8 core/src/plugins/mq.sql/class.AJXP_SqlMessageExchanger.php
@@ -289,24 +289,6 @@ public static function executableRequest(ContextInterface $context, $action, $pa
*/
public static function applyActionInBackground($currentRepositoryId, $actionName, $parameters, $user ="", $statusFile = "", $taskId = null)
{
-/*
- if (empty($user)) {
- if(AuthService::usersEnabled() && AuthService::getLoggedUser() !== null) $user = AuthService::getLoggedUser()->getId();
- else $user = "shared";
- }
- $fName = AJXP_DATA_PATH."/plugins/mq.serial/worker-queue";
- $fData = file_get_contents($fName);
- $data = json_decode($fData, true);
- $data[] = array(
- "userId" => $user,
- "repoId" => $currentRepositoryId,
- "actionName" => $actionName,
- "parameters" => $parameters
- );
- file_put_contents($fName, json_encode($data));
- return ;
-*/
-
$token = md5(time());
$logDir = AJXP_CACHE_DIR."/cmd_outputs";
@@ -319,22 +301,7 @@ public static function applyActionInBackground($currentRepositoryId, $actionName
$user = "shared";
}
}
-/*
- require_once(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/core.mq/vendor/autoload.php");
- $nsq = new nsqphp\nsqphp;
- $nsq->publishTo("localhost", 1);
- $payload = array(
- 'msg' => 'bg',
- 'data' => [
- 'repository_id' => $currentRepositoryId,
- 'user_id' => $user,
- 'action' => $actionName,
- 'parameters' => $parameters
- ]);
- $nsq->publish('pydio', new nsqphp\Message\Message(json_encode($payload)));
-
- return;
-*/
+
if (Services\AuthService::usersEnabled()) {
$cKey = ConfService::getCoreConf("AJXP_CLI_SECRET_KEY", "conf");
if(empty($cKey)){
@@ -22,6 +22,8 @@
use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\Repository;
+use Pydio\Core\Model\Context;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\AuthService;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\ConfService;
@@ -157,6 +159,15 @@ public function init($options)
$this->options = array_merge($this->loadOptionsDefaults(), $options);
}
+ protected function getContextualOption(ContextInterface $ctx, $optionName){
+ if($ctx->hasRepository()){
+ $repo = $ctx->getRepository();
+ }else{
+ $repo = AJXP_REPO_SCOPE_ALL;
+ }
+ return $this->getFilteredOption($optionName, $repo, $ctx->getUser());
+ }
+
/**
* @param string $optionName
* @param string|\Pydio\Access\Core\Model\Repository $repositoryScope
@@ -246,9 +257,10 @@ public function isEnabled()
/**
* Main function for loading all the nodes under registry_contributions.
+ * @param ContextInterface $ctx
* @param bool $dry
*/
- protected function loadRegistryContributions($dry = false)
+ protected function loadRegistryContributions(ContextInterface $ctx, $dry = false)
{
if($this->manifestXML != null) $this->unserializeManifest();
$regNodes = $this->xPath->query("registry_contributions/*");
@@ -271,11 +283,11 @@ protected function loadRegistryContributions($dry = false)
} else {
$exclude = array();
}
- $this->initXmlContributionFile($filename, $include, $exclude, $dry);
+ $this->initXmlContributionFile($ctx, $filename, $include, $exclude, $dry);
} else {
if (!$dry) {
$this->registryContributions[]=$regNode;
- $this->parseSpecificContributions($regNode);
+ $this->parseSpecificContributions($ctx, $regNode);
}
}
}
@@ -291,26 +303,27 @@ protected function loadRegistryContributions($dry = false)
}
if (!$dry) {
$this->registryContributions[]=$pluginContrib->documentElement;
- $this->parseSpecificContributions($pluginContrib->documentElement);
+ $this->parseSpecificContributions($ctx, $pluginContrib->documentElement);
$this->contributionsLoaded = true;
}
}
/**
* Load an external XML file and include/exclude its nodes as contributions.
+ * @param ContextInterface $ctx
* @param string $xmlFile Path to the file from the base install path
* @param array $include XPath query for XML Nodes to include
* @param array $exclude XPath query for XML Nodes to exclude from the included ones.
* @param bool $dry Dry-run of the inclusion
*/
- protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclude=array(), $dry = false)
+ protected function initXmlContributionFile(ContextInterface $ctx, $xmlFile, $include=array("*"), $exclude=array(), $dry = false)
{
$contribDoc = new \DOMDocument();
$contribDoc->load(AJXP_INSTALL_PATH."/".$xmlFile);
if (!is_array($include) && !is_array($exclude)) {
if (!$dry) {
$this->registryContributions[] = $contribDoc->documentElement;
- $this->parseSpecificContributions($contribDoc->documentElement);
+ $this->parseSpecificContributions($ctx, $contribDoc->documentElement);
}
return;
}
@@ -365,7 +378,7 @@ protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclu
}
if (!$dry) {
$this->registryContributions[] = $node;
- $this->parseSpecificContributions($node);
+ $this->parseSpecificContributions($ctx, $node);
} else {
$this->reloadXPath();
}
@@ -374,10 +387,11 @@ protected function initXmlContributionFile($xmlFile, $include=array("*"), $exclu
/**
* Dynamically modify some registry contributions nodes. Can be easily derivated to enable/disable
* some features dynamically during plugin initialization.
+ * @param ContextInterface $ctx
* @param \DOMNode $contribNode
* @return void
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
//Append plugin id to callback tags
$callbacks = $contribNode->getElementsByTagName("serverCallback");
@@ -501,7 +515,7 @@ protected function unserializeManifest(){
public function getManifestRawContent($xmlNodeName = "", $format = "string", $externalFiles = false)
{
if ($externalFiles && !$this->externalFilesAppended) {
- $this->loadRegistryContributions(true);
+ $this->loadRegistryContributions(Context::fromGlobalServices(), true);
$this->externalFilesAppended = true;
}
if($this->manifestXML != null) $this->unserializeManifest();
@@ -527,13 +541,14 @@ public function getManifestRawContent($xmlNodeName = "", $format = "string", $ex
/**
* Return the registry contributions. The parameter can be used by subclasses to optimize the size of the XML returned :
* the extended version is called when sending to the client, whereas the "small" version is loaded to find and apply actions.
+ * @param ContextInterface $ctx
* @param bool $extendedVersion Can be used by subclasses to optimize the size of the XML returned.
* @return array
*/
- public function getRegistryContributions($extendedVersion = true)
+ public function getRegistryContributions(ContextInterface $ctx, $extendedVersion = true)
{
if (!$this->contributionsLoaded) {
- $this->loadRegistryContributions();
+ $this->loadRegistryContributions($ctx);
}
return $this->registryContributions;
}
@@ -884,7 +884,7 @@ private function buildXmlRegistry($extendedVersion = true)
foreach ($actives as $activeName=>$status) {
if($status === false) continue;
$plug = $this->getPluginById($activeName);
- $contribs = $plug->getRegistryContributions($extendedVersion);
+ $contribs = $plug->getRegistryContributions($this->context, $extendedVersion);
foreach ($contribs as $contrib) {
$parent = $contrib->nodeName;
$nodes = $contrib->childNodes;
@@ -329,11 +329,14 @@ public function listAllActions($action, $httpVars, $fileVars, ContextInterface $
}
}
- public function parseSpecificContributions(&$contribNode)
+ /**
+ * @inheritdoc
+ */
+ public function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return;
- $currentUserIsGroupAdmin = (AuthService::getLoggedUser() != null && AuthService::getLoggedUser()->getGroupPath() != "/");
+ $currentUserIsGroupAdmin = ($ctx->hasUser() && $ctx->getUser()->getGroupPath() != "/");
if(!$currentUserIsGroupAdmin) return;
$actionXpath=new DOMXPath($contribNode->ownerDocument);
$publicUrlNodeList = $actionXpath->query('action[@name="create_repository"]/subMenu', $contribNode);
@@ -22,6 +22,7 @@
namespace Pydio\Access\Driver\DataProvider;
use DOMXPath;
use Pydio\Access\Core\AbstractAccessDriver;
+use Pydio\Core\Model\ContextInterface;
defined('AJXP_EXEC') or die( 'Access not allowed');
/**
@@ -33,19 +34,19 @@
class HomePagePlugin extends AbstractAccessDriver
{
- public function parseSpecificContributions(&$contribNode){
- parent::parseSpecificContributions($contribNode);
+ public function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode){
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName == "client_configs"){
$actionXpath=new DOMXPath($contribNode->ownerDocument);
$gettingStartedList = $actionXpath->query('template[@name="tutorial_pane"]', $contribNode);
if(!$gettingStartedList->length) return ;
- if($this->getFilteredOption("ENABLE_GETTING_STARTED") === false){
+ if($this->getContextualOption($ctx, "ENABLE_GETTING_STARTED") === false){
$contribNode->removeChild($gettingStartedList->item(0));
}else{
$cdata = $gettingStartedList->item(0)->firstChild;
$keys = array("URL_APP_IOSAPPSTORE", "URL_APP_ANDROID", "URL_APP_SYNC_WIN", "URL_APP_SYNC_MAC");
$values = array();
- foreach($keys as $k) $values[] = $this->getFilteredOption($k);
+ foreach($keys as $k) $values[] = $this->getContextualOption($ctx, $k);
$newData = str_replace($keys, $values, $cdata->nodeValue);
$newCData = $contribNode->ownerDocument->createCDATASection($newData);
$gettingStartedList->item(0)->appendChild($newCData);
@@ -54,16 +54,16 @@ public function initRepository()
require_once AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/action.share/vendor/autoload.php";
}
- public function parseSpecificContributions(&$contribNode){
- $disableAddressBook = $this->getFilteredOption("DASH_DISABLE_ADDRESS_BOOK") === true;
+ public function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode){
+ $disableAddressBook = $this->getContextualOption($ctx, "DASH_DISABLE_ADDRESS_BOOK") === true;
if($contribNode->nodeName == "client_configs" && $disableAddressBook){
// remove template_part for orbit_content
$xPath=new DOMXPath($contribNode->ownerDocument);
$tplNodeList = $xPath->query('component_config[@className="AjxpTabulator::userdashboard_main_tab"]', $contribNode);
if(!$tplNodeList->length) return ;
$contribNode->removeChild($tplNodeList->item(0));
}
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
}
public function switchAction(ServerRequestInterface $requestInterface, ResponseInterface &$responseInterface)
@@ -567,8 +567,8 @@ public function downloadAction(ServerRequestInterface &$request, ResponseInterfa
$file = Utils::getAjxpTmpDir()."/".($loggedUser?$loggedUser->getId():"shared")."_".time()."tmpDownload.zip";
$zipFile = $this->makeZip($selection->getFiles(), $file, empty($dir)?"/":$dir);
if(!$zipFile) throw new PydioException("Error while compressing");
- if(!$this->getFilteredOption("USE_XSENDFILE", $this->repository)
- && !$this->getFilteredOption("USE_XACCELREDIRECT", $this->repository)){
+ if(!$this->getContextualOption($ctx, "USE_XSENDFILE")
+ && !$this->getContextualOption($ctx, "USE_XACCELREDIRECT")){
register_shutdown_function("unlink", $file);
}
$localName = (empty($base)?"Files":$base).".zip";
@@ -1375,7 +1375,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
array_map(array($nodesList, "addBranch"), $fullList["f"]);
// ADD RECYCLE BIN TO THE LIST
- if ($dir == "" && $lsOptions["d"] && RecycleBinManager::recycleEnabled() && $this->getFilteredOption("HIDE_RECYCLE", $this->repository) !== true) {
+ if ($dir == "" && $lsOptions["d"] && RecycleBinManager::recycleEnabled() && $this->getContextualOption($ctx, "HIDE_RECYCLE") !== true) {
$recycleBinOption = RecycleBinManager::getRelativeRecycle();
if (file_exists($this->urlBase.$recycleBinOption)) {
$recycleNode = new AJXP_Node($this->urlBase.$recycleBinOption);
@@ -65,11 +65,12 @@ public function loadManifest()
/**
* Parse
+ * @param ContextInterface $ctx
* @param DOMNode $contribNode
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return ;
$this->disableArchiveBrowsingContributions($contribNode);
$this->redirectActionsToMethod($contribNode, array("upload", "next_to_remote", "trigger_remote_copy"), "uploadActions");
@@ -24,6 +24,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Utils\Utils;
defined('AJXP_EXEC') or die( 'Access not allowed');
@@ -158,11 +159,11 @@ public function attachmentDLName($currentNode, &$localName, $wrapperClassName)
/**
* Parse
- * @param DOMNode $contribNode
+ * @inheritdoc
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return ;
$this->disableArchiveBrowsingContributions($contribNode);
}
@@ -26,6 +26,7 @@
use Pydio\Access\Core\RecycleBinManager;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Exception\PydioException;
@@ -168,13 +169,12 @@ public function directoryUsage($directoryPath, $repositoryResolvedOptions = []){
}
- /**
- * Parse
- * @param DOMNode $contribNode
+ /**
+ * @inheritdoc
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return ;
$this->disableArchiveBrowsingContributions($contribNode);
}
@@ -28,6 +28,7 @@
use Pydio\Access\Core\RecycleBinManager;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Controller\Controller;
use Pydio\Core\Exception\PydioException;
@@ -82,17 +83,15 @@ public function initRepository()
}
/**
- * Parse
- * @param DOMNode $contribNode
+ * @inheritdoc
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return ;
$this->disableArchiveBrowsingContributions($contribNode);
}
-
protected function filecopy($srcFile, $destFile)
{
if (AJXP_MetaStreamWrapper::nodesUseSameWrappers($srcFile, $destFile)) {
@@ -25,6 +25,7 @@
use DOMNode;
use PclZip;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
+use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
defined('AJXP_EXEC') or die( 'Access not allowed' );
@@ -81,12 +82,11 @@ public function detectStreamWrapper($register = false)
}
/**
- * Parse
- * @param DOMNode $contribNode
+ * @inheritdoc
*/
- protected function parseSpecificContributions(&$contribNode)
+ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
{
- parent::parseSpecificContributions($contribNode);
+ parent::parseSpecificContributions($ctx, $contribNode);
if($contribNode->nodeName != "actions") return ;
$this->disableArchiveBrowsingContributions($contribNode);
}
Oops, something went wrong.

0 comments on commit 9093ccc

Please sign in to comment.