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

Commit

Permalink
Hunting for AuthService::getLoggedUser() usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 7, 2016
1 parent a601082 commit 320b714
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 154 deletions.
4 changes: 3 additions & 1 deletion core/src/core/src/pydio/Core/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ public static function run(ServerRequestInterface $request, &$actionNode = null)
}
$actionNode = $actions->item(0);
}
/** @var ContextInterface $ctx */
$ctx = $request->getAttribute("ctx");
//Check Rights
if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser();
$loggedUser = $ctx->getUser();
if( $actionName != "logout" && Controller::actionNeedsRight($actionNode, $xPath, "userLogged", "only") && $loggedUser == null){
throw new AuthRequiredException();
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/core/src/pydio/Core/Utils/JSPacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function pack()
* @param $mode
* @return bool
*/
public function concatListAndPack($src, $out, $mode)
public static function concatListAndPack($src, $out, $mode)
{
if (!is_file($src) || !is_readable($src)) {
return false;
Expand Down
4 changes: 0 additions & 4 deletions core/src/plugins/editor.browser/class.FileMimeSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public function switchAction($action, $httpVars, $filesVars, \Pydio\Core\Model\C

if (AuthService::usersEnabled()) {
$loggedUser = $ctx->getUser();
if ($loggedUser === null && ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) {
AuthService::logUser("guest", null);
$loggedUser = AuthService::getLoggedUser();
}
if (!$loggedUser->canSwitchTo($repository->getId())) {
echo("You do not have permissions to access this resource");
return false;
Expand Down
15 changes: 0 additions & 15 deletions core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,7 @@ public function getBootGui(ServerRequestInterface &$request, ResponseInterface &
"REBASE" => $root
);
if (AuthService::usersEnabled()) {
//AuthService::preLogUser((isSet($httpVars["remote_session"])?$httpVars["remote_session"]:""));
AuthService::bootSequence($START_PARAMETERS);
/*
if (AuthService::getLoggedUser() != null || AuthService::logUser(null, null) == 1) {
if (AuthService::getDefaultRootId() == -1) {
AuthService::disconnect();
} else {
$loggedUser = AuthService::getLoggedUser();
if(!$loggedUser->canRead(ConfService::getCurrentRepositoryId())
&& AuthService::getDefaultRootId() != ConfService::getCurrentRepositoryId())
{
ConfService::switchRootDir(AuthService::getDefaultRootId());
}
}
}
*/
}

Utils::parseApplicationGetParameters($ctx, $_GET, $START_PARAMETERS, $_SESSION);
Expand Down
10 changes: 5 additions & 5 deletions core/src/plugins/index.elasticsearch/class.AjxpElasticSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ public function recursiveIndexation($url)
public function updateNodeIndexMeta($node)
{
$this->loadIndex($node->getContext(), true);
if (AuthService::usersEnabled() && AuthService::getLoggedUser()!=null) {
if (AuthService::usersEnabled() && $node->getContext()->hasUser()) {

$query = new Elastica\Query\Term();
$query->setTerm("node_url", $node->getUrl());
$results = $this->currentType->search($query);
$hits = $results->getResults();
foreach ($hits as $hit) {
$source = $hit->getSource();
if ($source['ajxp_scope'] == 'shared' || ($source['ajxp_scope'] == 'user' && $source['ajxp_user'] == AuthService::getLoggedUser()->getId())) {
if ($source['ajxp_scope'] == 'shared' || ($source['ajxp_scope'] == 'user' && $source['ajxp_user'] == $node->getContext()->getUser()->getId())) {
$this->currentType->deleteById($hit->getId());
}
}
Expand Down Expand Up @@ -574,16 +574,16 @@ public function createIndexedDocument($ajxpNode)
$this->currentType->addDocument($doc);
$this->nextId++;

if (isSet($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
if (isSet($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && $ajxpNode->getContext()->hasUser()) {

$userData = array(
"ajxp_scope" => "user",
"user" => AuthService::getLoggedUser()->getId(),
"user" => $ajxpNode->getUser()->getId(),
"serialized_metadata" => $data["serialized_metadata"],
"node_url" => $data["node_url"],
"node_path" => $data["node_path"]
);
$userData["ajxp_user"] = AuthService::getLoggedUser()->getId();
$userData["ajxp_user"] = $ajxpNode->getContext()->getUser()->getId();
foreach ($ajxpNode->indexableMetaKeys["user"] as $userField) {
if ($ajxpNode->$userField) {
$userData[$userField] = $ajxpNode->$userField;
Expand Down
8 changes: 4 additions & 4 deletions core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ public function updateNodeIndexMeta($node)
}
Zend_Search_Lucene_Analysis_Analyzer::setDefault( new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

if (AuthService::usersEnabled() && AuthService::getLoggedUser()!=null) {
if (AuthService::usersEnabled() && $node->getContext()->hasUser()) {
$term = new Zend_Search_Lucene_Index_Term(TextEncoder::toUTF8($node->getUrl()), "node_url");
$hits = $index->termDocs($term);
foreach ($hits as $hitId) {
$hit = $index->getDocument($hitId);
if ($hit->ajxp_scope == 'shared' || ($hit->ajxp_scope == 'user' && $hit->ajxp_user == AuthService::getLoggedUser()->getId())) {
if ($hit->ajxp_scope == 'shared' || ($hit->ajxp_scope == 'user' && $hit->ajxp_user == $node->getContext()->getUser()->getId())) {
$index->delete($hitId);
}
}
Expand Down Expand Up @@ -612,13 +612,13 @@ public function createIndexedDocument($ajxpNode, &$index)
$doc->addField(Zend_Search_Lucene_Field::Text("ajxp_meta_$field", $ajxpNode->$field), TextEncoder::getEncoding());
}
}
if (isSet($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
if (isSet($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && $ajxpNode->getContext()->hasUser() ) {
$privateDoc = new Zend_Search_Lucene_Document();
$privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_url", $ajxpNode->getUrl(), TextEncoder::getEncoding()));
$privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_path", str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath()), TextEncoder::getEncoding()));

$privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_scope", "user"));
$privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_user", AuthService::getLoggedUser()->getId()));
$privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_user", $ajxpNode->getContext()->getUser()->getId()));
foreach ($ajxpNode->indexableMetaKeys["user"] as $userField) {
if ($ajxpNode->$userField) {
$privateDoc->addField(Zend_search_Lucene_Field::keyword($userField, $ajxpNode->$userField));
Expand Down
26 changes: 12 additions & 14 deletions core/src/plugins/meta.git/class.GitManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,16 @@ protected function gitHistory($git, $file)
*/
public function changesHook($fromNode=null, $toNode=null, $copy=false)
{
$this->commitChanges();
$refNode = ($fromNode !== null ? $fromNode : $toNode);
$this->commitChanges($refNode->getContext());
return;
/*
$refNode = $fromNode;
if ($fromNode == null && $toNode != null) {
$refNode = $toNode;
}
$this->commitChanges(dirname($refNode->getPath()));
*/
}

private function commitChanges($path = null)
/**
* @param ContextInterface $ctx
* @param string $path
*/
private function commitChanges(ContextInterface $ctx, $path = null)
{
$git = new VersionControl_Git($this->repoBase);
$command = $git->getCommand("add");
Expand All @@ -306,18 +304,18 @@ private function commitChanges($path = null)
$cmd = $command->createCommandString();
$this->logDebug("Git command ".$cmd);
$res = $command->execute();
$this->logDebug("GIT RESULT ADD : ".$res);
} catch (Exception $e) {
$this->logDebug("Error ".$e->getMessage());
$this->logDebug("Error in GIT Command ".$e->getMessage());
}
$this->logDebug("GIT RESULT ADD : ".$res);

$command = $git->getCommand("commit");
$command->setOption("a", true);
$userId = "no user";
$mail = "mail@mail.com";
if (AuthService::getLoggedUser()!=null) {
$userId = AuthService::getLoggedUser()->getId();
$mail = AuthService::getLoggedUser()->personalRole->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "mail@mail.com");
if ($ctx->hasUser()) {
$userId = $ctx->getUser()->getId();
$mail = $ctx->getUser()->getPersonalRole()->filterParameterValue("core.conf", "email", AJXP_REPO_SCOPE_ALL, "mail@mail.com");
}
$command->setOption("m", $userId);
$command->setOption("author", "$userId <$mail>");
Expand Down
37 changes: 1 addition & 36 deletions core/src/plugins/meta.quota/class.QuotaComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,7 @@ class QuotaComputer extends AJXP_AbstractMetaSource
* @var AjxpMailer
*/
protected $mailer;

/**
* @return array
protected function getWorkingRepositoryOptions()
{
$p = array();
$repo = $this->accessDriver->repository;
$clearParent = null;
// SPECIAL : QUOTA MUST BE COMPUTED ON PARENT REPOSITORY FOLDER
if ($repo->hasParent()) {
$parentOwner = $repo->getOwner();
if ($parentOwner !== null) {
$repo = ConfService::getRepositoryById($repo->getParentId());
$originalUser = AuthService::getLoggedUser();
$loggedUser = AuthService::getLoggedUser();
if (!$loggedUser->hasParent()) {
$loggedUser->setParent($parentOwner);
$clearParent = null;
} else {
$clearParent = $loggedUser->getParent();
}
$loggedUser->setResolveAsParent(true);
AuthService::updateUser($loggedUser);
}
}
$path = $repo->getOption("PATH");
$p["PATH"] = $path;
if ( isSet($originalUser) ) {
$originalUser->setParent($clearParent);
$originalUser->setResolveAsParent(false);
AuthService::updateUser($originalUser);
}
return $p;
}
*/


/**
* @param ContextInterface $ctx
* @return ContextInterface
Expand Down
7 changes: 5 additions & 2 deletions core/src/plugins/meta.simple_lock/class.SimpleLockManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ public function processLockMeta($node)
AJXP_METADATA_SCOPE_GLOBAL);
if(is_array($lock)
&& array_key_exists("lock_user", $lock)){
if ($lock["lock_user"] != AuthService::getLoggedUser()->getId()) {
if ($lock["lock_user"] != $node->getContext()->getUser()->getId()) {
$displayName = ConfService::getUserPersonalParameter("USER_DISPLAY_NAME", $lock["lock_user"], "core.conf", $lock["lock_user"]);
$node->setLabel($node->getLabel() . " (locked by ".$displayName.")");
$node->mergeMetadata(array(
"sl_locked" => "true",
"overlay_icon" => "meta_simple_lock/ICON_SIZE/lock.png",
"overlay_class" => "icon-lock"
), true);
} else {
$node->setLabel($node->getLabel() . " (locked by you)");
$node->mergeMetadata(array(
"sl_locked" => "true",
"sl_mylock" => "true",
Expand All @@ -146,7 +149,7 @@ public function checkFileLock($node)
AJXP_METADATA_SCOPE_GLOBAL);
if(is_array($lock)
&& array_key_exists("lock_user", $lock)
&& $lock["lock_user"] != AuthService::getLoggedUser()->getId()){
&& $lock["lock_user"] != $node->getUserId()){
$mess = ConfService::getMessages();
throw new Exception($mess["meta.simple_lock.5"]);
}
Expand Down
58 changes: 21 additions & 37 deletions core/src/plugins/meta.syncable/class.ChangesTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ protected function excludeFromSync($path){
return false;
}

protected function indexIsSync(){
/**
* @param ContextInterface $ctx
*/
protected function indexIsSync(ContextInterface $ctx){
// Grab all folders mtime and compare them
$repoIdentifier = $this->computeIdentifier($this->accessDriver->repository);
$repoIdentifier = $this->computeIdentifier($ctx);
$res = dibi::query("SELECT [node_path],[mtime] FROM [ajxp_index] WHERE [md5] = %s AND [repository_identifier] = %s", 'directory', $repoIdentifier);
$modified = array();

// REGISTER ROOT ANYWAY: WE PROBABLY CAN'T GET A "FILEMTIME" ON IT.
$mod = array(
"url" => $this->accessDriver->getResourceUrl(""),
"url" => $ctx->getUrlBase(),
"path" => "/",
"children" => array()
);
Expand All @@ -100,7 +103,7 @@ protected function indexIsSync(){
foreach($res as $row){
$path = $row->node_path;
$mtime = intval($row->mtime);
$url = $this->accessDriver->getResourceUrl($path);
$url = $ctx->getUrlBase().$path;
$currentTime = @filemtime($url);
if($currentTime === false && !file_exists($url)) {
// Deleted folder!
Expand Down Expand Up @@ -198,11 +201,11 @@ protected function getResyncTimestampFile(\Pydio\Core\Model\ContextInterface $ct
public function resyncAction($actionName, $httpVars, $fileVars, \Pydio\Core\Model\ContextInterface $contextInterface)
{
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
Controller::applyActionInBackground($contextInterface->getRepositoryId(), "resync_storage", $httpVars);
Controller::applyActionInBackground($contextInterface, "resync_storage", $httpVars);
}else{
$file = $this->getResyncTimestampFile($contextInterface, true);
file_put_contents($file, time());
$this->indexIsSync();
$this->indexIsSync($contextInterface);
}
}

Expand Down Expand Up @@ -261,7 +264,7 @@ public function switchActions($actionName, $httpVars, $fileVars, \Pydio\Core\Mod


$ands = array();
$ands[] = array("[ajxp_changes].[repository_identifier] = %s", $this->computeIdentifier($currentRepo));
$ands[] = array("[ajxp_changes].[repository_identifier] = %s", $this->computeIdentifier($contextInterface));
$ands[]= array("[seq] > %i", $seqId);
if(isSet($httpVars["filter"])) {
$filter = Utils::decodeSecureMagic($httpVars["filter"]);
Expand Down Expand Up @@ -453,40 +456,21 @@ protected function filterMasks(&$previousRow, $masks = array()){
}

/**
* @param Repository $repository
* @param null $resolveUserId
* @param ContextInterface $ctx
* @return String
*/
protected function computeIdentifier($repository, $resolveUserId = null)
protected function computeIdentifier(ContextInterface $ctx)
{
$parts = array($repository->getId());
$parts = array($ctx->getRepositoryId());
$repository = $ctx->getRepository();
if ($repository->securityScope() == 'USER') {
if($resolveUserId != null) {
$parts[] = $resolveUserId;
} else {
$parts[] = AuthService::getLoggedUser()->getId();
}
$parts[] = $ctx->getUser()->getId();
} else if ($repository->securityScope() == 'GROUP') {
if($resolveUserId != null) {
$userObject = ConfService::getConfStorageImpl()->createUserObject($resolveUserId);
if($userObject != null) $parts[] = $userObject->getGroupPath();
}else{
$parts[] = AuthService::getLoggedUser()->getGroupPath();
}
$parts[] = $ctx->getUser()->getGroupPath();
}
return implode("-", $parts);
}

/**
* @param Repository $repository
* @return float
*/
public function getRepositorySpaceUsage($repository){
$id = $this->computeIdentifier($repository);
$res = dibi::query("SELECT SUM([bytesize]) FROM [ajxp_index] WHERE [repository_identifier] = %s", $id);
return floatval($res->fetchSingle());
}

/**
* Called on workspace.after_delete event. Remove all references to this WS in the DB.
* Find all repo identifier exactly equal to $repoId , or like $repoId-%
Expand All @@ -509,7 +493,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
if(!dibi::isConnected()) {
dibi::connect($this->sqlDriver);
}
//$this->logInfo("Syncable index", array($oldNode == null?'null':$oldNode->getUrl(), $newNode == null?'null':$newNode->getUrl()));
$refNode = ($oldNode !== null ? $oldNode : $newNode);
try {
if ($newNode != null && $this->excludeNode($newNode)) {
// CREATE
Expand All @@ -522,7 +506,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
}
}
if ($newNode == null) {
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUserId());
$repoId = $this->computeIdentifier($refNode->getContext());
// DELETE
$this->logDebug('DELETE', $oldNode->getUrl());
dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", TextEncoder::toUTF8($oldNode->getPath()), $repoId);
Expand All @@ -536,7 +520,7 @@ 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(), $newNode->getUserId())
"repository_identifier" => $repoId = $this->computeIdentifier($refNode->getContext())
));
if($copy && !$newNode->isLeaf()){
// Make sure to index the content of this folder
Expand All @@ -546,7 +530,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
TaskService::getInstance()->enqueueTask($task);
}
} else {
$repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUserId());
$repoId = $this->computeIdentifier($refNode->getContext());
if ($oldNode->getPath() == $newNode->getPath()) {
// CONTENT CHANGE
clearstatcache();
Expand Down Expand Up @@ -614,7 +598,7 @@ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false
*/
public function computeSizeRecursive(&$node, &$result){

$id = $this->computeIdentifier($node->getRepository());
$id = $this->computeIdentifier($node->getContext());
$res = dibi::query("SELECT SUM([bytesize]) FROM [ajxp_index] WHERE [repository_identifier] = %s AND ([node_path] = %s OR [node_path] LIKE %s)", $id, $node->getPath(), rtrim($node->getPath(), "/")."/%");
$result = floatval($res->fetchSingle());

Expand Down
Loading

0 comments on commit 320b714

Please sign in to comment.