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

Commit

Permalink
Fix various stuff with sharing admin settings, format date, set maxim…
Browse files Browse the repository at this point in the history
…um date, etc. Fix #1095
  • Loading branch information
cdujeu committed Mar 18, 2016
1 parent dd01ff4 commit c310e6d
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -415,8 +415,8 @@ public function switchAction($action, $httpVars, $fileVars)
throw new Exception("Cannot share a non-existing file: ".$ajxpNode->getUrl());
}

$this->updateToMaxAllowedValue($httpVars, "FILE_MAX_DOWNLOAD", "downloadlimit");
$this->updateToMaxAllowedValue($httpVars, "FILE_MAX_EXPIRATION", "expiration");
$this->updateToMaxAllowedValue($httpVars, "downloadlimit", "FILE_MAX_DOWNLOAD");
$this->updateToMaxAllowedValue($httpVars, "expiration", "FILE_MAX_EXPIRATION");

$newMeta = null;
$httpHash = null;
Expand Down
5 changes: 4 additions & 1 deletion core/src/plugins/action.share/class.ShareRightsManager.php
Expand Up @@ -86,13 +86,16 @@ public function prepareSharedUserEntry($httpVars, &$shareObject, $update, $guest
$this->store->testUserCanEditShare($existingRepo->getOwner(), $existingRepo->options);
}
$uniqueUser = $shareObject->getUniqueUser();

if($guestUserPass !== null && strlen($guestUserPass)) {
$userPass = $guestUserPass;
$shareObject->setUniqueUser($uniqueUser, true);
}else if(!$shareObject->shouldRequirePassword() || ($guestUserPass !== null && $guestUserPass == "")){
$shareObject->setUniqueUser($uniqueUser, false);
}
if($update && $forcePassword && !($shareObject instanceof \Pydio\OCS\Model\TargettedLink) && !$shareObject->shouldRequirePassword() && empty($guestUserPass)){
$mess = ConfService::getMessages();
throw new Exception($mess["share_center.175"]);
}

} else {

Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/action.share/res/i18n/ca.php
Expand Up @@ -228,4 +228,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
1 change: 1 addition & 0 deletions core/src/plugins/action.share/res/i18n/de.php
Expand Up @@ -227,4 +227,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
5 changes: 3 additions & 2 deletions core/src/plugins/action.share/res/i18n/en.php
Expand Up @@ -23,7 +23,7 @@
"18"=> "Folder is shared as a new workspace",
"19"=> "Shared workspace options were successfully modified",
"20"=> "Ooops, the file you required could not be found! Maybe it was deleted or it is not shared with you anymore.",
"21"=> "Expire in (days)",
"21"=> "Will expire on",
"22"=> "Allowed Downloads",
"23"=> "Password",
"24"=> "Set expiration limits or define a password to access this share.",
Expand Down Expand Up @@ -98,7 +98,7 @@
"89"=> "Number of downloads / authorized downloads. Click to reset download counter.",
"90"=> "Link URL",
"91"=> "Tags (Enter to save)",
"92"=> "New link",
"92"=> "Create link",
"93"=> "Existing links",
"94"=> "QR Code",
"95"=> "QR code",
Expand Down Expand Up @@ -227,4 +227,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
2 changes: 1 addition & 1 deletion core/src/plugins/action.share/res/i18n/es.php
Expand Up @@ -226,5 +226,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",

"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
5 changes: 3 additions & 2 deletions core/src/plugins/action.share/res/i18n/fr.php
Expand Up @@ -22,7 +22,7 @@
"18"=> "Le répertoire a été partagé comme un nouveau dépôt",
"19"=> "Les options de partage ont été modifiées avec succès",
"20"=> "Désolé, le fichier que vous avez demandé ne peut pas être trouvé ! Peut-être a-t-il été supprimé, ou il n'est plus partagé avec vous.",
"21"=> "Expire dans (jours)",
"21"=> "Expirera le",
"22"=> "Téléchargements autorisés",
"23"=> "Mot de passe",
"24"=> "Définissez des limites d'expiration ou un mot de passe pour accèder au partage",
Expand Down Expand Up @@ -97,7 +97,7 @@
"89"=> "Nombre de téléchargements / nombre autorisés. Cliquer pour remettre à zéro.",
"90"=> "URL du lien",
"91"=> "Tags (Entrez pour sauver)",
"92"=> "Nouveau lien",
"92"=> "Créer le lien",
"93"=> "Liens existants",
"94"=> "QRCode",
"95"=> "QRcode",
Expand Down Expand Up @@ -226,4 +226,5 @@
"212" => "accepté",
"213" => "rejeté",
"214" => "pas envoyé",
"215" => "Pour activer un lien public sur un fichier ou un répertoire, vous devez lui assigner un mot de passe.",
);
1 change: 1 addition & 0 deletions core/src/plugins/action.share/res/i18n/it.php
Expand Up @@ -225,4 +225,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
1 change: 1 addition & 0 deletions core/src/plugins/action.share/res/i18n/pt.php
Expand Up @@ -226,4 +226,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
1 change: 1 addition & 0 deletions core/src/plugins/action.share/res/i18n/ru.php
Expand Up @@ -222,4 +222,5 @@
"212" => "accepted",
"213" => "rejected",
"214" => "not sent",
"215" => "To enable a public link on a file or a folder, you first need to set up a password.",
);
74 changes: 68 additions & 6 deletions core/src/plugins/action.share/res/react/ShareDialog.js
Expand Up @@ -723,14 +723,35 @@
showMailer:React.PropTypes.func
},

toggleLink: function(event){
this.props.shareModel.togglePublicLink();
toggleLink: function(){
var publicLinks = this.props.shareModel.getPublicLinks();
if(this.state.showTemporaryPassword){
this.setState({showTemporaryPassword: false, temporaryPassword: null});
}else if(!publicLinks.length && ReactModel.Share.getAuthorizations(this.props.pydio).password_mandatory){
this.setState({showTemporaryPassword: true, temporaryPassword: ''});
}else{
this.props.shareModel.togglePublicLink();
}
},

getInitialState: function(){
return {showTemporaryPassword: false, temporaryPassword: null};
},

updateTemporaryPassword: function(value, event){
if(value == undefined) value = event.currentTarget.getValue();
this.setState({temporaryPassword:value});
},

enableLinkWithPassword:function(){
this.props.shareModel.enablePublicLinkWithPassword(this.state.temporaryPassword);
this.setState({showTemporaryPassword:false, temporaryPassword:null});
},

render: function(){

var publicLinkPanes;
if(this.props.linkData){
if(this.props.linkData) {
publicLinkPanes = [
<PublicLinkField
showMailer={this.props.showMailer}
Expand All @@ -742,13 +763,33 @@
<PublicLinkPermissions
linkData={this.props.linkData}
shareModel={this.props.shareModel}
key="public-perm" />,
key="public-perm"/>,
<PublicLinkSecureOptions
linkData={this.props.linkData}
shareModel={this.props.shareModel}
pydio={this.props.pydio}
key="public-secure"
/>
];
}else if(this.state.showTemporaryPassword){
publicLinkPanes = [
<div>
<div className="section-legend" style={{marginTop:20}}>{this.context.getMessage('215')}</div>
<div>
<div style={{float:'left'}}>
<PydioForm.ValidPassword
attributes={{label:this.context.getMessage('23')}}
value={this.state.temporaryPassword}
onChange={this.updateTemporaryPassword}
/>
</div>
<div style={{marginLeft:7,marginTop: 26,float:'left'}}>
<ReactMUI.RaisedButton label={this.context.getMessage('92')} secondary={true} onClick={this.enableLinkWithPassword}/>
</div>
</div>
</div>
];

}else{
publicLinkPanes = [
<div className="section-legend" style={{marginTop:20}}>{this.context.getMessage('190')}</div>
Expand All @@ -764,7 +805,7 @@
<ReactMUI.Checkbox
disabled={this.context.isReadonly() || disableForNotOwner}
onCheck={this.toggleLink}
checked={!!this.props.linkData}
checked={!!this.props.linkData || this.state.showTemporaryPassword}
label={this.context.getMessage('189')}
/>
{publicLinkPanes}
Expand Down Expand Up @@ -1048,6 +1089,14 @@
}
},

formatDate : function(dateObject){
var dateFormatDay = this.context.getMessage('date_format', '').split(' ').shift();
return dateFormatDay
.replace('Y', dateObject.getFullYear())
.replace('m', dateObject.getMonth() + 1)
.replace('d', dateObject.getDate());
},

render: function(){
var linkId = this.props.linkData.hash;
var passContainer = this.renderPasswordContainer();
Expand All @@ -1056,8 +1105,18 @@
var expirationDateValue = this.props.shareModel.getExpirationFor(linkId, 'days') === 0 ? "" : this.props.shareModel.getExpirationFor(linkId, 'days');
var calIcon = <span className="ajxp_icon_span icon-calendar"/>;
var expDate = null;
var maxDate = null, maxDownloads = null;
var auth = ReactModel.Share.getAuthorizations(this.props.pydio);
var today = new Date();
if(parseInt(auth.max_expiration) > 0){
maxDate = new Date();
maxDate.setDate(today.getDate() + parseInt(auth.max_expiration));
}
if(parseInt(auth.max_downloads) > 0){
// todo: limit the field values by default?
maxDownloads = parseInt(auth.max_downloads);
}
if(expirationDateValue){
var today = new Date();
expDate = new Date();
expDate.setDate(today.getDate() + parseInt(expirationDateValue));
var clearValue = function(){
Expand Down Expand Up @@ -1096,15 +1155,18 @@
hintText={this.context.getMessage('21')}
autoOk={true}
minDate={new Date()}
maxDate={maxDate}
defaultDate={expDate}
showYearSelector={true}
onShow={null}
onDismiss={null}
formatDate={this.formatDate}
/>
</div>
<div style={{width:'50%', display:crtLinkDLAllowed?'inline-block':'none', position:'relative'}}>
<span className="ajxp_icon_span mdi mdi-download"/>
<ReactMUI.TextField
type="number"
disabled={this.context.isReadonly()}
floatingLabelText={this.context.getMessage('22')}
value={this.props.shareModel.getExpirationFor(linkId, 'downloads') === 0 ? "" : this.props.shareModel.getExpirationFor(linkId, 'downloads')}
Expand Down
14 changes: 13 additions & 1 deletion core/src/plugins/action.share/res/react/model/ShareModel.js
Expand Up @@ -69,6 +69,16 @@
this.save();
}

enablePublicLinkWithPassword(mandatoryPassword){
this._pendingData['enable_public_link'] = true;
this._initPendingData();
this._pendingData['links']['ajxp_create_public_link'] = {'password':mandatoryPassword};
if(!this._data['links']){
this._data['links'] = {};
}
this.save();
}

_initPendingData(){
if(!this._pendingData['links']){
this._pendingData['links'] = {};
Expand Down Expand Up @@ -731,7 +741,9 @@
file_public_link : pluginConfigs.get("ENABLE_FILE_PUBLIC_LINK"),
file_workspaces : true, //pluginConfigs.get("ENABLE_FILE_SHARING"),
editable_hash : pluginConfigs.get("HASH_USER_EDITABLE"),
pass_mandatory: false
pass_mandatory: false,
max_expiration : pluginConfigs.get("FILE_MAX_EXPIRATION"),
max_downloads : pluginConfigs.get("FILE_MAX_DOWNLOAD")
};
var pass_mandatory = pluginConfigs.get("SHARE_FORCE_PASSWORD");
if(pass_mandatory){
Expand Down

0 comments on commit c310e6d

Please sign in to comment.