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

Commit

Permalink
Add new parameter in ShareCenter to force password on public links.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Apr 16, 2015
1 parent d57bd98 commit 36b32ee
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 37 deletions.
119 changes: 86 additions & 33 deletions core/src/plugins/action.share/class.ShareCenter.js
Expand Up @@ -46,6 +46,18 @@ Class.create("ShareCenter", {
if(console) console.log(e);
}
});
var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
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")
};
var pass_mandatory = pluginConfigs.get("SHARE_FORCE_PASSWORD");
if(pass_mandatory){
this.authorizations.password_mandatory = true;
}
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
},

performShareAction : function(dataModel){
Expand All @@ -56,6 +68,11 @@ Class.create("ShareCenter", {
}else{
userSelection = ajaxplorer.getUserSelection();
}
var pass_mandatory = ajaxplorer.getPluginConfigs("action.share").get("SHARE_FORCE_PASSWORD");
if(pass_mandatory){
this.authorizations.password_mandatory = true;
}
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
this.currentNode = userSelection.getUniqueNode();
this.shareFolderMode = "workspace";
this.readonlyMode = this.currentNode.getMetadata().get('share_data') ? true : false;
Expand Down Expand Up @@ -94,14 +111,12 @@ Class.create("ShareCenter", {

performShare: function(type){
this.currentNode = ajaxplorer.getUserSelection().getUniqueNode();
var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
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")
};

var pass_mandatory = ajaxplorer.getPluginConfigs("action.share").get("SHARE_FORCE_PASSWORD");
if(pass_mandatory){
this.authorizations.password_mandatory = true;
}
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link && !this.authorizations.folder_workspaces){
alert('You are not authorized to share folders');
return;
Expand Down Expand Up @@ -139,17 +154,24 @@ Class.create("ShareCenter", {
alert(MessageHash[349]);
return false;
}
oForm.addClassName("share_edit");
var userSelection = ajaxplorer.getUserSelection();
var publicUrl = ajxpServerAccessPath+'&get_action=share';
publicUrl = userSelection.updateFormOrUrl(null, publicUrl);
var conn = new Connexion(publicUrl);
conn.setMethod("POST");
var params = modal.getForm().serialize(true);
var passwordField = modal.getForm().down('input[name="guest_user_pass"]');
if(passwordField.readAttribute('data-password-set') === 'true' && !passwordField.getValue()){
delete params['guest_user_pass'];
}
if(this.shareFolderMode == "minisite_public" && this.authorizations.password_mandatory && passwordField.readAttribute('data-password-set') !== 'true'
&& ( !params['guest_user_pass'] || params['guest_user_pass'].length < parseInt(pydio.getPluginConfigs("core.auth").get("PASSWORD_MINLENGTH")) ) ){
pydio.displayMessage('ERROR', MessageHash["share_center.175"]);
passwordField.addClassName("SF_failed");
modal.getForm().down('#generate_publiclet').show();
return;
}
var userSelection = ajaxplorer.getUserSelection();
var publicUrl = ajxpServerAccessPath+'&get_action=share';
publicUrl = userSelection.updateFormOrUrl(null, publicUrl);
var conn = new Connexion(publicUrl);
conn.setMethod("POST");
oForm.addClassName("share_edit");
conn.setParameters(params);
if(this._currentRepositoryId){
conn.addParameter("repository_id", this._currentRepositoryId);
Expand Down Expand Up @@ -389,23 +411,26 @@ Class.create("ShareCenter", {
}
};
oForm.down('#repo_label').setValue(getBaseName(this.currentNode.getPath()));
if(!$('share_folder_form').autocompleter){
var shareFolderForm = oForm.down('#share_folder_form');
if(!shareFolderForm.autocompleter){
var pref = ajaxplorer.getPluginConfigs("action.share").get("SHARED_USERS_TMP_PREFIX");
$('share_folder_form').autocompleter = new AjxpUsersCompleter(
$("shared_user"),
$("shared_users_summary"),
shareFolderForm.autocompleter = new AjxpUsersCompleter(
oForm.down("#shared_user"),
oForm.down("#shared_users_summary"),
$("shared_users_autocomplete_choices"),
{
tmpUsersPrefix:pref,
updateUserEntryAfterCreate:updateUserEntryAfterCreate,
indicator: $("complete_indicator"),
indicator: oForm.down("#complete_indicator"),
minChars:parseInt(ajaxplorer.getPluginConfigs("conf").get("USERS_LIST_COMPLETE_MIN_CHARS"))
}
);
}
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', this.authorizations.password_placeholder);
if(this.readonlyMode){
$("shared_user").disabled = true;
oForm.down("#shared_user").disabled = true;
}
var openBlocks = null;
this._currentRepositoryId = null;
this._currentRepositoryLink = null;
this._currentRepositoryLabel = null;
Expand Down Expand Up @@ -433,18 +458,34 @@ Class.create("ShareCenter", {
if(json['password']){
oForm.down('input[name="guest_user_pass"]').setValue(json['password']);
}
var passwordField = oForm.down('input[name="guest_user_pass"]');
var passwordButton = oForm.down('#remove_user_pass');
var protopassContainer = oForm.down('#password_strength_checker');
if(json['has_password']){
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', '***********');
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'true');
oForm.down('#remove_user_pass').show();
oForm.down('#remove_user_pass').observeOnce('click', function(){
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'false');
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', MessageHash['share_center.148']);
oForm.down('#remove_user_pass').hide();
var placeholder = this.authorizations.password_placeholder;
passwordField.writeAttribute('placeholder', '***********');
passwordField.writeAttribute('data-password-set', 'true');
protopassContainer.hide();
passwordButton.show();
passwordButton.observeOnce('click', function(){
passwordField.writeAttribute('data-password-set', 'false');
passwordField.writeAttribute('placeholder', placeholder);
passwordButton.hide();
protopassContainer.show();
new Protopass(passwordField, {
barContainer : protopassContainer,
barPosition:'bottom',
labelWidth: 28
});
});
}else{
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'false');
oForm.down('#remove_user_pass').hide();
passwordField.writeAttribute('data-password-set', 'false');
passwordButton.hide();
new Protopass(passwordField, {
barContainer : protopassContainer,
barPosition:'bottom',
labelWidth: 28
});
}
if(json['expire_time']){
oForm.down('input[name="expiration"]').setValue(json['expire_after']);
Expand Down Expand Up @@ -515,7 +556,14 @@ Class.create("ShareCenter", {
if(this.authorizations.editable_hash){
oForm.down('#editable_hash_link').insert({top:MessageHash['share_center.171'] + ': '});
}

if(this.authorizations.password_mandatory){
openBlocks = ["security_parameters"];
}
new Protopass(oForm.down('input[name="guest_user_pass"]'), {
barContainer : oForm.down('#password_strength_checker'),
barPosition:'bottom',
labelWidth: 28
});
if(this.shareFolderMode != "workspace"){
var generateButton = oForm.down("#generate_publiclet");
var container = oForm.down('.layout_template_container');
Expand Down Expand Up @@ -558,14 +606,16 @@ Class.create("ShareCenter", {
if(!reload){
window.setTimeout(modal.refreshDialogPosition.bind(modal), 400);
}
this.accordionize(oForm);
this.accordionize(oForm, openBlocks);

}.bind(this);
var closeFunc = function (oForm){
if(Prototype.Browser.IE){
/*
if($(document.body).down("#shared_users_autocomplete_choices")){
$(document.body).down("#shared_users_autocomplete_choices").remove();
}
*/
if($(document.body).down("#shared_users_autocomplete_choices_iefix")){
$(document.body).down("#shared_users_autocomplete_choices_iefix").remove();
}
Expand Down Expand Up @@ -733,14 +783,17 @@ Class.create("ShareCenter", {

},

accordionize: function(form){
accordionize: function(form, openBlocks){

form.select('div[data-toggleBlock]').each(function(toggler){

var toggled = form.down('#' + toggler.readAttribute('data-toggleBlock'));
var toggleName = toggler.readAttribute('data-toggleBlock');
var toggled = form.down('#' + toggleName);
if(!toggled) return;


if(openBlocks && openBlocks.indexOf(toggleName) > -1){
toggled.addClassName('share_dialog_toggled_open');
}
toggler.addClassName('share_dialog_toggler');
var initialHeight = toggled.getHeight();
if(initialHeight){
Expand Down
8 changes: 8 additions & 0 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -213,6 +213,7 @@ public function switchAction($action, $httpVars, $fileVars)
} else {
$httpVars["expiration"] = min($expiration,$maxexpiration);
}
$forcePassword = $this->getFilteredOption("SHARE_FORCE_PASSWORD", $this->repository->getId());
$httpHash = null;
$originalHash = null;

Expand All @@ -235,6 +236,13 @@ public function switchAction($action, $httpVars, $fileVars)
throw new Exception("Please provide a guest_user_pass for private link");
}
}
if($forcePassword && (
(isSet($httpVars["create_guest_user"]) && $httpVars["create_guest_user"] == "true" && empty($httpVars["guest_user_pass"]))
|| (isSet($httpVars["guest_user_id"]) && isSet($httpVars["guest_user_pass"]) && $httpVars["guest_user_pass"] == "")
)){
$mess = ConfService::getMessages();
throw new Exception($mess["share_center.175"]);
}
$res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
if (!is_array($res)) {
$url = $res;
Expand Down
2 changes: 2 additions & 0 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -8,6 +8,7 @@
<global_param name="HASH_USER_EDITABLE" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Allow users to manually choose a hash for the generated links]" label="CONF_MESSAGE[Hash user-editable]" type="boolean" default="true" expose="true"/>
<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="SHARE_FORCE_PASSWORD" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Do not allow users to create public links, only private links (password-protected)]" label="CONF_MESSAGE[Set password mandatory]" type="boolean" default="false" expose="true"/>
<global_param name="EMAIL_INVITE_EXTERNAL" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Use external mailer for invitations]" label="CONF_MESSAGE[Force External Mailer]" type="boolean" default="false" expose="true"/>
<global_param name="CREATE_QRCODE" group="CONF_MESSAGE[Link Generation]" description="CONF_MESSAGE[Create and display QRCode for shared link]" label="CONF_MESSAGE[Create QRCode]" type="boolean" default="false" expose="true"/>
<global_param name="ENABLE_FOLDER_SHARING" group="CONF_MESSAGE[Folder Sharing]" description="CONF_MESSAGE[Enable folder sharing (workspace and minisite)]" label="CONF_MESSAGE[Enable folder sharing]" type="select" choices="both|CONF_MESSAGE[Minisites and Workspaces],minisite|CONF_MESSAGE[Minisites only],workspace|CONF_MESSAGE[Workspaces only],disable|CONF_MESSAGE[Disable Folder Sharing]" mandatory="true" default="both" expose="true"/>
Expand Down Expand Up @@ -140,6 +141,7 @@
<div class="dialogContentMainTitle" data-toggleBlock="security_parameters">AJXP_MESSAGE[share_center.147]</div>
<div class="SF_element" id="security_parameters">
<div class="SF_label" ajxp_message_id="share_center.23" style="width:130px;" title="AJXP_MESSAGE[share_center.23]">AJXP_MESSAGE[share_center.23]</div>
<div id="password_strength_checker" style="width: 56%; float: right; padding-top: 7px;"></div>
<input type="text" name="guest_user_pass" value="" placeholder="AJXP_MESSAGE[share_center.148]" autocomplete="off" class="SF_input" style="width:40% !important;"> <span style="display:none;" id="remove_user_pass">AJXP_MESSAGE[share_center.174]</span>
<div class="SF_horizontal_labelRow">
<div class="SF_label" ajxp_message_id="share_center.21" style="width:40% !important;" title="AJXP_MESSAGE[share_center.21]">AJXP_MESSAGE[share_center.21]</div>
Expand Down
4 changes: 3 additions & 1 deletion core/src/plugins/action.share/res/i18n/ca.php
Expand Up @@ -185,5 +185,7 @@
"171" => "Link Handle",
"172" => "Sorry this link is already used, please pick another handle.",
"173" => "If you want a durable and pretty link (like https://.../my-share-link), you can use this field. Link handle will be generated if left empty.",
"174" => "Disable Password",
"174" => "Reset Password",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
2 changes: 2 additions & 0 deletions core/src/plugins/action.share/res/i18n/de.php
Expand Up @@ -185,4 +185,6 @@
"172" => "Dieser Link wird bereits genutzt. Wähle ein anderes Kürzel.",
"173" => "Wenn Sie ein dauerhaften und ansehlichen Link möchten (z.B. https://.../mein-kuerzel), können Sie dieses Feld nutzen. Ansonsten wird das Kürzel zufällig generiert.",
"174" => "Deaktiviere Passwort",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
4 changes: 3 additions & 1 deletion core/src/plugins/action.share/res/i18n/en.php
Expand Up @@ -186,5 +186,7 @@
"171" => "Link Handle",
"172" => "Sorry this link is already used, please pick another handle.",
"173" => "If you want a durable and pretty link (like https://.../my-share-link), you can use this field. Link handle will be generated if left empty.",
"174" => "Disable Password",
"174" => "Reset Password",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
2 changes: 2 additions & 0 deletions core/src/plugins/action.share/res/i18n/es.php
Expand Up @@ -186,4 +186,6 @@
"172" => "Sorry this link is already used, please pick another handle.",
"173" => "If you want a durable and pretty link (like https://.../my-share-link), you can use this field. Link handle will be generated if left empty.",
"174" => "Disable Password",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
4 changes: 3 additions & 1 deletion core/src/plugins/action.share/res/i18n/fr.php
Expand Up @@ -185,5 +185,7 @@
"171" => "Lien Personnalisé",
"172" => "Désolé ce lien est déjà utilisé, veuillez en choisir un autre.",
"173" => "Si vous voulez créer un lien durable, vous pouvez utiliser ce champ pour fixer la dernière partie du lien (e.g. https://.../mon-joli-lien). Laisser vide pour générer automatiquement.",
"174" => "Désactiver le mot de passe",
"174" => "Remettre à zéro",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
2 changes: 2 additions & 0 deletions core/src/plugins/action.share/res/i18n/it.php
Expand Up @@ -183,4 +183,6 @@
"172" => "Spiacenti, il link è già in uso. Sceglierne un altro.",
"173" => "Se desideri un link personalizzato e più duraturo (come https://.../my-share-link), puoi utilizzare questo campo. Un gestore link verrà generato automaticamente in caso contrario.",
"174" => "Disabilita Password",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);
4 changes: 3 additions & 1 deletion core/src/plugins/action.share/res/i18n/pt.php
Expand Up @@ -185,5 +185,7 @@
"171" => "Link Handle",
"172" => "Sorry this link is already used, please pick another handle.",
"173" => "If you want a durable and pretty link (like https://.../my-share-link), you can use this field. Link handle will be generated if left empty.",
"174" => "Disable Password",
"174" => "Reset Password",
"175" => "Please set a password and make sure it's long enough!",
"176" => "(Mandatory)",
);

0 comments on commit 36b32ee

Please sign in to comment.