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

Commit

Permalink
Hunting AuthService::getLoggedUser to replace with Context
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jun 6, 2016
1 parent baf6bd0 commit 2cf2a73
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 124 deletions.
12 changes: 7 additions & 5 deletions core/src/core/src/pydio/Core/Controller/XMLWriter.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@


use Pydio\Access\Core\Model\AJXP_Node; use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\IAjxpWrapperProvider; use Pydio\Access\Core\IAjxpWrapperProvider;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\RepositoryInterface; use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Utils\Utils; use Pydio\Core\Utils\Utils;
use Pydio\Core\Services; use Pydio\Core\Services;
use Pydio\Core\Services\AuthService;
use Pydio\Conf\Core\AbstractAjxpUser; use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Core\Services\ConfService; use Pydio\Core\Services\ConfService;
use Pydio\Core\PluginFramework\PluginsService; use Pydio\Core\PluginFramework\PluginsService;
Expand Down Expand Up @@ -498,24 +498,26 @@ public static function sendMessage($logMessage, $errorMessage, $print = true)
/** /**
* Extract all the user data and put it in XML * Extract all the user data and put it in XML
* @static * @static
* @param ContextInterface $ctx
* @param AbstractAjxpUser|null $userObject * @param AbstractAjxpUser|null $userObject
* @return string * @return string
*/ */
public static function getUserXML($userObject = null) public static function getUserXML(ContextInterface $ctx, $userObject = null)
{ {
$buffer = ""; $buffer = "";
$loggedUser = AuthService::getLoggedUser(); $loggedUser = $ctx->getUser();
$currentRepoId = $ctx->getRepositoryId();
$confDriver = ConfService::getConfStorageImpl(); $confDriver = ConfService::getConfStorageImpl();
if($userObject != null) $loggedUser = $userObject; if($userObject != null) $loggedUser = $userObject;
if (!Services\AuthService::usersEnabled()) { if (!Services\AuthService::usersEnabled()) {
$buffer.="<user id=\"shared\">"; $buffer.="<user id=\"shared\">";
$buffer.="<active_repo id=\"".ConfService::getCurrentRepositoryId()."\" write=\"1\" read=\"1\"/>"; $buffer.="<active_repo id=\"".$currentRepoId."\" write=\"1\" read=\"1\"/>";
$buffer.= XMLWriter::writeRepositoriesData(null); $buffer.= XMLWriter::writeRepositoriesData(null);
$buffer.="</user>"; $buffer.="</user>";
} else if ($loggedUser != null) { } else if ($loggedUser != null) {
$lock = $loggedUser->getLock(); $lock = $loggedUser->getLock();
$buffer.="<user id=\"".$loggedUser->id."\">"; $buffer.="<user id=\"".$loggedUser->id."\">";
$buffer.="<active_repo id=\"".ConfService::getCurrentRepositoryId()."\" write=\"".($loggedUser->canWrite(ConfService::getCurrentRepositoryId())?"1":"0")."\" read=\"".($loggedUser->canRead(ConfService::getCurrentRepositoryId())?"1":"0")."\"/>"; $buffer.="<active_repo id=\"".$currentRepoId."\" write=\"".($loggedUser->canWrite($currentRepoId)?"1":"0")."\" read=\"".($loggedUser->canRead($currentRepoId)?"1":"0")."\"/>";
$buffer.= XMLWriter::writeRepositoriesData($loggedUser); $buffer.= XMLWriter::writeRepositoriesData($loggedUser);
$buffer.="<preferences>"; $buffer.="<preferences>";
$preferences = $confDriver->getExposedPreferences($loggedUser); $preferences = $confDriver->getExposedPreferences($loggedUser);
Expand Down
8 changes: 3 additions & 5 deletions core/src/core/src/pydio/Core/Services/AuthService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
namespace Pydio\Core\Services; namespace Pydio\Core\Services;
use Pydio\Access\Core\Model\Repository; use Pydio\Access\Core\Model\Repository;
use Pydio\Auth\Core\AJXP_Safe; use Pydio\Auth\Core\AJXP_Safe;
use Pydio\Authfront\Core\AbstractAuthFrontend;
use Pydio\Conf\Core\AbstractAjxpUser; use Pydio\Conf\Core\AbstractAjxpUser;
use Pydio\Conf\Core\AJXP_Role; use Pydio\Conf\Core\AJXP_Role;
use Pydio\Conf\Core\AjxpGroupPathProvider; use Pydio\Conf\Core\AjxpGroupPathProvider;
use Pydio\Conf\Core\AjxpRole; use Pydio\Conf\Core\AjxpRole;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface; use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService; use Pydio\Core\Model\UserInterface;
use Pydio\Core\Controller\Controller; use Pydio\Core\Controller\Controller;
use Pydio\Core\Utils\CookiesHelper; use Pydio\Core\Utils\CookiesHelper;
use Pydio\Core\Utils\Utils; use Pydio\Core\Utils\Utils;
Expand Down Expand Up @@ -189,7 +187,7 @@ public static function ignoreUserCase()


/** /**
* @static * @static
* @param AbstractAjxpUser $user * @param UserInterface $user
*/ */
public static function refreshRememberCookie($user) public static function refreshRememberCookie($user)
{ {
Expand All @@ -199,7 +197,7 @@ public static function refreshRememberCookie($user)
} }
$rememberPass = CookiesHelper::getCookieString($user); $rememberPass = CookiesHelper::getCookieString($user);
if(self::$useSession) { if(self::$useSession) {
setcookie("AjaXplorer-remember", $user->id.":".$rememberPass, time()+3600*24*10, null, null, (isSet($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on"), true); setcookie("AjaXplorer-remember", $user->getId().":".$rememberPass, time()+3600*24*10, null, null, (isSet($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on"), true);
} }
} }


Expand Down
12 changes: 6 additions & 6 deletions core/src/core/src/pydio/Core/Services/ConfService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public static function getRepositoriesList($scope = "user", $includeShared = tru
if ($scope == "user") { if ($scope == "user") {
return self::getInstance()->getLoadedRepositories(); return self::getInstance()->getLoadedRepositories();
} else { } else {
return self::getInstance()->initRepositoriesListInst("all", $includeShared); return self::getInstance()->initRepositoriesListInst("all", null, $includeShared);
} }
} }


Expand Down Expand Up @@ -510,7 +510,7 @@ private function getLoadedRepositories()
unset($this->configs["REPOSITORIES"]); unset($this->configs["REPOSITORIES"]);
} }
} }
$this->configs["REPOSITORIES"] = $this->initRepositoriesListInst(); $this->configs["REPOSITORIES"] = $this->initRepositoriesListInst("user", AuthService::getLoggedUser());
$_SESSION["REPOSITORIES"] = $this->configs["REPOSITORIES"]; $_SESSION["REPOSITORIES"] = $this->configs["REPOSITORIES"];
return $this->configs["REPOSITORIES"]; return $this->configs["REPOSITORIES"];
} }
Expand Down Expand Up @@ -762,13 +762,13 @@ public static function listRepositoriesWithCriteria($criteria, &$count){


/** /**
* @param $scope String "user", "all" * @param $scope String "user", "all"
* @param UserInterface|null $loggedUser
* @param bool $includeShared * @param bool $includeShared
* @return array * @return array
*/ */
protected function initRepositoriesListInst($scope = "user", $includeShared = true) protected function initRepositoriesListInst($scope = "user", $loggedUser = null, $includeShared = true)
{ {
// APPEND CONF FILE REPOSITORIES // APPEND CONF FILE REPOSITORIES
$loggedUser = AuthService::getLoggedUser();
$objList = array(); $objList = array();
if($loggedUser != null){ if($loggedUser != null){
$l = $loggedUser->getLock(); $l = $loggedUser->getLock();
Expand All @@ -786,8 +786,8 @@ protected function initRepositoriesListInst($scope = "user", $includeShared = tr
$confDriver = self::getConfStorageImpl(); $confDriver = self::getConfStorageImpl();
if($scope == "user"){ if($scope == "user"){
$acls = array(); $acls = array();
if(AuthService::getLoggedUser() != null){ if($loggedUser != null){
$acls = AuthService::getLoggedUser()->mergedRole->listAcls(true); $acls = $loggedUser->getMergedRole()->listAcls(true);
} }
if(!count($acls)) { if(!count($acls)) {
$drvList = array(); $drvList = array();
Expand Down
14 changes: 8 additions & 6 deletions core/src/core/src/pydio/Core/Utils/Utils.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
use Pydio\Access\Core\Model\Repository; use Pydio\Access\Core\Model\Repository;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\AuthService; use Pydio\Core\Services\AuthService;
use Pydio\Core\Services\ConfService; use Pydio\Core\Services\ConfService;
use Pydio\Core\PluginFramework\Plugin; use Pydio\Core\PluginFramework\Plugin;
Expand Down Expand Up @@ -384,12 +385,13 @@ public static function parseFileDataErrors($boxData, $throwException=false)
* + skipIOS * + skipIOS
* + gui * + gui
* @static * @static
* @param ContextInterface $ctx
* @param $parameters * @param $parameters
* @param $output * @param $output
* @param $session * @param $session
* @return void * @return void
*/ */
public static function parseApplicationGetParameters($parameters, &$output, &$session) public static function parseApplicationGetParameters(ContextInterface $ctx, $parameters, &$output, &$session)
{ {
$output["EXT_REP"] = "/"; $output["EXT_REP"] = "/";


Expand All @@ -411,7 +413,7 @@ public static function parseApplicationGetParameters($parameters, &$output, &$se
$parameters["repository_id"] = $repository->getId(); $parameters["repository_id"] = $repository->getId();
} }
if (AuthService::usersEnabled()) { if (AuthService::usersEnabled()) {
$loggedUser = AuthService::getLoggedUser(); $loggedUser = $ctx->getUser();
if ($loggedUser != null && $loggedUser->canSwitchTo($parameters["repository_id"])) { if ($loggedUser != null && $loggedUser->canSwitchTo($parameters["repository_id"])) {
$output["FORCE_REGISTRY_RELOAD"] = true; $output["FORCE_REGISTRY_RELOAD"] = true;
$output["EXT_REP"] = TextEncoder::toUTF8(urldecode($parameters["folder"])); $output["EXT_REP"] = TextEncoder::toUTF8(urldecode($parameters["folder"]));
Expand Down Expand Up @@ -1731,10 +1733,10 @@ public static function filterFormElementsFromMeta($metadata, &$nestedData, $user
} }
} }


public static function parseStandardFormParameters(&$repDef, &$options, $userId = null, $prefix = "DRIVER_OPTION_", $binariesContext = null, $cypheredPassPrefix = "") public static function parseStandardFormParameters(ContextInterface $ctx, &$repDef, &$options, $prefix = "DRIVER_OPTION_", $binariesContext = null, $cypheredPassPrefix = "")
{ {
if ($binariesContext === null) { if ($binariesContext === null) {
$binariesContext = array("USER" => (AuthService::getLoggedUser()!= null)?AuthService::getLoggedUser()->getId():"shared"); $binariesContext = array("USER" => ($ctx->hasUser())?$ctx->getUser()->getId():"shared");
} }
$replicationGroups = array(); $replicationGroups = array();
$switchesGroups = array(); $switchesGroups = array();
Expand All @@ -1752,10 +1754,10 @@ public static function parseStandardFormParameters(&$repDef, &$options, $userId
$value = intval($value); $value = intval($value);
} else if ($type == "array") { } else if ($type == "array") {
$value = explode(",", $value); $value = explode(",", $value);
} else if ($type == "password" && $userId!=null) { } else if ($type == "password" && $ctx->hasUser()) {
if (trim($value) != "" && $value != "__AJXP_VALUE_SET__" && function_exists('mcrypt_encrypt')) { if (trim($value) != "" && $value != "__AJXP_VALUE_SET__" && function_exists('mcrypt_encrypt')) {
// We encode as base64 so if we need to store the result in a database, it can be stored in text column // We encode as base64 so if we need to store the result in a database, it can be stored in text column
$value = $cypheredPassPrefix . base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($userId."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB)); $value = $cypheredPassPrefix . base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($ctx->getUser()->getId()."\1CDAFx¨op#"), $value, MCRYPT_MODE_ECB));
} }
} else if ($type == "binary" && $binariesContext !== null) { } else if ($type == "binary" && $binariesContext !== null) {
if (!empty($value)) { if (!empty($value)) {
Expand Down
37 changes: 25 additions & 12 deletions core/src/plugins/access.ajxp_conf/class.ajxp_confAccessDriver.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Pydio\Access\Core\Filter\AJXP_PermissionMask; use Pydio\Access\Core\Filter\AJXP_PermissionMask;
use Pydio\Access\Core\Model\Repository; use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Core\Model\UserSelection; use Pydio\Access\Core\Model\UserSelection;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface; use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Model\UserInterface; use Pydio\Core\Model\UserInterface;
use Pydio\Core\Services\AuthService; use Pydio\Core\Services\AuthService;
Expand Down Expand Up @@ -871,7 +872,10 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
$data = json_decode($jsonData, true); $data = json_decode($jsonData, true);
$roleData = $data["ROLE"]; $roleData = $data["ROLE"];
$binariesContext = array(); $binariesContext = array();
$parseContext = $ctx;
if (isset($userObject)) { if (isset($userObject)) {
$parseContext = new Context(null, $ctx->getRepositoryId());
$parseContext->setUserObject($userObject);
$binariesContext = array("USER" => $userObject->getId()); $binariesContext = array("USER" => $userObject->getId());
} }
if(isSet($data["FORMS"])){ if(isSet($data["FORMS"])){
Expand All @@ -880,9 +884,9 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
foreach ($plugData as $plugId => $formsData) { foreach ($plugData as $plugId => $formsData) {
$parsed = array(); $parsed = array();
Utils::parseStandardFormParameters( Utils::parseStandardFormParameters(
$parseContext,
$formsData, $formsData,
$parsed, $parsed,
($userObject!=null?$usrId:null),
"ROLE_PARAM_", "ROLE_PARAM_",
$binariesContext, $binariesContext,
AJXP_Role::$cypheredPassPrefix AJXP_Role::$cypheredPassPrefix
Expand Down Expand Up @@ -1284,6 +1288,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
break; break;


case "save_custom_user_params" : case "save_custom_user_params" :

$userId = Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); $userId = Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS);
if ($userId == $loggedUser->getId()) { if ($userId == $loggedUser->getId()) {
$user = $loggedUser; $user = $loggedUser;
Expand All @@ -1299,7 +1304,8 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
if(!is_array($custom)) $custom = array(); if(!is_array($custom)) $custom = array();


$options = $custom; $options = $custom;
$this->parseParameters($httpVars, $options, $userId, false, $custom); $newCtx = new Context($userId, $ctx->getRepositoryId());
$this->parseParameters($newCtx, $httpVars, $options, false, $custom);
$custom = $options; $custom = $options;
$user->setPref("CUSTOM_PARAMS", $custom); $user->setPref("CUSTOM_PARAMS", $custom);
$user->save(); $user->save();
Expand Down Expand Up @@ -1333,7 +1339,8 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
} }
$options = $wallet[$repoID]; $options = $wallet[$repoID];
$existing = $options; $existing = $options;
$this->parseParameters($httpVars, $options, $userId, false, $existing); $newCtx = new Context($userId, $ctx->getRepositoryId());
$this->parseParameters($newCtx, $httpVars, $options, false, $existing);
$wallet[$repoID] = $options; $wallet[$repoID] = $options;
$user->setPref("AJXP_WALLET", $wallet); $user->setPref("AJXP_WALLET", $wallet);
$user->save(); $user->save();
Expand Down Expand Up @@ -1448,7 +1455,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
$options = $repDef["DRIVER_OPTIONS"]; $options = $repDef["DRIVER_OPTIONS"];
} else { } else {
$options = array(); $options = array();
$this->parseParameters($repDef, $options, null, true); $this->parseParameters($ctx, $repDef, $options, true);
} }
if (count($options)) { if (count($options)) {
$repDef["DRIVER_OPTIONS"] = $options; $repDef["DRIVER_OPTIONS"] = $options;
Expand Down Expand Up @@ -1717,7 +1724,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
if(!$repo->isTemplate){ if(!$repo->isTemplate){
foreach($existing as $exK) $existingValues[$exK] = $repo->getOption($exK, true); foreach($existing as $exK) $existingValues[$exK] = $repo->getOption($exK, true);
} }
$this->parseParameters($httpVars, $options, null, true, $existingValues); $this->parseParameters($ctx, $httpVars, $options, true, $existingValues);
if (count($options)) { if (count($options)) {
foreach ($options as $key=>$value) { foreach ($options as $key=>$value) {
if ($key == "AJXP_SLUG") { if ($key == "AJXP_SLUG") {
Expand Down Expand Up @@ -1822,7 +1829,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
$options = json_decode(TextEncoder::magicDequote($httpVars["json_data"]), true); $options = json_decode(TextEncoder::magicDequote($httpVars["json_data"]), true);
} else { } else {
$options = array(); $options = array();
$this->parseParameters($httpVars, $options, null, true); $this->parseParameters($ctx, $httpVars, $options, true);
} }
$repoOptions = $repo->getOption("META_SOURCES"); $repoOptions = $repo->getOption("META_SOURCES");
if (is_array($repoOptions) && isSet($repoOptions[$metaSourceType])) { if (is_array($repoOptions) && isSet($repoOptions[$metaSourceType])) {
Expand Down Expand Up @@ -1879,7 +1886,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
$options = json_decode(TextEncoder::magicDequote($httpVars["json_data"]), true); $options = json_decode(TextEncoder::magicDequote($httpVars["json_data"]), true);
} else { } else {
$options = array(); $options = array();
$this->parseParameters($httpVars, $options, null, true); $this->parseParameters($ctx, $httpVars, $options, true);
} }
if(isset($repoOptions[$metaSourceId])){ if(isset($repoOptions[$metaSourceId])){
$this->mergeExistingParameters($options, $repoOptions[$metaSourceId]); $this->mergeExistingParameters($options, $repoOptions[$metaSourceId]);
Expand Down Expand Up @@ -2094,7 +2101,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
case "run_plugin_action": case "run_plugin_action":


$options = array(); $options = array();
$this->parseParameters($httpVars, $options, null, true); $this->parseParameters($ctx, $httpVars, $options, true);
$pluginId = $httpVars["action_plugin_id"]; $pluginId = $httpVars["action_plugin_id"];
if (isSet($httpVars["button_key"])) { if (isSet($httpVars["button_key"])) {
$options = $options[$httpVars["button_key"]]; $options = $options[$httpVars["button_key"]];
Expand All @@ -2117,7 +2124,7 @@ public function switchAction($action, $httpVars, $fileVars, ContextInterface $ct
case "edit_plugin_options": case "edit_plugin_options":


$options = array(); $options = array();
$this->parseParameters($httpVars, $options, null, true); $this->parseParameters($ctx, $httpVars, $options, true);
$confStorage = ConfService::getConfStorageImpl(); $confStorage = ConfService::getConfStorageImpl();
$pluginId = Utils::sanitize($httpVars["plugin_id"], AJXP_SANITIZE_ALPHANUM); $pluginId = Utils::sanitize($httpVars["plugin_id"], AJXP_SANITIZE_ALPHANUM);
list($pType, $pName) = explode(".", $pluginId); list($pType, $pName) = explode(".", $pluginId);
Expand Down Expand Up @@ -2911,10 +2918,16 @@ public function updateUserRole(UserInterface $ctxUser, $userId, $roleId, $addOrR


} }



/**
protected function parseParameters(&$repDef, &$options, $userId = null, $globalBinaries = false, $existingValues = array()) * @param ContextInterface $ctx
* @param $repDef
* @param $options
* @param bool $globalBinaries
* @param array $existingValues
*/
protected function parseParameters(ContextInterface $ctx, &$repDef, &$options, $globalBinaries = false, $existingValues = array())
{ {
Utils::parseStandardFormParameters($repDef, $options, $userId, "DRIVER_OPTION_", ($globalBinaries?array():null)); Utils::parseStandardFormParameters($ctx, $repDef, $options, "DRIVER_OPTION_", ($globalBinaries?array():null));
if(!count($existingValues)){ if(!count($existingValues)){
return; return;
} }
Expand Down
23 changes: 12 additions & 11 deletions core/src/plugins/access.dropbox/class.dropboxAccessDriver.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function initRepository(ContextInterface $contextInterface)
if(!empty($_SESSION["OAUTH_DROPBOX_TOKENS"])) return; if(!empty($_SESSION["OAUTH_DROPBOX_TOKENS"])) return;


// TOKENS IN FILE ? // TOKENS IN FILE ?
$tokens = $this->getTokens(); $tokens = $this->getTokens($contextInterface);
if (!empty($tokens)) { if (!empty($tokens)) {
$_SESSION["OAUTH_DROPBOX_TOKENS"] = $tokens; $_SESSION["OAUTH_DROPBOX_TOKENS"] = $tokens;
return; return;
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function initRepository(ContextInterface $contextInterface)
} }
$_SESSION['DROPBOX_NEGOCIATION_STATE'] = 3; $_SESSION['DROPBOX_NEGOCIATION_STATE'] = 3;
$_SESSION['OAUTH_DROPBOX_TOKENS'] = $tokens; $_SESSION['OAUTH_DROPBOX_TOKENS'] = $tokens;
$this->setTokens($tokens); $this->setTokens($contextInterface, $tokens);
return; return;
} }


Expand All @@ -128,14 +128,15 @@ public function isWriteable($dir, $type = "dir")
return true; return true;
} }


public function getTokens() public function getTokens(ContextInterface $ctx)
{ {
if($this->repository->getOption("DROPBOX_OAUTH_TOKENS") !== null && is_array($this->repository->getOption("DROPBOX_OAUTH_TOKENS"))){ $repo = $ctx->getRepository();
return $this->repository->getOption("DROPBOX_OAUTH_TOKENS"); if($repo->getOption("DROPBOX_OAUTH_TOKENS") !== null && is_array($repo->getOption("DROPBOX_OAUTH_TOKENS"))){
return $repo->getOption("DROPBOX_OAUTH_TOKENS");
} }
$repositoryId = $this->repository->getId(); $repositoryId = $repo->getId();
if(AuthService::usersEnabled()) { if(AuthService::usersEnabled()) {
$u = AuthService::getLoggedUser(); $u = $ctx->getUser();
$userId = $u->getId(); $userId = $u->getId();
if($u->getResolveAsParent()){ if($u->getResolveAsParent()){
$userId = $u->getParent(); $userId = $u->getParent();
Expand All @@ -146,18 +147,18 @@ public function getTokens()
return Utils::loadSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens"); return Utils::loadSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens");
} }


public function setTokens($oauth_tokens) public function setTokens(ContextInterface $ctx, $oauth_tokens)
{ {
$repositoryId = $this->repository->getId(); $repositoryId = $ctx->getUser()->getId();
if(AuthService::usersEnabled()) $userId = AuthService::getLoggedUser()->getId(); if(AuthService::usersEnabled()) $userId = $ctx->getUser()->getId();
else $userId = "shared"; else $userId = "shared";
Utils::saveSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens", $oauth_tokens, true); Utils::saveSerialFile(AJXP_DATA_PATH."/plugins/access.dropbox/".$repositoryId."_".$userId."_tokens", $oauth_tokens, true);
} }


public function makeSharedRepositoryOptions(ContextInterface $ctx, $httpVars) public function makeSharedRepositoryOptions(ContextInterface $ctx, $httpVars)
{ {
$newOptions = parent::makeSharedRepositoryOptions($ctx, $httpVars); $newOptions = parent::makeSharedRepositoryOptions($ctx, $httpVars);
$newOptions["DROPBOX_OAUTH_TOKENS"] = $this->getTokens(); $newOptions["DROPBOX_OAUTH_TOKENS"] = $this->getTokens($ctx);
return $newOptions; return $newOptions;
} }


Expand Down
Loading

0 comments on commit 2cf2a73

Please sign in to comment.