implements setting and removing password for link shares, including forced ones

This commit is contained in:
Arthur Schiwon 2015-09-12 17:02:03 +02:00 committed by Vincent Petry
parent 5dfaa0c82d
commit 9fe6d7c568
5 changed files with 58 additions and 74 deletions

View File

@ -69,3 +69,7 @@
#shareWithList li label{
margin-right: 8px;
}
.shareTabView .icon-loading-small {
margin-left: -30px;
}

View File

@ -996,76 +996,6 @@ $(document).ready(function() {
});
});
$(document).on('click', '#dropdown #showPassword', function() {
$('#linkPass').slideToggle(OC.menuSpeed);
if (!$('#showPassword').is(':checked') ) {
var itemType = $('#dropdown').data('item-type');
var itemSource = $('#dropdown').data('item-source');
var itemSourceName = $('#dropdown').data('item-source-name');
var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
var permissions = 0;
var $loading = $('#showPassword .icon-loading-small');
// Calculate permissions
if (allowPublicUpload) {
permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
} else {
permissions = OC.PERMISSION_READ;
}
$loading.removeClass('hidden');
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName).then(function() {
$loading.addClass('hidden');
$('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link'));
});
} else {
$('#linkPassText').focus();
}
});
$(document).on('focusout keyup', '#dropdown #linkPassText', function(event) {
var linkPassText = $('#linkPassText');
if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) {
var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked');
var dropDown = $('#dropdown');
var itemType = dropDown.data('item-type');
var itemSource = dropDown.data('item-source');
var itemSourceName = $('#dropdown').data('item-source-name');
var permissions = 0;
var $loading = dropDown.find('#linkPass .icon-loading-small');
// Calculate permissions
if (allowPublicUpload) {
permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ;
} else {
permissions = OC.PERMISSION_READ;
}
var expireDateString = OC.Share.getDefaultExpirationDate();
$loading.removeClass('hidden');
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, expireDateString, function(data) {
$loading.addClass('hidden');
linkPassText.val('');
linkPassText.attr('placeholder', t('core', 'Password protected'));
if (oc_appconfig.core.enforcePasswordForPublicLink) {
OC.Share.showLink(data.token, "password set", itemSource);
OC.Share.updateIcon(itemType, itemSource);
}
$('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares}));
}, function(result) {
$loading.addClass('hidden');
linkPassText.val('');
linkPassText.attr('placeholder', result.data.message);
});
if (expireDateString !== '') {
OC.Share.showExpirationDate(expireDateString);
}
}
});
$(document).on('click', '#dropdown #expirationCheckbox', function() {
if (this.checked) {
OC.Share.showExpirationDate('');

View File

@ -94,7 +94,7 @@
throw 'missing OC.Share.ShareConfigModel';
}
_.bindAll(this, 'onLinkCheckBoxChange');
_.bindAll(this, 'onLinkCheckBoxChange', 'onPasswordEntered', 'onShowPasswordClick');
},
onLinkCheckBoxChange: function() {
@ -127,6 +127,28 @@
this.select();
},
onShowPasswordClick: function() {
this.$el.find('#linkPass').slideToggle(OC.menuSpeed);
if(!this.$el.find('#showPassword').is(':checked')) {
this.model.addLinkShare({password: ''});
} else {
this.$el.find('#linkPassText').focus();
}
},
onPasswordEntered: function() {
var password = this.$el.find('#linkPassText').val();
if(password === '') {
return;
}
this.$el.find('#linkPass .icon-loading-small')
.removeClass('hidden')
.addClass('inlineblock');
this.model.addLinkShare({password: password});
},
render: function() {
var linkShareTemplate = this.template();
@ -178,6 +200,14 @@
this.$el.find('#linkCheckbox').change(this.onLinkCheckBoxChange);
this.$el.find('#linkText').click(this.onLinkTextClick);
this.$el.find('#showPassword').click(this.onShowPasswordClick);
this.$el.find('#linkPassText').focusout(this.onPasswordEntered);
var view = this;
this.$el.find('#linkPassText').keyup(function(event) {
if(event.keyCode == 13) {
view.onPasswordEntered();
}
});
return this;
},

View File

@ -157,7 +157,7 @@
this.$el.html(baseTemplate({
shareLabel: t('core', 'Share'),
sharePlaceholder: this._renderSharePlaceholderPart(),
remoteShareInfo: this._renderRemoteShareInfoPart(),
remoteShareInfo: this._renderRemoteShareInfoPart()
}));
var view = this;

View File

@ -20,6 +20,7 @@
* @property {string} token
* @property {string|null} password
* @property {string} link
* @property {number} permissions
* @property {Date} expiration
* @property {number} stime share time
*/
@ -89,12 +90,30 @@
linkShare: {}
},
addLinkShare: function() {
addLinkShare: function(options) {
var model = this;
var expiration = this.configModel.getDefaultExpirationDateString();
var itemType = this.get('itemType');
var itemSource = this.get('itemSource');
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, this.fileInfoModel.get('name'), expiration, function(data) {
var options = options || {};
var requiredOptions = [
{ name: 'password', defaultValue: '' },
{ name: 'permissions', defaultValue: OC.PERMISSION_READ }
];
_.each(requiredOptions, function(option) {
// a provided options overrides a present value of the link
// share. If neither is given, the default value is used.
if(_.isUndefined(options[option.name])) {
options[option.name] = option.defaultValue;
var currentValue = model.get('linkShare')[option.name];
if(!_.isUndefined(currentValue)) {
options[option.name] = currentValue;
}
}
});
OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, options.password, options.permissions, this.fileInfoModel.get('name'), expiration, function(data) {
model.fetch();
//FIXME: updateIcon belongs to view
OC.Share.updateIcon(itemType, itemSource);
@ -512,6 +531,7 @@
token: share.token,
password: share.share_with,
link: link,
permissions: share.permissions,
// currently expiration is only effective for link shares.
expiration: share.expiration,
stime: share.stime