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

Commit b5f0b32

Browse files
committed
ShareCenter:
Fix authorization checking for various share types. Make sure to register the REQUIRES_INDEXATION flag on syncable shared workspaces to trigger indexation at first changes API call (should fix #913)
1 parent 99a718a commit b5f0b32

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

core/src/plugins/action.share/class.ShareCenter.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ protected function parseSpecificContributions(&$contribNode)
8080
// All share- actions
8181
$xpathesToRemove[] = 'action[contains(@name, "share-")]';
8282
}else{
83-
$folderSharingMode = $this->pluginConf["ENABLE_FOLDER_SHARING"];
84-
$fileSharingAllowed = $this->pluginConf["ENABLE_FILE_PUBLIC_LINK"];
83+
$folderSharingAllowed = $this->getAuthorization("folder", "any"); // $this->pluginConf["ENABLE_FOLDER_SHARING"];
84+
$fileSharingAllowed = $this->getAuthorization("file"); //$this->pluginConf["ENABLE_FILE_PUBLIC_LINK"];
8585
if($fileSharingAllowed === false){
8686
// Share file button
8787
$xpathesToRemove[] = 'action[@name="share-file-minisite"]';
8888
}
89-
if($folderSharingMode == 'disable'){
89+
if(!$folderSharingAllowed){
9090
// Share folder button
9191
$xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]';
9292
}
@@ -116,6 +116,21 @@ public function init($options)
116116
}
117117
}
118118

119+
protected function getAuthorization($nodeType, $shareType = "any"){
120+
if($nodeType == "file"){
121+
return $this->getFilteredOption("ENABLE_FILE_PUBLIC_LINK") !== false;
122+
}else{
123+
$opt = $this->getFilteredOption("ENABLE_FOLDER_SHARING");
124+
if($shareType == "minisite"){
125+
return ($opt == "minisite" || $opt == "both");
126+
}else if($shareType == "workspace"){
127+
return ($opt == "workspace" || $opt == "both");
128+
}else{
129+
return ($opt !== "disabled");
130+
}
131+
}
132+
}
133+
119134
/**
120135
* @return ShareCenter
121136
*/
@@ -219,6 +234,11 @@ public function switchAction($action, $httpVars, $fileVars)
219234

220235
if ($subAction == "delegate_repo") {
221236
header("Content-type:text/plain");
237+
$auth = $this->getAuthorization("folder", "workspace");
238+
if(!$auth){
239+
print 103;
240+
break;
241+
}
222242
$result = $this->createSharedRepository($httpVars, $this->repository, $this->accessDriver);
223243
if (is_a($result, "Repository")) {
224244
$newMeta = array("id" => $result->getUniqueId(), "type" => "repository");
@@ -1601,8 +1621,18 @@ public function createSharedMinisite($httpVars, $repository, $accessDriver)
16011621
}else{
16021622
$setFilter = true;
16031623
}
1624+
$nodes = $userSelection->buildNodes($this->accessDriver);
1625+
$hasDir = false; $hasFile = false;
1626+
foreach($nodes as $n){
1627+
$n->loadNodeInfo();
1628+
if($n->isLeaf()) $hasFile = true;
1629+
else $hasDir = true;
1630+
}
1631+
if( ( $hasDir && !$this->getAuthorization("folder", "minisite") ) || ($hasFile && !$this->getAuthorization("file"))){
1632+
return 103;
1633+
}
16041634
if($setFilter){
1605-
$httpVars["filter_nodes"] = $userSelection->buildNodes($this->accessDriver);
1635+
$httpVars["filter_nodes"] = $nodes;
16061636
}
16071637
if(!isSet($httpVars["repo_label"])){
16081638
$first = $userSelection->getUniqueNode($this->accessDriver);
@@ -1739,10 +1769,15 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
17391769
if (!isSet($httpVars["repo_label"]) || $httpVars["repo_label"] == "") {
17401770
return 100;
17411771
}
1772+
/*
1773+
// FILE IS ALWAYS THE PARENT FOLDER SO WE NOW CHECK FOLDER_SHARING AT A HIGHER LEVEL
1774+
$file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
17421775
$foldersharing = $this->getFilteredOption("ENABLE_FOLDER_SHARING", $this->repository->getId());
1743-
if (isset($foldersharing) && ($foldersharing === false || (is_string($foldersharing) && $foldersharing == "disable"))) {
1776+
$foldersharingDisabled = isset($foldersharing) && ($foldersharing === false || (is_string($foldersharing) && $foldersharing == "disable"));
1777+
if (is_dir($this->urlBase.$file) && $foldersharingDisabled) {
17441778
return 103;
17451779
}
1780+
*/
17461781
$loggedUser = AuthService::getLoggedUser();
17471782
$actRights = $loggedUser->mergedRole->listActionsStatesFor($repository);
17481783
if (isSet($actRights["share"]) && $actRights["share"] === false) {
@@ -1883,7 +1918,7 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
18831918
if (isSet($data["USE_SESSION_CREDENTIALS"]) && $data["USE_SESSION_CREDENTIALS"] === true) {
18841919
$options["META_SOURCES"][$index]["ENCODED_CREDENTIALS"] = AJXP_Safe::getEncodedCredentialString();
18851920
}
1886-
if($index == "meta.syncable" && $data["REPO_SYNCABLE"] === true ){
1921+
if($index == "meta.syncable" && (!isSet($data["REPO_SYNCABLE"]) || $data["REPO_SYNCABLE"] === true )){
18871922
$data["REQUIRES_INDEXATION"] = true;
18881923
}
18891924
}

0 commit comments

Comments
 (0)