Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
'<div class="avatar {{#if modSeed}}imageplaceholderseed{{/if}}" data-username="{{shareWith}}" {{#if modSeed}}data-seed="{{shareWith}} {{shareType}}"{{/if}}></div>' +
'{{/if}}' +
'<span class="has-tooltip username" title="{{shareWith}}">{{shareWithDisplayName}}</span>' +
'{{#if mailNotificationEnabled}} {{#unless isRemoteShare}}' +
'<span class="shareOption">' +
'<input id="mail-{{cid}}-{{shareWith}}" type="checkbox" name="mailNotification" class="mailNotification checkbox" {{#if wasMailSent}}checked="checked"{{/if}} />' +
'<label for="mail-{{cid}}-{{shareWith}}">{{notifyByMailLabel}}</label>' +
'</span>' +
'{{/unless}} {{/if}}' +
'<span class="sharingOptionsGroup">' +
'{{#if editPermissionPossible}}' +
'<span class="shareOption">' +
Expand Down Expand Up @@ -122,7 +116,6 @@
'click .unshare': 'onUnshare',
'click .icon-more': 'onToggleMenu',
'click .permissions': 'onPermissionChange',
'click .mailNotification': 'onSendMailNotification'
},

initialize: function(options) {
Expand Down Expand Up @@ -175,7 +168,6 @@
getShareeList: function() {
var universal = {
avatarEnabled: this.configModel.areAvatarsEnabled(),
mailNotificationEnabled: this.configModel.isMailNotificationEnabled(),
notifyByMailLabel: t('core', 'notify by email'),
unshareLabel: t('core', 'Unshare'),
canShareLabel: t('core', 'can reshare'),
Expand Down Expand Up @@ -371,15 +363,6 @@

this.model.updateShare(shareId, {permissions: permissions});
},

onSendMailNotification: function(event) {
var $target = $(event.target);
var $li = $(event.target).closest('li[data-share-id]');
var shareType = $li.data('share-type');
var shareWith = $li.attr('data-share-with');

this.model.sendNotificationForShare(shareType, shareWith, $target.is(':checked'));
}
});

OC.Share.ShareDialogShareeListView = ShareDialogShareeListView;
Expand Down
29 changes: 0 additions & 29 deletions core/js/shareitemmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,35 +426,6 @@
return share.mail_send === 1;
},

/**
* Sends an email notification for the given share
*
* @param {int} shareType share type
* @param {string} shareWith recipient
* @param {bool} state whether to set the notification flag or remove it
*/
sendNotificationForShare: function(shareType, shareWith, state) {
var itemType = this.get('itemType');
var itemSource = this.get('itemSource');

return $.post(
OC.generateUrl('core/ajax/share.php'),
{
action: state ? 'informRecipients' : 'informRecipientsDisabled',
recipient: shareWith,
shareType: shareType,
itemSource: itemSource,
itemType: itemType
},
function(result) {
if (result.status !== 'success') {
// FIXME: a model should not show dialogs
OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
}
}
);
},

/**
* Send the link share information by email
*
Expand Down
17 changes: 0 additions & 17 deletions core/js/tests/specs/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,6 @@ describe('OC.Share.ShareDialogShareeListView', function () {
listView.$el.find('a.showCruds').click();
expect(listView.$el.find('li.cruds').hasClass('hidden')).toEqual(false);
});

it('sends notification to user when checkbox clicked', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user1',
share_with_displayname: 'User One'
}]);
listView.render();
var notificationStub = sinon.stub(listView.model, 'sendNotificationForShare');
listView.$el.find("input[name='mailNotification']").click();
expect(notificationStub.called).toEqual(true);
notificationStub.restore();
});

});

});
80 changes: 0 additions & 80 deletions lib/private/Share/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,75 +88,6 @@ public function __construct(IUser $user,
$this->senderDisplayName = $this->user->getDisplayName();
}

/**
* inform users if a file was shared with them
*
* @param IUser[] $recipientList list of recipients
* @param string $itemSource shared item source
* @param string $itemType shared item type
* @return array list of user to whom the mail send operation failed
*/
public function sendInternalShareMail($recipientList, $itemSource, $itemType) {
$noMail = [];

foreach ($recipientList as $recipient) {
$recipientDisplayName = $recipient->getDisplayName();
$to = $recipient->getEMailAddress();

if ($to === '') {
$noMail[] = $recipientDisplayName;
continue;
}

$items = $this->getItemSharedWithUser($itemSource, $itemType, $recipient);
$filename = trim($items[0]['file_target'], '/');
$subject = (string) $this->l->t('%s shared »%s« with you', array($this->senderDisplayName, $filename));
$expiration = null;
if (isset($items[0]['expiration'])) {
try {
$date = new DateTime($items[0]['expiration']);
$expiration = $date->getTimestamp();
} catch (\Exception $e) {
$this->logger->error("Couldn't read date: ".$e->getMessage(), ['app' => 'sharing']);
}
}

$link = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile',
['fileId' => $items[0]['item_source']]
);

list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, 'internal');

// send it out now
try {
$message = $this->mailer->createMessage();
$message->setSubject($subject);
$message->setTo([$to => $recipientDisplayName]);
$message->setHtmlBody($htmlBody);
$message->setPlainBody($textBody);
$message->setFrom([
Util::getDefaultEmailAddress('sharing-noreply') =>
(string)$this->l->t('%s via %s', [
$this->senderDisplayName,
$this->defaults->getName()
]),
]);
if(!is_null($this->replyTo)) {
$message->setReplyTo([$this->replyTo]);
}

$this->mailer->send($message);
} catch (\Exception $e) {
$this->logger->error("Can't send mail to inform the user about an internal share: ".$e->getMessage(), ['app' => 'sharing']);
$noMail[] = $recipientDisplayName;
}
}

return $noMail;

}

/**
* inform recipient about public link share
*
Expand Down Expand Up @@ -224,15 +155,4 @@ private function createMailBody($filename, $link, $expiration, $prefix = '') {

return [$htmlMail, $plainTextMail];
}

/**
* @param string $itemSource
* @param string $itemType
* @param IUser $recipient
* @return array
*/
protected function getItemSharedWithUser($itemSource, $itemType, $recipient) {
return Share::getItemSharedWithUser($itemType, $itemSource, $recipient->getUID());
}

}
4 changes: 0 additions & 4 deletions settings/templates/admin/sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') print_unescaped('checked="checked"'); ?> />
<label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/>

<input type="checkbox" name="shareapi_allow_public_notification" id="allowPublicMailNotification" class="checkbox"
value="1" <?php if ($_['allowPublicMailNotification'] == 'yes') print_unescaped('checked="checked"'); ?> />
<label for="allowPublicMailNotification"><?php p($l->t('Allow users to send mail notification for shared files'));?></label><br/>

</p>
<p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden');?>">
<?php p($l->t( 'Expire after ' )); ?>
Expand Down
48 changes: 0 additions & 48 deletions tests/lib/Share/MailNotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,54 +208,6 @@ public function testSendLinkShareMailException() {
$this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600));
}

public function testSendInternalShareMail() {
$this->setupMailerMock('TestUser shared »welcome.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false);

/** @var MailNotifications | \PHPUnit_Framework_MockObject_MockObject $mailNotifications */
$mailNotifications = $this->getMockBuilder(MailNotifications::class)
->setMethods(['getItemSharedWithUser'])
->setConstructorArgs([
$this->user,
$this->l10n,
$this->mailer,
$this->logger,
$this->defaults,
$this->urlGenerator
])
->getMock();

$mailNotifications->method('getItemSharedWithUser')
->withAnyParameters()
->willReturn([
['file_target' => '/welcome.txt', 'item_source' => 123],
]);

$recipient = $this->getMockBuilder('\OCP\IUser')
->disableOriginalConstructor()->getMock();
$recipient
->expects($this->once())
->method('getEMailAddress')
->willReturn('recipient@owncloud.com');
$recipient
->expects($this->once())
->method('getDisplayName')
->willReturn('Recipient');

$this->urlGenerator->expects($this->once())
->method('linkToRouteAbsolute')
->with(
$this->equalTo('files.viewcontroller.showFile'),
$this->equalTo([
'fileId' => 123,
])
);

$recipientList = [$recipient];
$result = $mailNotifications->sendInternalShareMail($recipientList, '3', 'file');
$this->assertSame([], $result);

}

/**
* @param string $subject
*/
Expand Down