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

Commit 36b32ee

Browse files
committed
Add new parameter in ShareCenter to force password on public links.
1 parent d57bd98 commit 36b32ee

File tree

11 files changed

+116
-37
lines changed

11 files changed

+116
-37
lines changed

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

Lines changed: 86 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ Class.create("ShareCenter", {
4646
if(console) console.log(e);
4747
}
4848
});
49+
var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
50+
this.authorizations = {
51+
folder_public_link : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'minisite' ,
52+
folder_workspaces : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'workspace' ,
53+
file_public_link : pluginConfigs.get("ENABLE_FILE_PUBLIC_LINK"),
54+
editable_hash : pluginConfigs.get("HASH_USER_EDITABLE")
55+
};
56+
var pass_mandatory = pluginConfigs.get("SHARE_FORCE_PASSWORD");
57+
if(pass_mandatory){
58+
this.authorizations.password_mandatory = true;
59+
}
60+
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
4961
},
5062

5163
performShareAction : function(dataModel){
@@ -56,6 +68,11 @@ Class.create("ShareCenter", {
5668
}else{
5769
userSelection = ajaxplorer.getUserSelection();
5870
}
71+
var pass_mandatory = ajaxplorer.getPluginConfigs("action.share").get("SHARE_FORCE_PASSWORD");
72+
if(pass_mandatory){
73+
this.authorizations.password_mandatory = true;
74+
}
75+
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
5976
this.currentNode = userSelection.getUniqueNode();
6077
this.shareFolderMode = "workspace";
6178
this.readonlyMode = this.currentNode.getMetadata().get('share_data') ? true : false;
@@ -94,14 +111,12 @@ Class.create("ShareCenter", {
94111

95112
performShare: function(type){
96113
this.currentNode = ajaxplorer.getUserSelection().getUniqueNode();
97-
var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
98-
this.authorizations = {
99-
folder_public_link : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'minisite' ,
100-
folder_workspaces : pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'both' || pluginConfigs.get("ENABLE_FOLDER_SHARING") == 'workspace' ,
101-
file_public_link : pluginConfigs.get("ENABLE_FILE_PUBLIC_LINK"),
102-
editable_hash : pluginConfigs.get("HASH_USER_EDITABLE")
103-
};
104114

115+
var pass_mandatory = ajaxplorer.getPluginConfigs("action.share").get("SHARE_FORCE_PASSWORD");
116+
if(pass_mandatory){
117+
this.authorizations.password_mandatory = true;
118+
}
119+
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
105120
if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link && !this.authorizations.folder_workspaces){
106121
alert('You are not authorized to share folders');
107122
return;
@@ -139,17 +154,24 @@ Class.create("ShareCenter", {
139154
alert(MessageHash[349]);
140155
return false;
141156
}
142-
oForm.addClassName("share_edit");
143-
var userSelection = ajaxplorer.getUserSelection();
144-
var publicUrl = ajxpServerAccessPath+'&get_action=share';
145-
publicUrl = userSelection.updateFormOrUrl(null, publicUrl);
146-
var conn = new Connexion(publicUrl);
147-
conn.setMethod("POST");
148157
var params = modal.getForm().serialize(true);
149158
var passwordField = modal.getForm().down('input[name="guest_user_pass"]');
150159
if(passwordField.readAttribute('data-password-set') === 'true' && !passwordField.getValue()){
151160
delete params['guest_user_pass'];
152161
}
162+
if(this.shareFolderMode == "minisite_public" && this.authorizations.password_mandatory && passwordField.readAttribute('data-password-set') !== 'true'
163+
&& ( !params['guest_user_pass'] || params['guest_user_pass'].length < parseInt(pydio.getPluginConfigs("core.auth").get("PASSWORD_MINLENGTH")) ) ){
164+
pydio.displayMessage('ERROR', MessageHash["share_center.175"]);
165+
passwordField.addClassName("SF_failed");
166+
modal.getForm().down('#generate_publiclet').show();
167+
return;
168+
}
169+
var userSelection = ajaxplorer.getUserSelection();
170+
var publicUrl = ajxpServerAccessPath+'&get_action=share';
171+
publicUrl = userSelection.updateFormOrUrl(null, publicUrl);
172+
var conn = new Connexion(publicUrl);
173+
conn.setMethod("POST");
174+
oForm.addClassName("share_edit");
153175
conn.setParameters(params);
154176
if(this._currentRepositoryId){
155177
conn.addParameter("repository_id", this._currentRepositoryId);
@@ -389,23 +411,26 @@ Class.create("ShareCenter", {
389411
}
390412
};
391413
oForm.down('#repo_label').setValue(getBaseName(this.currentNode.getPath()));
392-
if(!$('share_folder_form').autocompleter){
414+
var shareFolderForm = oForm.down('#share_folder_form');
415+
if(!shareFolderForm.autocompleter){
393416
var pref = ajaxplorer.getPluginConfigs("action.share").get("SHARED_USERS_TMP_PREFIX");
394-
$('share_folder_form').autocompleter = new AjxpUsersCompleter(
395-
$("shared_user"),
396-
$("shared_users_summary"),
417+
shareFolderForm.autocompleter = new AjxpUsersCompleter(
418+
oForm.down("#shared_user"),
419+
oForm.down("#shared_users_summary"),
397420
$("shared_users_autocomplete_choices"),
398421
{
399422
tmpUsersPrefix:pref,
400423
updateUserEntryAfterCreate:updateUserEntryAfterCreate,
401-
indicator: $("complete_indicator"),
424+
indicator: oForm.down("#complete_indicator"),
402425
minChars:parseInt(ajaxplorer.getPluginConfigs("conf").get("USERS_LIST_COMPLETE_MIN_CHARS"))
403426
}
404427
);
405428
}
429+
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', this.authorizations.password_placeholder);
406430
if(this.readonlyMode){
407-
$("shared_user").disabled = true;
431+
oForm.down("#shared_user").disabled = true;
408432
}
433+
var openBlocks = null;
409434
this._currentRepositoryId = null;
410435
this._currentRepositoryLink = null;
411436
this._currentRepositoryLabel = null;
@@ -433,18 +458,34 @@ Class.create("ShareCenter", {
433458
if(json['password']){
434459
oForm.down('input[name="guest_user_pass"]').setValue(json['password']);
435460
}
461+
var passwordField = oForm.down('input[name="guest_user_pass"]');
462+
var passwordButton = oForm.down('#remove_user_pass');
463+
var protopassContainer = oForm.down('#password_strength_checker');
436464
if(json['has_password']){
437-
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', '***********');
438-
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'true');
439-
oForm.down('#remove_user_pass').show();
440-
oForm.down('#remove_user_pass').observeOnce('click', function(){
441-
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'false');
442-
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', MessageHash['share_center.148']);
443-
oForm.down('#remove_user_pass').hide();
465+
var placeholder = this.authorizations.password_placeholder;
466+
passwordField.writeAttribute('placeholder', '***********');
467+
passwordField.writeAttribute('data-password-set', 'true');
468+
protopassContainer.hide();
469+
passwordButton.show();
470+
passwordButton.observeOnce('click', function(){
471+
passwordField.writeAttribute('data-password-set', 'false');
472+
passwordField.writeAttribute('placeholder', placeholder);
473+
passwordButton.hide();
474+
protopassContainer.show();
475+
new Protopass(passwordField, {
476+
barContainer : protopassContainer,
477+
barPosition:'bottom',
478+
labelWidth: 28
479+
});
444480
});
445481
}else{
446-
oForm.down('input[name="guest_user_pass"]').writeAttribute('data-password-set', 'false');
447-
oForm.down('#remove_user_pass').hide();
482+
passwordField.writeAttribute('data-password-set', 'false');
483+
passwordButton.hide();
484+
new Protopass(passwordField, {
485+
barContainer : protopassContainer,
486+
barPosition:'bottom',
487+
labelWidth: 28
488+
});
448489
}
449490
if(json['expire_time']){
450491
oForm.down('input[name="expiration"]').setValue(json['expire_after']);
@@ -515,7 +556,14 @@ Class.create("ShareCenter", {
515556
if(this.authorizations.editable_hash){
516557
oForm.down('#editable_hash_link').insert({top:MessageHash['share_center.171'] + ': '});
517558
}
518-
559+
if(this.authorizations.password_mandatory){
560+
openBlocks = ["security_parameters"];
561+
}
562+
new Protopass(oForm.down('input[name="guest_user_pass"]'), {
563+
barContainer : oForm.down('#password_strength_checker'),
564+
barPosition:'bottom',
565+
labelWidth: 28
566+
});
519567
if(this.shareFolderMode != "workspace"){
520568
var generateButton = oForm.down("#generate_publiclet");
521569
var container = oForm.down('.layout_template_container');
@@ -558,14 +606,16 @@ Class.create("ShareCenter", {
558606
if(!reload){
559607
window.setTimeout(modal.refreshDialogPosition.bind(modal), 400);
560608
}
561-
this.accordionize(oForm);
609+
this.accordionize(oForm, openBlocks);
562610

563611
}.bind(this);
564612
var closeFunc = function (oForm){
565613
if(Prototype.Browser.IE){
614+
/*
566615
if($(document.body).down("#shared_users_autocomplete_choices")){
567616
$(document.body).down("#shared_users_autocomplete_choices").remove();
568617
}
618+
*/
569619
if($(document.body).down("#shared_users_autocomplete_choices_iefix")){
570620
$(document.body).down("#shared_users_autocomplete_choices_iefix").remove();
571621
}
@@ -733,14 +783,17 @@ Class.create("ShareCenter", {
733783

734784
},
735785

736-
accordionize: function(form){
786+
accordionize: function(form, openBlocks){
737787

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

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

743-
794+
if(openBlocks && openBlocks.indexOf(toggleName) > -1){
795+
toggled.addClassName('share_dialog_toggled_open');
796+
}
744797
toggler.addClassName('share_dialog_toggler');
745798
var initialHeight = toggled.getHeight();
746799
if(initialHeight){

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public function switchAction($action, $httpVars, $fileVars)
213213
} else {
214214
$httpVars["expiration"] = min($expiration,$maxexpiration);
215215
}
216+
$forcePassword = $this->getFilteredOption("SHARE_FORCE_PASSWORD", $this->repository->getId());
216217
$httpHash = null;
217218
$originalHash = null;
218219

@@ -235,6 +236,13 @@ public function switchAction($action, $httpVars, $fileVars)
235236
throw new Exception("Please provide a guest_user_pass for private link");
236237
}
237238
}
239+
if($forcePassword && (
240+
(isSet($httpVars["create_guest_user"]) && $httpVars["create_guest_user"] == "true" && empty($httpVars["guest_user_pass"]))
241+
|| (isSet($httpVars["guest_user_id"]) && isSet($httpVars["guest_user_pass"]) && $httpVars["guest_user_pass"] == "")
242+
)){
243+
$mess = ConfService::getMessages();
244+
throw new Exception($mess["share_center.175"]);
245+
}
238246
$res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
239247
if (!is_array($res)) {
240248
$url = $res;

core/src/plugins/action.share/manifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<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"/>
99
<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"/>
1010
<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"/>
11+
<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"/>
1112
<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"/>
1213
<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"/>
1314
<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"/>
@@ -140,6 +141,7 @@
140141
<div class="dialogContentMainTitle" data-toggleBlock="security_parameters">AJXP_MESSAGE[share_center.147]</div>
141142
<div class="SF_element" id="security_parameters">
142143
<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>
144+
<div id="password_strength_checker" style="width: 56%; float: right; padding-top: 7px;"></div>
143145
<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>
144146
<div class="SF_horizontal_labelRow">
145147
<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>

core/src/plugins/action.share/res/i18n/ca.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,7 @@
185185
"171" => "Link Handle",
186186
"172" => "Sorry this link is already used, please pick another handle.",
187187
"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.",
188-
"174" => "Disable Password",
188+
"174" => "Reset Password",
189+
"175" => "Please set a password and make sure it's long enough!",
190+
"176" => "(Mandatory)",
189191
);

core/src/plugins/action.share/res/i18n/de.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,6 @@
185185
"172" => "Dieser Link wird bereits genutzt. Wähle ein anderes Kürzel.",
186186
"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.",
187187
"174" => "Deaktiviere Passwort",
188+
"175" => "Please set a password and make sure it's long enough!",
189+
"176" => "(Mandatory)",
188190
);

core/src/plugins/action.share/res/i18n/en.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,7 @@
186186
"171" => "Link Handle",
187187
"172" => "Sorry this link is already used, please pick another handle.",
188188
"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.",
189-
"174" => "Disable Password",
189+
"174" => "Reset Password",
190+
"175" => "Please set a password and make sure it's long enough!",
191+
"176" => "(Mandatory)",
190192
);

core/src/plugins/action.share/res/i18n/es.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,6 @@
186186
"172" => "Sorry this link is already used, please pick another handle.",
187187
"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.",
188188
"174" => "Disable Password",
189+
"175" => "Please set a password and make sure it's long enough!",
190+
"176" => "(Mandatory)",
189191
);

core/src/plugins/action.share/res/i18n/fr.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,7 @@
185185
"171" => "Lien Personnalisé",
186186
"172" => "Désolé ce lien est déjà utilisé, veuillez en choisir un autre.",
187187
"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.",
188-
"174" => "Désactiver le mot de passe",
188+
"174" => "Remettre à zéro",
189+
"175" => "Please set a password and make sure it's long enough!",
190+
"176" => "(Mandatory)",
189191
);

core/src/plugins/action.share/res/i18n/it.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,6 @@
183183
"172" => "Spiacenti, il link è già in uso. Sceglierne un altro.",
184184
"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.",
185185
"174" => "Disabilita Password",
186+
"175" => "Please set a password and make sure it's long enough!",
187+
"176" => "(Mandatory)",
186188
);

core/src/plugins/action.share/res/i18n/pt.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,7 @@
185185
"171" => "Link Handle",
186186
"172" => "Sorry this link is already used, please pick another handle.",
187187
"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.",
188-
"174" => "Disable Password",
188+
"174" => "Reset Password",
189+
"175" => "Please set a password and make sure it's long enough!",
190+
"176" => "(Mandatory)",
189191
);

0 commit comments

Comments
 (0)