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

Commit

Permalink
do not cache Sharing configs - Fix #1013
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Jan 4, 2016
1 parent 94f1fda commit 55c1efc
Showing 1 changed file with 31 additions and 75 deletions.
106 changes: 31 additions & 75 deletions core/src/plugins/action.share/class.ShareCenter.js
Expand Up @@ -30,7 +30,6 @@ Class.create("ShareCenter", {
try{
var u = ajaxplorer.getContextHolder().getUniqueNode();
if(u.getMetadata().get("ajxp_shared")){
var leaf = u.isLeaf();
var f = $("generic_dialog_box").down("#delete_message");
if(!f.down("#share_delete_alert")){
var message;
Expand All @@ -46,18 +45,25 @@ Class.create("ShareCenter", {
if(console) console.log(e);
}
});
},

computeAuthorizations : function(){

var pluginConfigs = ajaxplorer.getPluginConfigs("action.share");
this.authorizations = {
var 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")
editable_hash : pluginConfigs.get("HASH_USER_EDITABLE"),
pass_mandatory: false
};
var pass_mandatory = pluginConfigs.get("SHARE_FORCE_PASSWORD");
if(pass_mandatory){
this.authorizations.password_mandatory = true;
authorizations.password_mandatory = true;
}
this.authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148']
authorizations.password_placeholder = pass_mandatory ? MessageHash['share_center.176'] : MessageHash['share_center.148'];
return authorizations;

},

performShareAction : function(dataModel){
Expand All @@ -68,11 +74,6 @@ 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 @@ -111,13 +112,8 @@ Class.create("ShareCenter", {

performShare: function(type){
this.currentNode = ajaxplorer.getUserSelection().getUniqueNode();

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){
var authorizations = this.computeAuthorizations();
if(!this.currentNode.isLeaf() && !authorizations.folder_public_link && !authorizations.folder_workspaces){
alert('You are not authorized to share folders');
return;
}
Expand All @@ -132,15 +128,15 @@ Class.create("ShareCenter", {
this.shareFolderMode = 'file';
}
if(this.shareFolderMode == 'file'){
if(this.currentNode.isLeaf() && !this.authorizations.file_public_link){
if(this.currentNode.isLeaf() && !authorizations.file_public_link){
alert('You are not authorized to share files');
return;
}
this.shareFile();
}else{
if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link){
if(!this.currentNode.isLeaf() && !authorizations.folder_public_link){
this.shareFolderMode = "workspace";
}else if(!this.currentNode.isLeaf() && !this.authorizations.folder_workspaces){
}else if(!this.currentNode.isLeaf() && !authorizations.folder_workspaces){
this.shareFolderMode = "minisite_public";
}
this.shareRepository();
Expand All @@ -149,6 +145,8 @@ Class.create("ShareCenter", {

shareRepository : function(reload){

var authorizations = this.computeAuthorizations();

var submitFunc = function(oForm){
if(!oForm.down('input[name="repo_label"]').value){
alert(MessageHash[349]);
Expand All @@ -159,7 +157,7 @@ Class.create("ShareCenter", {
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'
if(this.shareFolderMode == "minisite_public" && 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");
Expand Down Expand Up @@ -308,26 +306,18 @@ Class.create("ShareCenter", {
if(this.maxdownload > 0){
oForm.down("[name='downloadlimit']").setValue(this.maxdownload);
}
if(!this.authorizations){
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){
if(!this.currentNode.isLeaf() && !authorizations.folder_public_link && !authorizations.folder_workspaces){
alert('You are not authorized to share folders');
hideLightBox();
return;
}else if(this.currentNode.isLeaf() && !this.authorizations.file_public_link){
}else if(this.currentNode.isLeaf() && !authorizations.file_public_link){
alert('You are not authorized to share files');
hideLightBox();
return;
}else if(!this.currentNode.isLeaf() && !this.authorizations.folder_public_link){
}else if(!this.currentNode.isLeaf() && !authorizations.folder_public_link){
this.shareFolderMode = "workspace";
}else if(!this.currentNode.isLeaf() && !this.authorizations.folder_workspaces){
}else if(!this.currentNode.isLeaf() && !authorizations.folder_workspaces){
this.shareFolderMode = "minisite_public";
}

Expand Down Expand Up @@ -360,7 +350,7 @@ Class.create("ShareCenter", {
oForm.down('label[for="simple_right_write"]').hide();
}

if(!this.authorizations.folder_public_link || !this.authorizations.folder_workspaces){
if(!authorizations.folder_public_link || !authorizations.folder_workspaces){
oForm.down("#share-folder-type-chooser").hide();
}else{
oForm.down('#share-folder-type-chooser').select("input").each(function(i){
Expand All @@ -384,7 +374,7 @@ Class.create("ShareCenter", {
modal.refreshDialogPosition();
});

if(!this.authorizations.editable_hash){
if(!authorizations.editable_hash){
oForm.down('#editable_hash_container').hide();
}

Expand Down Expand Up @@ -426,7 +416,7 @@ Class.create("ShareCenter", {
}
);
}
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', this.authorizations.password_placeholder);
oForm.down('input[name="guest_user_pass"]').writeAttribute('placeholder', authorizations.password_placeholder);
if(this.readonlyMode){
oForm.down("#shared_user").disabled = true;
}
Expand Down Expand Up @@ -462,7 +452,7 @@ Class.create("ShareCenter", {
var passwordButton = oForm.down('#remove_user_pass');
var protopassContainer = oForm.down('#password_strength_checker');
if(json['has_password']){
var placeholder = this.authorizations.password_placeholder;
var placeholder = authorizations.password_placeholder;
passwordField.writeAttribute('placeholder', '***********');
passwordField.writeAttribute('data-password-set', 'true');
protopassContainer.hide();
Expand Down Expand Up @@ -516,7 +506,7 @@ Class.create("ShareCenter", {
oForm.down('#simple_right_read').checked = (json.entries[0].RIGHT.indexOf('r') !== -1 && json['minisite_layout']!='ajxp_unique_dl');
oForm.down('#simple_right_write').checked = (json.entries[0].RIGHT.indexOf('w') !== -1);
}
if(this.authorizations.editable_hash && this._currentMinisiteHash){
if(authorizations.editable_hash && this._currentMinisiteHash){
if(json.minisite.hash_is_shorten){
oForm.down('#editable_hash_container').hide();
}else{
Expand Down Expand Up @@ -553,10 +543,10 @@ Class.create("ShareCenter", {
$('shared_user').observeOnce("focus", function(){
$('share_folder_form').autocompleter.activate();
});
if(this.authorizations.editable_hash){
if(authorizations.editable_hash){
oForm.down('#editable_hash_link').insert({top:MessageHash['share_center.171'] + ': '});
}
if(this.authorizations.password_mandatory){
if(authorizations.password_mandatory){
openBlocks = ["security_parameters"];
}
new Protopass(oForm.down('input[name="guest_user_pass"]'), {
Expand Down Expand Up @@ -611,11 +601,6 @@ Class.create("ShareCenter", {
}.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 All @@ -627,7 +612,7 @@ Class.create("ShareCenter", {
modal.showDialogForm('Get',
'share_folder_form',
loadFunc,
submitFunc, /*(this.shareFolderMode != "workspace" || this.readonlyMode ? function(){hideLightBox();} : submitFunc),*/
submitFunc,
closeFunc,
false,
!(this.shareFolderMode == "workspace" && !this.currentNode.getMetadata().get("ajxp_shared"))
Expand Down Expand Up @@ -718,35 +703,6 @@ Class.create("ShareCenter", {

oRow.down('[name="link_url"]').setValue(linkData["publiclet_link"]);
oRow.down('[name="link_tag"]').setValue('');
/*
var actions = oRow.down('.SF_horizontal_actions');
if(linkData['has_password']){
actions.insert({top:new Element('span', {className:'icon-key simple_tooltip_observer',"data-tooltipTitle":MessageHash["share_center.85"]}).update(' '+MessageHash["share_center.84"])});
}
if(linkData["expire_time"]){
if(linkData['is_expired'] && linkData['expire_after'] <= 0 && (linkData['download_limit'] && linkData['download_limit'] != linkData['download_counter'])){
actions.insert({top:new Element('span', {className:'icon-calendar simple_tooltip_observer SF_horizontal_action_destructive',"data-tooltipTitle":MessageHash["share_center.169"]}).update(' '+linkData["expire_time"])});
}else{
actions.insert({top:new Element('span', {className:'icon-calendar simple_tooltip_observer',"data-tooltipTitle":MessageHash["share_center.87"]}).update(' '+linkData["expire_time"])});
}
}
var dlC = new Element('span', {className:'icon-download-alt simple_tooltip_observer',"data-tooltipTitle":MessageHash["share_center.89"]}).update(' '+MessageHash["share_center.88"]+' '+linkData['download_counter']+'/'+linkData['download_limit']);
actions.insert({top:dlC});
dlC.observe("click", function(){
if(window.confirm(MessageHash['share_center.106'])){
var conn = new Connexion();
conn.setParameters({
file: this.currentNode.getPath(),
get_action: 'reset_counter',
element_id: linkData["element_id"]
});
conn.onComplete = function(transport){
dlC.update(' '+MessageHash["share_center.88"]+' 0/'+linkData['download_limit']);
};
conn.sendAsync();
}
}.bind(this));
*/
oRow.down('[data-action="remove"]').observe("click", function(){
this.performUnshareAction(linkData['element_id'], oRow);
}.bind(this));
Expand Down

0 comments on commit 55c1efc

Please sign in to comment.