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

Commit

Permalink
Transport a contextual user ID as a node property or through the URL.
Browse files Browse the repository at this point in the history
Pass a contextual user to the VarsFilter::filter() function
Fix shareEventsForwarding when in a personal workspace (shared events not going to parents, preventing sync for example)
  • Loading branch information
cdujeu committed Feb 16, 2015
1 parent f81ab4b commit 5a32597
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 42 deletions.
4 changes: 4 additions & 0 deletions core/src/core/classes/class.AJXP_Node.php
Expand Up @@ -415,6 +415,10 @@ public function getUser(){
*/
public function setUser($userId){
$this->_user = $userId;
$this->urlParts["user"] = $userId;
// Update url with a user@workspaceID
$crt = $this->getScheme()."://".$this->getRepositoryId();
$this->_url = str_replace($crt, $this->getScheme()."://".$this->_user."@".$this->getRepositoryId(), $this->_url);
}

/**
Expand Down
29 changes: 19 additions & 10 deletions core/src/core/classes/class.AJXP_VarsFilter.php
Expand Up @@ -33,30 +33,39 @@ class AJXP_VarsFilter
* Calls the vars.filter hooks.
* @static
* @param $value
* @param AbstractAjxpUser $resolveUser
* @return mixed|string
*/
public static function filter($value)
public static function filter($value, $resolveUser = null)
{
if (is_string($value) && strpos($value, "AJXP_USER")!==false) {
if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser();
if ($loggedUser != null) {
if ($loggedUser->hasParent() && $loggedUser->getResolveAsParent()) {
$loggedUserId = $loggedUser->getParent();
if($resolveUser != null){
$value = str_replace("AJXP_USER", $resolveUser->getId(), $value);
}else{
$loggedUser = AuthService::getLoggedUser();
if ($loggedUser != null) {
if ($loggedUser->hasParent() && $loggedUser->getResolveAsParent()) {
$loggedUserId = $loggedUser->getParent();
} else {
$loggedUserId = $loggedUser->getId();
}
$value = str_replace("AJXP_USER", $loggedUserId, $value);
} else {
$loggedUserId = $loggedUser->getId();
return "";
}
$value = str_replace("AJXP_USER", $loggedUserId, $value);
} else {
return "";
}
} else {
$value = str_replace("AJXP_USER", "shared", $value);
}
}
if (is_string($value) && strpos($value, "AJXP_GROUP_PATH")!==false) {
if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser();
if($resolveUser != null){
$loggedUser = $resolveUser;
}else{
$loggedUser = AuthService::getLoggedUser();
}
if ($loggedUser != null) {
$gPath = $loggedUser->getGroupPath();
$value = str_replace("AJXP_GROUP_PATH_FLAT", str_replace("/", "_", trim($gPath, "/")), $value);
Expand Down
5 changes: 3 additions & 2 deletions core/src/core/classes/class.Repository.php
Expand Up @@ -306,9 +306,10 @@ public function addOption($oName, $oValue)
* Get the repository options, filtered in various maners
* @param string $oName
* @param bool $safe Do not filter
* @param AbstractAjxpUser $resolveUser
* @return mixed|string
*/
public function getOption($oName, $safe=false)
public function getOption($oName, $safe=false, $resolveUser = null)
{
if (!$safe && $this->inferOptionsFromParent) {
if (!isset($this->parentTemplateObject)) {
Expand All @@ -324,7 +325,7 @@ public function getOption($oName, $safe=false)
}
if (isSet($this->options[$oName])) {
$value = $this->options[$oName];
if(!$safe) $value = AJXP_VarsFilter::filter($value);
if(!$safe) $value = AJXP_VarsFilter::filter($value, $resolveUser);
return $value;
}
if ($this->inferOptionsFromParent) {
Expand Down
13 changes: 10 additions & 3 deletions core/src/plugins/access.fs/class.fsAccessWrapper.php
Expand Up @@ -78,6 +78,13 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
if($split && $streamType == "file" && $split[1] != "/") $insideZip = true;
if($split && $streamType == "dir") $insideZip = true;
if($skipZip) $insideZip = false;

$resolveUser = null;
if(isSet($url["user"]) && AuthService::usersEnabled()){
$resolveUser = ConfService::getConfStorageImpl()->createUserObject($url["user"]);
}
$resolvedPath = realpath(SystemTextEncoding::toStorageEncoding($repoObject->getOption("PATH", false, $resolveUser)));

//var_dump($path);
//var_dump($skipZip);
// Inside a zip : copy the file to a tmp file and return a reference to it
Expand All @@ -93,7 +100,7 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
$tmpFileName = $tmpDir.DIRECTORY_SEPARATOR.basename($localPath);
AJXP_Logger::debug(__CLASS__,__FUNCTION__,"Tmp file $tmpFileName");
register_shutdown_function(array("fsAccessWrapper", "removeTmpFile"), $tmpDir, $tmpFileName);
$crtZip = new PclZip(AJXP_Utils::securePath(realpath(SystemTextEncoding::toStorageEncoding($repoObject->getOption("PATH"))).$repoObject->resolveVirtualRoots($zipPath)));
$crtZip = new PclZip(AJXP_Utils::securePath($resolvedPath.$repoObject->resolveVirtualRoots($zipPath)));
$content = $crtZip->listContent();
foreach ($content as $item) {
$fName = AJXP_Utils::securePath($item["stored_filename"]);
Expand All @@ -116,7 +123,7 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
}
}
} else {
$crtZip = new PclZip(AJXP_Utils::securePath(realpath(SystemTextEncoding::toStorageEncoding($repoObject->getOption("PATH"))).$repoObject->resolveVirtualRoots($zipPath)));
$crtZip = new PclZip(AJXP_Utils::securePath($resolvedPath.$repoObject->resolveVirtualRoots($zipPath)));
$liste = $crtZip->listContent();
if($storeOpenContext) self::$crtZip = $crtZip;
$folders = array(); $files = array();$builtFolders = array();
Expand Down Expand Up @@ -178,7 +185,7 @@ protected static function initPath($path, $streamType, $storeOpenContext = false
return -1;
}
}
return realpath(SystemTextEncoding::toStorageEncoding($repoObject->getOption("PATH"))).$repoObject->resolveVirtualRoots($url["path"]);
return $resolvedPath.$repoObject->resolveVirtualRoots($url["path"]);
}
}

Expand Down
11 changes: 9 additions & 2 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -604,11 +604,18 @@ private function findMirrorNodesInShares($node, $direction){
if($node->getRepository()->hasParent()){
$parentRepoId = $node->getRepository()->getParentId();
$currentRoot = $node->getRepository()->getOption("PATH");
$parentRoot = ConfService::getRepositoryById($parentRepoId)->getOption("PATH");
$owner = $node->getRepository()->getOwner();
$resolveUser = null;
if($owner != null){
$resolveUser = ConfService::getConfStorageImpl()->createUserObject($owner);
}
$parentRoot = ConfService::getRepositoryById($parentRepoId)->getOption("PATH", false, $resolveUser);
$relative = substr($currentRoot, strlen($parentRoot));
$parentNodeURL = $node->getScheme()."://".$parentRepoId.$relative.$node->getPath();
$this->logDebug("action.share", "Should trigger on ".$parentNodeURL);
$result[$parentRepoId] = array(new AJXP_Node($parentNodeURL), "UP");
$parentNode = new AJXP_Node($parentNodeURL);
if($owner != null) $parentNode->setUser($owner);
$result[$parentRepoId] = array($parentNode, "UP");
}
}
return $result;
Expand Down
16 changes: 10 additions & 6 deletions core/src/plugins/core.mq/class.MqManager.php
Expand Up @@ -86,15 +86,17 @@ public function consumeQueue($action, $httpVars, $fileVars)
}

/**
* @param null AJXP_Node $origNode
* @param null AJXP_Node $newNode
* @param bool bool $copy
* @param AJXP_Node $origNode
* @param AJXP_Node $newNode
* @param bool $copy
*/
public function publishNodeChange($origNode = null, $newNode = null, $copy = false)
{
$content = "";$repo = "";
$content = "";$repo = "";$targetUserId=null;
$update = false;
if ($newNode != null) {
$repo = $newNode->getRepositoryId();
$targetUserId = $newNode->getUser();
$update = false;
$data = array();
if ($origNode != null && !$copy) {
Expand All @@ -107,11 +109,12 @@ public function publishNodeChange($origNode = null, $newNode = null, $copy = fal
}
if ($origNode != null && ! $update && !$copy) {
$repo = $origNode->getRepositoryId();
$targetUserId = $origNode->getUser();
$content = AJXP_XMLWriter::writeNodesDiff(array("REMOVE" => array($origNode->getPath())));
}
if (!empty($content) && $repo != "") {

$this->sendInstantMessage($content, $repo);
$this->sendInstantMessage($content, $repo, $targetUserId);

}

Expand All @@ -124,7 +127,8 @@ public function sendInstantMessage($xmlContent, $repositoryId, $targetUserId = n
} else {
$scope = ConfService::getRepositoryById($repositoryId)->securityScope();
if ($scope == "USER") {
$userId = AuthService::getLoggedUser()->getId();
if($targetUserId) $userId = $targetUserId;
else $userId = AuthService::getLoggedUser()->getId();
} else if ($scope == "GROUP") {
$gPath = AuthService::getLoggedUser()->getGroupPath();
} else if (isSet($targetUserId)) {
Expand Down
Expand Up @@ -91,8 +91,14 @@ public function persistChangeHookToFeed(AJXP_Node $oldNode = null, AJXP_Node $ne

$n = ($oldNode == null ? $newNode : $oldNode);
$repoId = $n->getRepositoryId();
$userId = AuthService::getLoggedUser()->getId();
$userGroup = AuthService::getLoggedUser()->getGroupPath();
if($n->getUser()){
$userId = $n->getUser();
$obj = ConfService::getConfStorageImpl()->createUserObject($userId);
if($obj) $userGroup = $obj->getGroupPath();
}else{
$userId = AuthService::getLoggedUser()->getId();
$userGroup = AuthService::getLoggedUser()->getGroupPath();
}
$repository = ConfService::getRepositoryById($repoId);
$repositoryScope = $repository->securityScope();
$repositoryScope = ($repositoryScope !== false ? $repositoryScope : "ALL");
Expand Down
20 changes: 14 additions & 6 deletions core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php
Expand Up @@ -39,10 +39,10 @@ public function init($options)
parent::init($options);
set_include_path(get_include_path().PATH_SEPARATOR.AJXP_INSTALL_PATH."/plugins/index.lucene");
$metaFields = $this->getFilteredOption("index_meta_fields");
$specKey = $this->getFilteredOption("repository_specific_keywords");
if (!empty($metaFields)) {
$this->metaFields = explode(",",$metaFields);
}
$specKey = $this->getFilteredOption("repository_specific_keywords");
if (!empty($specKey)) {
$this->specificId = "-".str_replace(array(",", "/"), array("-", "__"), AJXP_VarsFilter::filter($specKey));
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public function updateNodeIndexMeta($node)
if (isSet($this->currentIndex)) {
$index = $this->currentIndex;
} else {
$index = $this->loadIndex($node->getRepositoryId());
$index = $this->loadIndex($node->getRepositoryId(), true, $node->getUser());
}
Zend_Search_Lucene_Analysis_Analyzer::setDefault( new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

Expand Down Expand Up @@ -453,9 +453,9 @@ public function updateNodeIndex($oldNode, $newNode = null, $copy = false, $recur
$index = $this->currentIndex;
} else {
if($oldNode == null){
$index = $this->loadIndex($newNode->getRepositoryId());
$index = $this->loadIndex($newNode->getRepositoryId(), true, $newNode->getUser());
}else{
$index = $this->loadIndex($oldNode->getRepositoryId());
$index = $this->loadIndex($oldNode->getRepositoryId(), true, $newNode->getUser());
}
}
$this->setDefaultAnalyzer();
Expand Down Expand Up @@ -687,11 +687,19 @@ protected function releaseLock($repositoryId)
* @param bool $create
* @return Zend_Search_Lucene_Interface the index
*/
protected function loadIndex($repositoryId, $create = true)
protected function loadIndex($repositoryId, $create = true, $resolveUserId = null)
{
require_once("Zend/Search/Lucene.php");
$mainCacheDir = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR);
$iPath = $mainCacheDir."/indexes/index-$repositoryId".$this->specificId;
$specificId = $this->specificId;
if($resolveUserId != null){
$specKey = $this->getFilteredOption("repository_specific_keywords");
if (!empty($specKey)) {
$specKey = str_replace("AJXP_USER", $resolveUserId, $specKey);
$specificId = "-".str_replace(array(",", "/"), array("-", "__"), AJXP_VarsFilter::filter($specKey));
}
}
$iPath = $mainCacheDir."/indexes/index-$repositoryId".$specificId;
if(!is_dir($mainCacheDir."/indexes")) mkdir($mainCacheDir."/indexes",0755,true);
if (is_dir($iPath)) {
$index = Zend_Search_Lucene::open($iPath);
Expand Down
21 changes: 15 additions & 6 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
Expand Up @@ -292,13 +292,22 @@ protected function filterRow(&$previousRow, $filter = null){
* @param Repository $repository
* @return String
*/
protected function computeIdentifier($repository)
protected function computeIdentifier($repository, $resolveUserId = null)
{
$parts = array($repository->getId());
if ($repository->securityScope() == 'USER') {
$parts[] = AuthService::getLoggedUser()->getId();
if($resolveUserId != null) {
$parts[] = $resolveUserId;
} else {
$parts[] = AuthService::getLoggedUser()->getId();
}
} else if ($repository->securityScope() == 'GROUP') {
$parts[] = AuthService::getLoggedUser()->getGroupPath();
if($resolveUserId != null) {
$userObject = ConfService::getConfStorageImpl()->createUserObject($resolveUserId);
if($userObject != null) $parts[] = $userObject->getGroupPath();
}else{
$parts[] = AuthService::getLoggedUser()->getGroupPath();
}
}
return implode("-", $parts);
}
Expand Down Expand Up @@ -335,7 +344,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
}
}
if ($newNode == null) {
$repoId = $this->computeIdentifier($oldNode->getRepository());
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser());
// DELETE
dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
} else if ($oldNode == null || $copy) {
Expand All @@ -346,10 +355,10 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
"bytesize" => $stat["size"],
"mtime" => $stat["mtime"],
"md5" => $newNode->isLeaf()? md5_file($newNode->getUrl()):"directory",
"repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository())
"repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository(), $newNode->getUser())
));
} else {
$repoId = $this->computeIdentifier($oldNode->getRepository());
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser());
if ($oldNode->getPath() == $newNode->getPath()) {
// CONTENT CHANGE
clearstatcache();
Expand Down
19 changes: 14 additions & 5 deletions core/src/plugins/metastore.serial/class.SerialMetaStore.php
Expand Up @@ -137,16 +137,25 @@ public function enrichNode(&$ajxpNode)
$ajxpNode->mergeMetadata($allMeta);
}

protected function updateSecurityScope($metaFile, $repositoryId)
protected function updateSecurityScope($metaFile, $repositoryId, $resolveUserId = null)
{
$repo = ConfService::getRepositoryById($repositoryId);
if (!is_object($repo)) {
return $metaFile;
}
$securityScope = $repo->securityScope();
if($securityScope == false) return $metaFile;

if (AuthService::getLoggedUser() != null) {
if($resolveUserId != null){
if ($securityScope == "USER") {
$metaFile .= "_".$resolveUserId;
}else if($securityScope == "GROUP"){
$uObj= ConfService::getConfStorageImpl()->createUserObject($resolveUserId);
if($uObj != null){
$u = str_replace("/", "__", $uObj->getGroupPath());
$metaFile.= "_".$u;
}
}
}else if (AuthService::getLoggedUser() != null) {
if ($securityScope == "USER") {
$u = AuthService::getLoggedUser();
if($u->getResolveAsParent()) $id = $u->getParent();
Expand Down Expand Up @@ -186,7 +195,7 @@ protected function loadMetaFileData($ajxpNode, $scope, $userId)
$fileKey = basename($fileKey);
} else {
$metaFile = $this->globalMetaFile."_".$ajxpNode->getRepositoryId();
$metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId());
$metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId(), $ajxpNode->getUser());
}
self::$metaCache = array();
if (!isSet(self::$fullMetaCache[$metaFile])) {
Expand Down Expand Up @@ -237,7 +246,7 @@ protected function saveMetaFileData($ajxpNode, $scope, $userId)
mkdir(dirname($this->globalMetaFile), 0755, true);
}
$metaFile = $this->globalMetaFile."_".$repositoryId;
$metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId());
$metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId(), $ajxpNode->getUser());
}
if($scope==AJXP_METADATA_SCOPE_REPOSITORY
|| (@is_file($metaFile) && call_user_func(array($this->accessDriver, "isWriteable"), $metaFile))
Expand Down

0 comments on commit 5a32597

Please sign in to comment.