Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Pass a context when building/parsing registry contributions in plugin…
Browse files Browse the repository at this point in the history
…s. Still todo in init/initRepository/initMeta methods
  • Loading branch information
cdujeu committed Jun 4, 2016
1 parent c4ff2e6 commit 9093ccc
Show file tree
Hide file tree
Showing 34 changed files with 124 additions and 151 deletions.
35 changes: 1 addition & 34 deletions core/src/core/src/pydio/Core/Controller/Controller.php
Expand Up @@ -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";
Expand All @@ -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)){
Expand Down
37 changes: 26 additions & 11 deletions core/src/core/src/pydio/Core/PluginFramework/Plugin.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/*");
Expand All @@ -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);
}
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions core/src/plugins/access.ajxp_home/class.HomePagePlugin.php
Expand Up @@ -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');
/**
Expand All @@ -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);
Expand Down
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/access.fs/class.fsAccessDriver.php
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/access.ftp/class.ftpAccessDriver.php
Expand Up @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions core/src/plugins/access.imap/class.imapAccessDriver.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/plugins/access.s3/class.s3AccessDriver.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 4 additions & 5 deletions core/src/plugins/access.sftp/class.sftpAccessDriver.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
Expand Up @@ -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' );
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9093ccc

Please sign in to comment.