Unshare from mail activity is missing

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-11-23 13:04:16 +01:00
parent 441496a5a5
commit 11c39b6c16
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 64 additions and 3 deletions

View File

@ -60,6 +60,8 @@ class Activity implements IProvider {
const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send';
const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self';
const SUBJECT_UNSHARED_EMAIL_SELF = 'unshared_with_email_self';
const SUBJECT_UNSHARED_EMAIL_BY = 'unshared_with_email_by';
/**
* @param IFactory $languageFactory
@ -137,6 +139,32 @@ class Activity implements IProvider {
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
$event->setParsedSubject($this->l->t('Unshared from %1$s', [
$parsedParameters['email']['name'],
]))
->setRichSubject($this->l->t('Unshared from {email}'), [
'email' => $parsedParameters['email'],
]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('Unshared from %1$s by %2$s', [
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('Unshared from {email} by {actor}'), [
'email' => $parsedParameters['email'],
'actor' => $parsedParameters['actor'],
]);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
$event->setParsedSubject($this->l->t('Password for mail share sent to %1$s', [
$parsedParameters['email']['name']
@ -196,6 +224,29 @@ class Activity implements IProvider {
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_SELF) {
$event->setParsedSubject($this->l->t('You unshared %1$s from %2$s by mail', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
]))
->setRichSubject($this->l->t('You unshared {file} from {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('%3$s unshared %1$s from %2$s by mail', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('{actor} unshared {file} from {email} by mail'), $parsedParameters);
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
} else {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
}
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
$event->setParsedSubject($this->l->t('Password to access %1$s was sent to %2s', [
$parsedParameters['file']['path'],
@ -231,11 +282,13 @@ class Activity implements IProvider {
switch ($subject) {
case self::SUBJECT_SHARED_EMAIL_SELF:
case self::SUBJECT_UNSHARED_EMAIL_SELF:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
'email' => $this->generateEmailParameter($parameters[1]),
];
case self::SUBJECT_SHARED_EMAIL_BY:
case self::SUBJECT_UNSHARED_EMAIL_BY:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
'email' => $this->generateEmailParameter($parameters[1]),

View File

@ -243,13 +243,14 @@ class ShareByMailProvider implements IShareProvider {
* create activity if a file/folder was shared by mail
*
* @param IShare $share
* @param string $type
*/
protected function createShareActivity(IShare $share) {
protected function createShareActivity(IShare $share, string $type = 'share') {
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
$this->publishActivity(
Activity::SUBJECT_SHARED_EMAIL_SELF,
$type === 'share' ? Activity::SUBJECT_SHARED_EMAIL_SELF : Activity::SUBJECT_UNSHARED_EMAIL_SELF,
[$userFolder->getRelativePath($share->getNode()->getPath()), $share->getSharedWith()],
$share->getSharedBy(),
$share->getNode()->getId(),
@ -262,6 +263,7 @@ class ShareByMailProvider implements IShareProvider {
$nodes = $ownerFolder->getById($fileId);
$ownerPath = $nodes[0]->getPath();
$this->publishActivity(
$type === 'share' ? Activity::SUBJECT_SHARED_EMAIL_BY : Activity::SUBJECT_UNSHARED_EMAIL_BY,
Activity::SUBJECT_SHARED_EMAIL_BY,
[$ownerFolder->getRelativePath($ownerPath), $share->getSharedWith(), $share->getSharedBy()],
$share->getShareOwner(),
@ -751,6 +753,11 @@ class ShareByMailProvider implements IShareProvider {
* @param IShare $share
*/
public function delete(IShare $share) {
try {
$this->createShareActivity($share, 'unshare');
} catch (\Exception $e) {
}
$this->removeShareFromTable($share->getId());
}

View File

@ -537,9 +537,10 @@ class ShareByMailProviderTest extends TestCase {
}
public function testDelete() {
$instance = $this->getInstance(['removeShareFromTable']);
$instance = $this->getInstance(['removeShareFromTable', 'createShareActivity']);
$this->share->expects($this->once())->method('getId')->willReturn(42);
$instance->expects($this->once())->method('removeShareFromTable')->with(42);
$instance->expects($this->once())->method('createShareActivity')->with($this->share, 'unshare');
$instance->delete($this->share);
}