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

Commit

Permalink
Embed CURRENT_MINISITE session key in ApplicationState, save / load i…
Browse files Browse the repository at this point in the history
…n middlewares.

Update DL links for public links
  • Loading branch information
cdujeu committed Sep 22, 2016
1 parent fef670f commit 345dac8
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 31 deletions.
Expand Up @@ -23,6 +23,7 @@
use Pydio\Core\Http\Server;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\SessionService;
use Pydio\Core\Utils\ApplicationState;

defined('AJXP_EXEC') or die('Access not allowed');

Expand Down Expand Up @@ -75,6 +76,10 @@ public static function handleRequest(\Psr\Http\Message\ServerRequestInterface $r
SessionService::close();
});

if(SessionService::has(SessionService::CTX_MINISITE_HASH)){
ApplicationState::setStateMinisite(SessionService::fetch(SessionService::CTX_MINISITE_HASH));
}

return Server::callNextMiddleWare($requestInterface, $responseInterface, $next);

}
Expand Down
5 changes: 2 additions & 3 deletions core/src/core/src/pydio/Core/Serializer/RepositoryXML.php
Expand Up @@ -26,6 +26,7 @@
use Pydio\Core\Model\UserInterface;
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Vars\StringHelper;

defined('AJXP_EXEC') or die('Access not allowed');
Expand Down Expand Up @@ -132,9 +133,7 @@ protected function repositoryToXML($repoObject, $isActive, $exposed, $streams, $
}

$descTag = "";
$public = false;
if(!empty($_SESSION["CURRENT_MINISITE"])) $public = true;
$description = $repoObject->getDescription($public, $ownerLabel);
$description = $repoObject->getDescription(ApplicationState::hasMinisiteHash(), $ownerLabel);
if (!empty($description)) {
$descTag = '<description>'. StringHelper::xmlEntities($description, true) .'</description>';
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/core/src/pydio/Core/Serializer/UserXML.php
Expand Up @@ -24,6 +24,7 @@
use Pydio\Core\PluginFramework\PluginsService;
use Pydio\Core\Services\ConfService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\ApplicationState;

defined('AJXP_EXEC') or die('Access not allowed');

Expand Down Expand Up @@ -126,7 +127,7 @@ protected function writeRepositoriesData(ContextInterface $ctx)
}

foreach ($accessible as $repoId => $repoObject) {
if(!isSet($_SESSION["CURRENT_MINISITE"]) && $repoObject->hasContentFilter()){
if(!ApplicationState::hasMinisiteHash() && $repoObject->hasContentFilter()){
continue;
}
$accessStatus = '';
Expand Down
1 change: 1 addition & 0 deletions core/src/core/src/pydio/Core/Services/SessionService.php
Expand Up @@ -41,6 +41,7 @@ class SessionService implements RepositoriesCache
const LANGUAGES_KEY = "PYDIO_LANGUAGES";
const CTX_LANGUAGE_KEY = "PYDIO_CTX_LANGUAGE";
const CTX_CHARSET_KEY = "PYDIO_CTX_CHARSET";
const CTX_MINISITE_HASH = "PYDIO_CTX_MINISITE";

private static $sessionName = PYDIO_SESSION_NAME;

Expand Down
26 changes: 26 additions & 0 deletions core/src/core/src/pydio/Core/Utils/ApplicationState.php
Expand Up @@ -42,6 +42,11 @@ class ApplicationState
*/
private static $sapiType = "session";

/**
* @var string
*/
private static $minisiteHash = null;

/**
* @param string $restBase
*/
Expand Down Expand Up @@ -75,6 +80,27 @@ public static function sapiUsesSession(){
return !self::sapiIsCli() && self::$restBase === null;
}

/**
* @param $hash
*/
public static function setStateMinisite($hash){
self::$minisiteHash = $hash;
}

/**
* @return bool
*/
public static function hasMinisiteHash(){
return self::$minisiteHash !== null;
}

/**
* @return string
*/
public static function getMinisiteHash(){
return self::$minisiteHash;
}

/**
* Check if data/cache/first_run_passed file exists or not
* @return bool
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/action.powerfs/PowerFSController.php
Expand Up @@ -50,7 +50,7 @@ class PowerFSController extends Plugin

public function performChecks()
{
if (class_exists("\\Pydio\\Share\\ShareCenter") && \Pydio\Share\ShareCenter::currentContextIsLinkDownload()) {
if(ApplicationState::hasMinisiteHash() && ApplicationState::getSapiRestBase() !== null){
throw new Exception("Disable during link download");
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -227,11 +227,11 @@
if(staticClass.getRESTPreviewLinks){
var links = staticClass.getRESTPreviewLinks(node);
$H(links).each(function(pair){
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "?dl=true&ct=true"+pair.value}));
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:pair.key,link:document.location.href.split('?').shift() + "/dl"+node.getPath()+"?ct=true"+pair.value}));
});
}
}
var dlLink = document.location.href.split('?').shift() + "?dl=true&file=" + encodeURIComponent(node.getPath());
var dlLink = document.location.href.split('?').shift() + "/dl" + node.getPath();
modal.getForm().down("#additional_links").insert(tpl.evaluate({title:MessageHash['share_center.60'],link:dlLink}));
}
]]></dialogOnOpen>
Expand All @@ -253,7 +253,7 @@
</action>
<action name="download">
<pre_processing>
<serverCallback methodName="preProcessDownload" applyCondition="$apply=isSet($_SESSION['CURRENT_MINISITE']);"/>
<serverCallback methodName="preProcessDownload" applyCondition="$apply=\Pydio\Core\Services\SessionService::has(\Pydio\Core\Services\SessionService::CTX_MINISITE_HASH);"/>
</pre_processing>
</action>
</actions>
Expand Down
Expand Up @@ -92,7 +92,8 @@ public static function handleRequest(ServerRequestInterface $requestInterface, R
}

if($sessions){
$_SESSION["CURRENT_MINISITE"] = $hash;
SessionService::save(SessionService::CTX_MINISITE_HASH, $hash);
ApplicationState::setStateMinisite($hash);
}
if(!empty($ctx) && $ctx->hasUser() && isSet($shareData["REPOSITORY"])){
$repoObject = UsersService::getRepositoryWithPermission($ctx->getUser(), $shareData["REPOSITORY"]);
Expand Down
24 changes: 13 additions & 11 deletions core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -533,17 +533,19 @@ protected function toggleWatchOnSharedRepository($childRepoId, $userId, $toggle
*/
public function preProcessDownload(ServerRequestInterface &$requestInterface, ResponseInterface &$responseInterface){

if(isSet($_SESSION["CURRENT_MINISITE"])){
$hash = $_SESSION["CURRENT_MINISITE"];
$share = $this->getShareStore()->loadShareObject($hash);
if(!empty($share)){
if($share->isExpired()){
throw new \Exception('Link is expired');
}
if($share->hasDownloadLimit()){
$share->incrementDownloadCount();
$share->save();
}
if(!ApplicationState::hasMinisiteHash()) {
return;
}

$hash = ApplicationState::getMinisiteHash();
$share = $this->getShareStore()->loadShareObject($hash);
if(!empty($share)){
if($share->isExpired()){
throw new \Exception('Link is expired');
}
if($share->hasDownloadLimit()){
$share->incrementDownloadCount();
$share->save();
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/authfront.cas/CasAuthFrontend.php
Expand Up @@ -32,6 +32,7 @@
use Pydio\Core\Services\RolesService;
use Pydio\Core\Services\SessionService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\DBHelper;
use Pydio\Log\Core\Logger;

Expand Down Expand Up @@ -82,7 +83,7 @@ function tryToLogUser(ServerRequestInterface &$request, ResponseInterface &$resp
{
$httpVars = $request->getParsedBody();

if (isset($_SESSION["CURRENT_MINISITE"])) {
if (ApplicationState::hasMinisiteHash()) {
return false;
}

Expand Down
Expand Up @@ -81,7 +81,7 @@ protected function logUserFromSession(\Psr\Http\Message\ServerRequestInterface &

}

if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !isSet($_SESSION["CURRENT_MINISITE"])) {
if (ConfService::getGlobalConf("ALLOW_GUEST_BROWSING", "auth") && !ApplicationState::hasMinisiteHash()) {

$authDriver = ConfService::getAuthDriverImpl();
if (!$authDriver->userExists("guest")) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/core.notifications/Notification.php
Expand Up @@ -165,8 +165,8 @@ protected function replaceVars($tplString, $mess, $rich = true)
*/
public function getMainLink()
{
if(isSet($_SESSION["CURRENT_MINISITE"]) && class_exists("\\Pydio\\Share\\ShareCenter")){
$hash = $_SESSION["CURRENT_MINISITE"];
if(ApplicationState::hasMinisiteHash() && class_exists("\\Pydio\\Share\\ShareCenter")){
$hash = ApplicationState::getMinisiteHash();
$shareCenter = \Pydio\Share\ShareCenter::getShareCenter($this->getContext());
if(!empty($shareCenter)){
return $shareCenter->getPublicAccessManager()->buildPublicLink($hash);
Expand Down Expand Up @@ -251,7 +251,7 @@ private function computeLocationType(){
$crtUserId = "shared";
$crtUser = $this->getNode()->hasUser() ? $this->getNode()->getUser() : null;
if($crtUser != null) $crtUserId = $crtUser->getId();
if(isSet($_SESSION["CURRENT_MINISITE"])){
if(ApplicationState::hasMinisiteHash()){
if($repo->hasContentFilter()){
$type = "minisite.file";
}else{
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/editor.diaporama/class.Diaporama.js
Expand Up @@ -719,8 +719,8 @@ Class.create("Diaporama", AbstractEditor, {

getRESTPreviewLinks:function(node){
return {
"Original image": "&file=" + encodeURIComponent(node.getPath()),
"Thumbnail (200px)": "&get_thumb=true&dimension=200&file=" + encodeURIComponent(node.getPath())
"Original image": "",
"Thumbnail (200px)": "&get_thumb=true&dimension=200"
};
},

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.imagick/class.IMagickPreviewer.js
Expand Up @@ -172,7 +172,7 @@ Class.create("IMagickPreviewer", Diaporama, {

getRESTPreviewLinks:function(node){
return {
"First Page Thumbnail": "&file=" + encodeURIComponent(node.getPath())
"First Page Thumbnail": ""
};
},

Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.soundmanager/class.SMPlayer.js
Expand Up @@ -243,7 +243,7 @@ soundManager.setup({\n\
},

getRESTPreviewLinks:function(node){
return {"MP3 Stream": "&file=" + encodeURIComponent(node.getPath())};
return {"MP3 Stream": ""};
},

getPreview : function(ajxpNode, rich){
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/editor.video/class.VideoPreviewer.js
Expand Up @@ -92,7 +92,7 @@ preload="auto" width="#{WIDTH}" height="#{HEIGHT}" data-setup="{}">\n\
},

getRESTPreviewLinks:function(node){
return {"Video Stream": "&file=" + encodeURIComponent(node.getPath())};
return {"Video Stream": ""};
},


Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/gui.ios/MobileNativeRedirect.php
Expand Up @@ -22,6 +22,7 @@
namespace Pydio\Gui;

use Exception;
use Pydio\Core\Utils\ApplicationState;
use Pydio\Core\Utils\Http\UserAgent;

use Pydio\Core\PluginFramework\Plugin;
Expand All @@ -37,7 +38,9 @@ class MobileNativeRedirect extends Plugin
{
public function performChecks()
{
if (isSet($_SESSION["CURRENT_MINISITE"])) throw new Exception("Disabled for minisites");
if (ApplicationState::hasMinisiteHash()) {
throw new Exception("Disabled for minisites");
}
if (UserAgent::userAgentIsWindowsPhone()) {
throw new Exception("No native app for windows phone");
}
Expand Down

0 comments on commit 345dac8

Please sign in to comment.