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

Commit

Permalink
Merge pull request #242 from echampet/sharelimits
Browse files Browse the repository at this point in the history
Add configurable limit for action.share plugin
  • Loading branch information
cdujeu committed Aug 27, 2013
2 parents fb4c4cd + 3fb2824 commit 97eb8f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
18 changes: 17 additions & 1 deletion core/src/plugins/action.share/class.ShareCenter.js
Expand Up @@ -221,7 +221,7 @@ Class.create("ShareCenter", {
};
oForm.down('#repo_label').setValue(getBaseName(this.currentNode.getPath()));
if(!$('share_folder_form').autocompleter){
var pref = ajaxplorer.getPluginConfigs("ajxp_plugin[@name='share']").get("SHARED_USERS_TMP_PREFIX");
var pref = ajaxplorer.getPluginConfigs("ajxp_plugin[@id='action.share']").get("SHARED_USERS_TMP_PREFIX");
$('share_folder_form').autocompleter = new AjxpUsersCompleter(
$("shared_user"),
$("shared_users_summary"),
Expand Down Expand Up @@ -383,6 +383,14 @@ Class.create("ShareCenter", {
}.bind(this));
this.updateDialogButtons(oForm.down("div.dialogButtons"), "file");
}else{
this.maxexpiration = parseInt(ajaxplorer.getPluginConfigs("ajxp_plugin[@id='action.share']").get("FILE_MAX_EXPIRATION"));
if(this.maxexpiration > 0){
oForm.down("[name='expiration']").setValue(this.maxexpiration);
}
this.maxdownload = parseInt(ajaxplorer.getPluginConfigs("ajxp_plugin[@id='action.share']").get("FILE_MAX_DOWNLOAD"));
if(this.maxdownload > 0){
oForm.down("[name='downloadlimit']").setValue(this.maxdownload);
}
var button = $(oForm).down('div#generate_publiclet');
button.observe("click", this.generatePublicLinkCallback.bind(this));
}
Expand Down Expand Up @@ -557,6 +565,14 @@ Class.create("ShareCenter", {
ajaxplorer.displayMessage("ERROR", MessageHash["share_center.75"]);
return;
}
if(this.maxexpiration > 0 && !(serialParams["expiration"] > 0 && serialParams["expiration"] <= this.maxexpiration) ){
ajaxplorer.displayMessage("ERROR", "Expiration must be between 1 and " + this.maxexpiration);
return;
}
if(this.maxdownload > 0 && !(serialParams["downloadlimit"] > 0 && serialParams["downloadlimit"] <= this.maxdownload) ){
ajaxplorer.displayMessage("ERROR", "Download limit must be between 1 and " + this.maxdownload);
return;
}

oForm.down('img#generate_image').src = window.ajxpResourcesFolder+"/images/autocompleter-loader.gif";
conn.setParameters(serialParams);
Expand Down
14 changes: 12 additions & 2 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -144,9 +144,19 @@ function switchAction($action, $httpVars, $fileVars){
}
print($url);
}else{
if(!isSet($httpVars["downloadlimit"])){
$httpVars["downloadlimit"] = 0;
$maxdownload = $this->getFilteredOption("FILE_MAX_DOWNLOAD", $this->repository->getId());
if(!isSet($httpVars["downloadlimit"]) || $httpVars["downloadlimit"] == 0){
$httpVars["downloadlimit"] = $maxdownload;
}else{
$httpVars["downloadlimit"] = min($maxdownload,floor(abs($httpVars["downloadlimit"])));
}
$maxexpiration = $this->getFilteredOption("FILE_MAX_EXPIRATION", $this->repository->getId());
if(!isSet($httpVars["expiration"]) || $httpVars["expiration"] == 0){
$httpVars["expiration"] = $maxexpiration;
}else{
$httpVars["expiration"] = min($maxexpiration,floor(abs($httpVars["expiration"])));
}

$data = $this->accessDriver->makePublicletOptions($file, $httpVars["password"], $httpVars["expiration"], $httpVars["downloadlimit"], $this->repository);
$customData = array();
foreach($httpVars as $key => $value){
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -3,6 +3,8 @@
<server_settings>
<global_param name="USE_REWRITE_RULE" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Use web server RewriteEngine mechanism to generate prettier URLs]" label="CONF_MESSAGE[Use Rewrite Rule]" type="boolean" default="false"/>
<global_param name="HASH_MIN_LENGTH" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Minimum length of the generated hash]" label="CONF_MESSAGE[Hash minimum length]" type="integer" default="6"/>
<global_param name="FILE_MAX_EXPIRATION" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Maximum share expiration limit for file, 0 = unlimited]" label="CONF_MESSAGE[Maximum file expiration limit]" type="integer" default="0" expose="true"/>
<global_param name="FILE_MAX_DOWNLOAD" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Maximum download limit for file, 0 = unlimited]" label="CONF_MESSAGE[Maximum file download limit]" type="integer" default="0" expose="true"/>
<global_param name="AVOID_SHARED_FOLDER_SAME_LABEL" group="CONF_MESSAGE[Folder Sharing]" description="CONF_MESSAGE[Disallow users to create shared folders if a workspace already exists with the same label]" label="CONF_MESSAGE[Avoid labels duplication]" type="boolean" default="true"/>
<!--
<global_param name="SHARED_USERS_LIST_MINIMUM" group="CONF_MESSAGE[Shared users configurations]" description="CONF_MESSAGE[Minimum number of characters to start getting results by auto-completion when sharing a folder with other users]" label="CONF_MESSAGE[Autocomplete minimum chars]" type="integer" default="2" expose="true"/>
Expand Down

0 comments on commit 97eb8f9

Please sign in to comment.