Skip to content

Commit

Permalink
Move sending link e-mail to OCS
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Oct 19, 2016
1 parent e072057 commit 74aee46
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
5 changes: 5 additions & 0 deletions apps/files_sharing/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
'url' => '/api/v1/shares/{id}',
'verb' => 'DELETE',
],
[
'name' => 'ShareAPI#emailLink',
'url' => '/api/v1/shares/{id}/emailLink',
'verb' => 'POST',
],
/*
* OCS Sharee API
*/
Expand Down
47 changes: 47 additions & 0 deletions apps/files_sharing/lib/API/Share20OCS.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
namespace OCA\Files_Sharing\API;

use OC\Share\MailNotifications;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSException;
Expand Down Expand Up @@ -699,6 +701,51 @@ public function updateShare(
return new DataResponse($this->formatShare($share));
}

/**
* Send a notification e-mail for a given share
*
* @param int $id
* @oaran string $toaddress Email of recipient
*
* @throws OCSNotFoundException
* @throws OCSForbiddenException
*
* @return DataResponse
*/
public function emailLink($id, $toaddress) {
try {
$share = $this->getShareById($id);
} catch (ShareNotFound $e) {
throw new OCSNotFoundException('Share not found');
}

if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
throw new OCSForbiddenException('Can\'t send link for non link share');
}

$mailer = new MailNotifications(
$this->currentUser,
\OC::$server->getL10N('core'),
\OC::$server->getMailer(),
\OC::$server->getLogger(),
new \OCP\Defaults(),
$this->urlGenerator
);

$failed = $mailer->sendLinkShareMail(
$toaddress,
$share->getNode()->getName(),
$this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]),
$share->getExpirationDate() !== null ? $share->getExpirationDate()->getTimestamp() : null
);

if ($failed === []) {
return new DataResponse([]);
} else {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
}

/**
* @param \OCP\Share\IShare $share
* @return bool
Expand Down
4 changes: 4 additions & 0 deletions core/js/sharedialogmailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@

var $emailField = this.$el.find('.emailField');
if (isLinkShare && $emailField.length !== 0) {
/*
* TODO: Need new API to search for autocomplete
*
$emailField.autocomplete({
minLength: 1,
source: function (search, response) {
Expand All @@ -154,6 +157,7 @@
.append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' )
.appendTo( ul );
};
*/
}
this.delegateEvents();

Expand Down
32 changes: 8 additions & 24 deletions core/js/shareitemmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,33 +460,17 @@
*
* @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');
sendEmailPrivateLink: function(recipientEmail, options) {
var shareId = this.get('linkShare').id;

$.post(
OC.generateUrl('core/ajax/share.php'), {
action: 'email',
toaddress: recipientEmail,
link: linkShare.link,
itemType: itemType,
itemSource: itemSource,
file: this.fileInfoModel.get('name'),
expiration: linkShare.expiration || ''
return $.ajax({
type: 'POST',
url: this._getUrl('shares/' + encodeURIComponent(shareId) + '/emailLink'),
data: {
toaddress: recipientEmail
},
function(result) {
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();
}
dataType: 'json'
});

return deferred.promise();
},

/**
Expand Down

0 comments on commit 74aee46

Please sign in to comment.