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

Commit

Permalink
Sharing: fix dialog reload after parameters changes (add a callback t…
Browse files Browse the repository at this point in the history
…o the standard nodeReload operation).

Add parameters for enabling/disabling various types of sharing
New feature: Ability to manually set the hash
  • Loading branch information
cdujeu committed Sep 1, 2014
1 parent fcaccf2 commit 8b268b6
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 43 deletions.
82 changes: 62 additions & 20 deletions core/src/plugins/action.share/class.ShareCenter.js
Expand Up @@ -118,7 +118,6 @@ Class.create("ShareCenter", {
return false;
}
oForm.addClassName("share_edit");
modal.refreshDialogPosition();
var userSelection = ajaxplorer.getUserSelection();
var publicUrl = ajxpServerAccessPath+'&get_action=share';
publicUrl = userSelection.updateFormOrUrl(null, publicUrl);
Expand Down Expand Up @@ -178,15 +177,18 @@ Class.create("ShareCenter", {
}else{
ajaxplorer.displayMessage('SUCCESS', MessageHash['share_center.18']);
}
ajaxplorer.fireNodeRefresh(this.currentNode);
this.currentNode.getMetadata().set("ajxp_shared", "true");
this.shareRepository(true);
ajaxplorer.fireNodeRefresh(this.currentNode, function(newNode){
this.currentNode = newNode;
this.shareRepository(true);
modal.refreshDialogPosition();
}.bind(this));
}else{
var messages = {100:349, 101:352, 102:350, 103:351};
ajaxplorer.displayMessage('ERROR', MessageHash[messages[response]]);
if(response == 101){
oForm.down("#repo_label").focus();
}
modal.refreshDialogPosition();
}
}.bind(this);
}else{
Expand All @@ -209,9 +211,15 @@ Class.create("ShareCenter", {
if(response == 101){
oForm.down("#repo_label").focus();
}
modal.refreshDialogPosition();
}else{
this.currentNode.getMetadata().set("ajxp_shared", "true");
ajaxplorer.fireNodeRefresh(this.currentNode);
ajaxplorer.fireNodeRefresh(this.currentNode, function(newNode){
this.currentNode = newNode;
this.shareRepository(true);
modal.refreshDialogPosition();
}.bind(this));
/*
ajaxplorer.displayMessage('SUCCESS', MessageHash["share_center.156"].replace("%s", response));
oForm.down("#share_container").setValue(response);
this._currentRepositoryLink = response;
Expand All @@ -226,6 +234,7 @@ Class.create("ShareCenter", {
oForm.select('span.simple_tooltip_observer').each(function(e){
modal.simpleTooltip(e, e.readAttribute('data-tooltipTitle'), 'top center', 'down_arrow_tip', 'element');
});
*/
}

}.bind(this);
Expand Down Expand Up @@ -253,15 +262,37 @@ Class.create("ShareCenter", {

oForm.removeClassName('share_leaf');
oForm.removeClassName('type-ws');
var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
if(this.currentNode.isLeaf()) oForm.addClassName('share_leaf');
this.maxexpiration = parseInt(ajaxplorer.getPluginConfigs("action.share").get("FILE_MAX_EXPIRATION"));
this.maxexpiration = parseInt(pluginConfigs.get("FILE_MAX_EXPIRATION"));
if(this.maxexpiration > 0){
oForm.down("[name='expiration']").setValue(this.maxexpiration);
}
this.maxdownload = parseInt(ajaxplorer.getPluginConfigs("action.share").get("FILE_MAX_DOWNLOAD"));
this.maxdownload = parseInt(pluginConfigs.get("FILE_MAX_DOWNLOAD"));
if(this.maxdownload > 0){
oForm.down("[name='downloadlimit']").setValue(this.maxdownload);
}
this.authorizations = {
folder_public_link : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'minisite' ,
folder_workspaces : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'workspace' ,
file_public_link : pluginConfigs.get("ENABLE_FILE_PUBLIC_LINK"),
editable_hash : pluginConfigs.get("HASH_USER_EDITABLE")
};

if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link && !this.authorizations.folder_workspaces){
alert('You are not authorized to share folders');
hideLightBox();
return;
}else if(this.currentNode.isLeaf() && !this.authorizations.file_public_link){
alert('You are not authorized to share files');
hideLightBox();
return;
}else if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link){
this.shareFolderMode = "workspaces";
}else if(!this.currentNode.isLeaf() && !this.authorizations.folder_workspaces){
this.shareFolderMode = "minisite_public";
}

if(this.shareFolderMode == "minisite_public"){

oForm.select(".mode-ws").invoke('hide');
Expand Down Expand Up @@ -291,17 +322,22 @@ Class.create("ShareCenter", {
oForm.down('label[for="simple_right_write"]').hide();
}

oForm.down('#share-folder-type-chooser').select("input").each(function(i){
if(i.id == 'share-type-minisite' && this.shareFolderMode == 'minisite_public'){
i.checked = true;
}else if(i.id == 'share-type-workspace' && this.shareFolderMode == 'workspace'){
i.checked = true;
}
i.observe("click", function(){
if(i.id == 'share-type-minisite') this.performShare('minisite-public');
else if(i.id == 'share-type-workspace') this.performShare('workspace');
if(!this.authorizations.folder_public_link || !this.authorizations.folder_workspaces){
oForm.down("#share-folder-type-chooser").hide();
}else{
oForm.down('#share-folder-type-chooser').select("input").each(function(i){
if(i.id == 'share-type-minisite' && this.shareFolderMode == 'minisite_public'){
i.checked = true;
}else if(i.id == 'share-type-workspace' && this.shareFolderMode == 'workspace'){
i.checked = true;
}
i.observe("click", function(){
if(i.id == 'share-type-minisite') this.performShare('minisite-public');
else if(i.id == 'share-type-workspace') this.performShare('workspace');
}.bind(this));
}.bind(this));
}.bind(this));
}


var nodeMeta = this.currentNode.getMetadata();
oForm.removeClassName("share_edit");
Expand All @@ -311,6 +347,10 @@ Class.create("ShareCenter", {
modal.refreshDialogPosition();
});

if(!this.authorizations.editable_hash || !nodeMeta.get("ajxp_shared")){
oForm.down('#editable_hash_container').hide();
}

this.createQRCode = ajaxplorer.getPluginConfigs("action.share").get("CREATE_QRCODE");
var disableAutocompleter = (nodeMeta.get("ajxp_shared") && ( this.shareFolderMode != "workspace" || this.readonlyMode ));
var updateUserEntryAfterCreate = function(li, assignedRights, watchValue){
Expand Down Expand Up @@ -404,9 +444,11 @@ Class.create("ShareCenter", {
oForm.down('#simple_right_read').checked = (json.entries[0].RIGHT.indexOf('r') !== -1);
oForm.down('#simple_right_write').checked = (json.entries[0].RIGHT.indexOf('w') !== -1);
}
//oForm.down('#simple_right_download').disable();
//oForm.down('#simple_right_read').disable();
//oForm.down('#simple_right_write').disable();
if(this.authorizations.editable_hash && this._currentMinisiteHash){
oForm.down('#editable_hash_container').show();
oForm.down('#editable_hash_link').update(this._currentRepositoryLink.replace(this._currentMinisiteHash, oForm.down('#editable_hash_link').innerHTML));
oForm.down('#editable_hash_link').down('input').setValue(this._currentMinisiteHash);
}
}
$A(json['entries']).each(function(u){
var newItem = $('share_folder_form').autocompleter.createUserEntry(u.TYPE=="group", u.TYPE =="tmp_user", u.ID, u.LABEL);
Expand Down
54 changes: 43 additions & 11 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -79,11 +79,26 @@ protected function parseSpecificContributions(&$contribNode)
&& !(isset($_GET["get_action"]) && $_GET["get_action"]=="list_all_plugins_actions")){
$disableSharing = true;
}
$xpathesToRemove = array();
if ($disableSharing) {
unset($this->actions["share"]);
// All share- actions
$xpathesToRemove[] = 'action[contains(@name, "share-")]';
}else{
$folderSharingMode = $this->pluginConf["ENABLE_FOLDER_SHARING"];
$fileSharingAllowed = $this->pluginConf["ENABLE_FILE_PUBLIC_LINK"];
if($fileSharingAllowed === false){
// Share file button
$xpathesToRemove[] = 'action[@name="share-file-minisite"]';
}
if($folderSharingMode == 'disable'){
// Share folder button
$xpathesToRemove[] = 'action[@name="share-folder-minisite-public"]';
}
}
foreach($xpathesToRemove as $xpath){
$actionXpath=new DOMXPath($contribNode->ownerDocument);
$publicUrlNodeList = $actionXpath->query('action[contains(@name, "share-")]', $contribNode);
foreach($publicUrlNodeList as $shareActionNode){
$nodeList = $actionXpath->query($xpath, $contribNode);
foreach($nodeList as $shareActionNode){
$contribNode->removeChild($shareActionNode);
}
}
Expand Down Expand Up @@ -196,6 +211,8 @@ public function switchAction($action, $httpVars, $fileVars)
} else {
$httpVars["expiration"] = min($expiration,$maxexpiration);
}
$httpHash = null;
$originalHash = null;

if ($subAction == "delegate_repo") {
header("Content-type:text/plain");
Expand All @@ -209,12 +226,16 @@ public function switchAction($action, $httpVars, $fileVars)
print($numResult);
} else if ($subAction == "create_minisite") {
header("Content-type:text/plain");
if(isSet($httpVars["hash"]) && !empty($httpVars["hash"])) $httpHash = $httpVars["hash"];
$res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
if (!is_array($res)) {
$url = $res;
} else {
list($hash, $url) = $res;
$newMeta = array("id" => $hash, "type" => "minisite");
if($httpHash != null && $hash != $httpHash){
$originalHash = $httpHash;
}
}
print($url);
} else {
Expand All @@ -240,7 +261,7 @@ public function switchAction($action, $httpVars, $fileVars)
flush();
}
if ($newMeta != null && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
$this->addShareInMeta($ajxpNode, $newMeta["type"], $newMeta["id"]);
$this->addShareInMeta($ajxpNode, $newMeta["type"], $newMeta["id"], $originalHash);
}
AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
// as the result can be quite small (e.g error code), make sure it's output in case of OB active.
Expand Down Expand Up @@ -869,7 +890,7 @@ public function buildPublicletLink($hash)
{
$addLang = ConfService::getLanguage() != ConfService::getCoreConf("DEFAULT_LANGUAGE");
if ($this->getFilteredOption("USE_REWRITE_RULE", $this->repository->getId()) == true) {
if($addLang) return $this->buildPublicDlURL()."/".$hash."-".ConfService::getLanguage();
if($addLang) return $this->buildPublicDlURL()."/".$hash."--".ConfService::getLanguage();
else return $this->buildPublicDlURL()."/".$hash;
} else {
if($addLang) return $this->buildPublicDlURL()."/".$hash.".php?lang=".ConfService::getLanguage();
Expand Down Expand Up @@ -908,9 +929,9 @@ public function initPublicFolder($downloadFolder)
RewriteBase '.$path.'
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9]+)\.php$ share.php?hash=$1 [QSA]
RewriteRule ^([a-z0-9]+)-([a-z]+)$ share.php?hash=$1&lang=$2 [QSA]
RewriteRule ^([a-z0-9]+)$ share.php?hash=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ share.php?hash=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)--([a-z]+)$ share.php?hash=$1&lang=$2 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)$ share.php?hash=$1 [QSA]
</IfModule>
';
file_put_contents($downloadFolder."/.htaccess", $htaccessContent);
Expand Down Expand Up @@ -1406,7 +1427,15 @@ public function createSharedMinisite($httpVars, $repository, $accessDriver)
}else{
try{
$hash = $httpVars["hash"];
$this->getShareStore()->storeShare($repository->getId(), $data, "minisite", $hash);
$updateHash = null;
if(isSet($httpVars["minisite_hash_update"]) && !empty($httpVars["minisite_hash_update"]) && $httpVars["minisite_hash_update"] != $httpVars["hash"]){
// Existing already
$test = $this->getShareStore()->loadShare($httpVars["minisite_hash_update"]);
if(!empty($test)) throw new Exception("Sorry hash already exists");
$updateHash = $httpVars["minisite_hash_update"];

}
$hash = $this->getShareStore()->storeShare($repository->getId(), $data, "minisite", $hash, $updateHash);
}catch(Exception $e){
return $e->getMessage();
}
Expand Down Expand Up @@ -1446,7 +1475,7 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
return 100;
}
$foldersharing = $this->getFilteredOption("ENABLE_FOLDER_SHARING", $this->repository->getId());
if (isset($foldersharing) && $foldersharing === false) {
if (isset($foldersharing) && ($foldersharing === false || $foldersharing == "disable" )) {
return 103;
}
$loggedUser = AuthService::getLoggedUser();
Expand Down Expand Up @@ -1962,11 +1991,14 @@ public static function checkHash($outputData, $hash)
* @param $shareType
* @param $shareId
*/
public function addShareInMeta($node, $shareType, $shareId){
public function addShareInMeta($node, $shareType, $shareId, $originalShareId=null){
$this->getSharesFromMeta($node, $shares, true);
if(empty($shares)){
$shares = array();
}
if(!empty($shares) && $originalShareId != null && isSet($shares[$originalShareId])){
unset($shares[$originalShareId]);
}
$shares[$shareId] = array("type" => $shareType);
$node->setMetadata("ajxp_shared", array("shares" => $shares), true, AJXP_METADATA_SCOPE_REPOSITORY, true);
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/plugins/action.share/class.ShareStore.php
Expand Up @@ -69,7 +69,7 @@ private function createGenericLoader(){
* @return string $hash
* @throws Exception
*/
public function storeShare($parentRepositoryId, $shareData, $type="minisite", $existingHash = null){
public function storeShare($parentRepositoryId, $shareData, $type="minisite", $existingHash = null, $updateHash = null){

$data = serialize($shareData);
if($existingHash){
Expand All @@ -80,6 +80,10 @@ public function storeShare($parentRepositoryId, $shareData, $type="minisite", $e
if($this->sqlSupported){
$this->createGenericLoader();
$shareData["SHARE_TYPE"] = $type;
if($updateHash != null){
$this->confStorage->simpleStoreClear("share", $existingHash);
$hash = $updateHash;
}
$this->confStorage->simpleStoreSet("share", $hash, $shareData, "serial", $parentRepositoryId);
return $hash;
}
Expand Down

0 comments on commit 8b268b6

Please sign in to comment.