summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-10-14 12:51:32 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-14 12:51:32 +0200
commit8d5aff9db57b3496e3a42f3015e1ada76f7a9451 (patch)
tree67425aff78284367d95d52aa09b943fde47f0ea3 /core/js
parent3d5b1df5492225f620248720a3e79329178928ee (diff)
parent08600a7ed5f41cfe18a9d11cf6874cb51d741009 (diff)
downloadnextcloud-server-8d5aff9db57b3496e3a42f3015e1ada76f7a9451.tar.gz
nextcloud-server-8d5aff9db57b3496e3a42f3015e1ada76f7a9451.zip
Merge pull request #19631 from owncloud/share-emailsenterror
Fix share email sending feedback
Diffstat (limited to 'core/js')
-rw-r--r--core/js/sharedialoglinkshareview.js10
-rw-r--r--core/js/shareitemmodel.js8
-rw-r--r--core/js/tests/specs/sharedialogviewSpec.js80
-rw-r--r--core/js/tests/specs/shareitemmodelSpec.js100
4 files changed, 185 insertions, 13 deletions
diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js
index 792062f0e16..1bbd10d5724 100644
--- a/core/js/sharedialoglinkshareview.js
+++ b/core/js/sharedialoglinkshareview.js
@@ -194,13 +194,19 @@
$emailField.prop('disabled', true);
$emailButton.prop('disabled', true);
$emailField.val(t('core', 'Sending ...'));
- this.model.sendEmailPrivateLink(email).then(function() {
+ this.model.sendEmailPrivateLink(email).done(function() {
$emailField.css('font-weight', 'bold').val(t('core','Email sent'));
setTimeout(function() {
- $emailField.css('font-weight', 'normal').val('');
+ $emailField.val('');
+ $emailField.css('font-weight', 'normal');
$emailField.prop('disabled', false);
$emailButton.prop('disabled', false);
}, 2000);
+ }).fail(function() {
+ $emailField.val(email);
+ $emailField.css('font-weight', 'normal');
+ $emailField.prop('disabled', false);
+ $emailButton.prop('disabled', false);
});
}
return false;
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
index 328d291b778..1cf116f08f9 100644
--- a/core/js/shareitemmodel.js
+++ b/core/js/shareitemmodel.js
@@ -522,11 +522,12 @@
* @param {string} recipientEmail recipient email address
*/
sendEmailPrivateLink: function(recipientEmail) {
+ var deferred = $.Deferred();
var itemType = this.get('itemType');
var itemSource = this.get('itemSource');
var linkShare = this.get('linkShare');
- return $.post(
+ $.post(
OC.generateUrl('core/ajax/share.php'), {
action: 'email',
toaddress: recipientEmail,
@@ -540,8 +541,13 @@
if (!result || result.status !== 'success') {
// FIXME: a model should not show dialogs
OC.dialogs.alert(result.data.message, t('core', 'Error while sending notification'));
+ deferred.reject();
+ } else {
+ deferred.resolve();
}
});
+
+ return deferred.promise();
},
/**
diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js
index 22ae63e796a..fe4cf8e8c2b 100644
--- a/core/js/tests/specs/sharedialogviewSpec.js
+++ b/core/js/tests/specs/sharedialogviewSpec.js
@@ -380,16 +380,6 @@ describe('OC.Share.ShareDialogView', function() {
dialog.$el.find('[name=expirationCheckbox]').click();
expect(dialog.$el.find('[name=expirationCheckbox]').prop('checked')).toEqual(true);
});
- it('displayes email form when sending emails is enabled', function() {
- $('input[name=mailPublicNotificationEnabled]').val('yes');
- dialog.render();
- expect(dialog.$('#emailPrivateLink').length).toEqual(1);
- });
- it('not renders email form when sending emails is disabled', function() {
- $('input[name=mailPublicNotificationEnabled]').val('no');
- dialog.render();
- expect(dialog.$('#emailPrivateLink').length).toEqual(0);
- });
it('sets picker minDate to today and no maxDate by default', function() {
dialog.render();
dialog.$el.find('[name=linkCheckbox]').click();
@@ -422,6 +412,76 @@ describe('OC.Share.ShareDialogView', function() {
expect($.datepicker._defaults.maxDate).toEqual(new Date(2014, 0, 27, 0, 0, 0, 0));
});
});
+ describe('send link by email', function() {
+ var sendEmailPrivateLinkStub;
+ var clock;
+
+ beforeEach(function() {
+ configModel.set({
+ isMailPublicNotificationEnabled: true
+ });
+
+ shareModel.set('linkShare', {
+ isLinkShare: true,
+ token: 'tehtoken',
+ permissions: OC.PERMISSION_READ,
+ expiration: null
+ });
+
+ sendEmailPrivateLinkStub = sinon.stub(dialog.model, "sendEmailPrivateLink");
+ clock = sinon.useFakeTimers();
+ });
+ afterEach(function() {
+ sendEmailPrivateLinkStub.restore();
+ clock.restore();
+ });
+
+ it('displayes form when sending emails is enabled', function() {
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+ expect(dialog.$('#emailPrivateLink').length).toEqual(1);
+ });
+ it('form not rendered when sending emails is disabled', function() {
+ $('input[name=mailPublicNotificationEnabled]').val('no');
+ dialog.render();
+ expect(dialog.$('#emailPrivateLink').length).toEqual(0);
+ });
+ it('input cleared on success', function() {
+ var defer = $.Deferred();
+ sendEmailPrivateLinkStub.returns(defer.promise());
+
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+
+ dialog.$el.find('#emailPrivateLink #email').val('a@b.c');
+ dialog.$el.find('#emailPrivateLink').trigger('submit');
+
+ expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Sending ...');
+
+ defer.resolve();
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Email sent');
+
+ clock.tick(2000);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('');
+ });
+ it('input not cleared on failure', function() {
+ var defer = $.Deferred();
+ sendEmailPrivateLinkStub.returns(defer.promise());
+
+ $('input[name=mailPublicNotificationEnabled]').val('yes');
+ dialog.render();
+
+ dialog.$el.find('#emailPrivateLink #email').val('a@b.c');
+ dialog.$el.find('#emailPrivateLink').trigger('submit');
+
+ expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('Sending ...');
+
+ defer.reject();
+ expect(dialog.$el.find('#emailPrivateLink #email').val()).toEqual('a@b.c');
+ });
+ });
});
describe('check for avatar', function() {
beforeEach(function() {
diff --git a/core/js/tests/specs/shareitemmodelSpec.js b/core/js/tests/specs/shareitemmodelSpec.js
index b4403e28475..28daf860393 100644
--- a/core/js/tests/specs/shareitemmodelSpec.js
+++ b/core/js/tests/specs/shareitemmodelSpec.js
@@ -378,5 +378,105 @@ describe('OC.Share.ShareItemModel', function() {
});
});
+
+ describe('sendEmailPrivateLink', function() {
+ it('succeeds', function() {
+ loadItemStub.yields({
+ shares: [{
+ displayname_owner: 'root',
+ expiration: null,
+ file_source: 123,
+ file_target: '/folder',
+ id: 20,
+ item_source: '123',
+ item_type: 'folder',
+ mail_send: '0',
+ parent: null,
+ path: '/folder',
+ permissions: OC.PERMISSION_READ,
+ share_type: OC.Share.SHARE_TYPE_LINK,
+ share_with: null,
+ stime: 1403884258,
+ storage: 1,
+ token: 'tehtoken',
+ uid_owner: 'root'
+ }]
+ });
+ model.fetch();
+
+ var res = model.sendEmailPrivateLink('foo@bar.com');
+
+ expect(res.state()).toEqual('pending');
+ expect(fakeServer.requests.length).toEqual(1);
+ expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('core/ajax/share.php'));
+ expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual(
+ {
+ action: 'email',
+ toaddress: 'foo@bar.com',
+ link: model.get('linkShare').link,
+ itemType: 'file',
+ itemSource: '123',
+ file: 'shared_file_name.txt',
+ expiration: ''
+ }
+ )
+
+ fakeServer.requests[0].respond(
+ 200,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({status: 'success'})
+ );
+ expect(res.state()).toEqual('resolved');
+ });
+
+ it('fails', function() {
+ loadItemStub.yields({
+ shares: [{
+ displayname_owner: 'root',
+ expiration: null,
+ file_source: 123,
+ file_target: '/folder',
+ id: 20,
+ item_source: '123',
+ item_type: 'folder',
+ mail_send: '0',
+ parent: null,
+ path: '/folder',
+ permissions: OC.PERMISSION_READ,
+ share_type: OC.Share.SHARE_TYPE_LINK,
+ share_with: null,
+ stime: 1403884258,
+ storage: 1,
+ token: 'tehtoken',
+ uid_owner: 'root'
+ }]
+ });
+ model.fetch();
+
+ var res = model.sendEmailPrivateLink('foo@bar.com');
+
+ expect(res.state()).toEqual('pending');
+ expect(fakeServer.requests.length).toEqual(1);
+ expect(fakeServer.requests[0].url).toEqual(OC.generateUrl('core/ajax/share.php'));
+ expect(OC.parseQueryString(fakeServer.requests[0].requestBody)).toEqual(
+ {
+ action: 'email',
+ toaddress: 'foo@bar.com',
+ link: model.get('linkShare').link,
+ itemType: 'file',
+ itemSource: '123',
+ file: 'shared_file_name.txt',
+ expiration: ''
+ }
+ )
+
+ fakeServer.requests[0].respond(
+ 200,
+ { 'Content-Type': 'application/json' },
+ JSON.stringify({data: {message: 'fail'}, status: 'error'})
+ );
+ expect(res.state()).toEqual('rejected');
+ });
+ });
});