create activity if a password was send by mail

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-04-19 15:10:22 +02:00
parent f0651cb066
commit f00c1eccf7
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
2 changed files with 101 additions and 24 deletions

View File

@ -58,6 +58,8 @@ class Activity implements IProvider {
const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
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';
/**
* @param IFactory $languageFactory
@ -119,15 +121,26 @@ class Activity implements IProvider {
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
'email' => $parsedParameters['email'],
'actor' => $parsedParameters['actor'],
])
->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 send to %1$s', [
$parsedParameters['email']['name']
]))
->setRichSubject($this->l->t('Password for mail share send to {email}'), [
'email' => $parsedParameters['email']
])
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
$event->setParsedSubject($this->l->t('Password for mail share send to you'))
->setRichSubject($this->l->t('Password for mail share send to you'))
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else {
throw new \InvalidArgumentException();
}
@ -153,12 +166,26 @@ class Activity implements IProvider {
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters)
->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 send to %2s', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name']
]))
->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
$event->setParsedSubject(
$this->l->t('Password to access %1$s was send to you',
[$parsedParameters['file']['path']]))
->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else {
throw new \InvalidArgumentException();
}
@ -182,6 +209,15 @@ class Activity implements IProvider {
'email' => $this->generateEmailParameter($parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
'email' => $this->generateEmailParameter($parameters[1]),
];
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
];
}
throw new \InvalidArgumentException();
}

View File

@ -172,11 +172,12 @@ class ShareByMailProvider implements IShareProvider {
}
$shareId = $this->createMailShare($share);
$send = $this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $password);
$send = $this->sendPassword($share, $password);
if ($passwordEnforced && $send === false) {
$this->sendPasswordToOwner($share->getNode()->getName(), $share->getSharedBy(), $shareWith, $password);
$this->sendPasswordToOwner($share, $password);
}
$this->createActivity($share);
$this->createShareActivity($share);
$data = $this->getRawShare($shareId);
return $this->createShareObject($data);
@ -212,7 +213,7 @@ class ShareByMailProvider implements IShareProvider {
*
* @param IShare $share
*/
protected function createActivity(IShare $share) {
protected function createShareActivity(IShare $share) {
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
@ -240,6 +241,37 @@ class ShareByMailProvider implements IShareProvider {
}
/**
* create activity if a file/folder was shared by mail
*
* @param IShare $share
* @param string $sharedWith
* @param bool $sendToSelf
*/
protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) {
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
if ($sendToSelf) {
$this->publishActivity(
Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF,
[$userFolder->getRelativePath($share->getNode()->getPath())],
$share->getSharedBy(),
$share->getNode()->getId(),
$userFolder->getRelativePath($share->getNode()->getPath())
);
} else {
$this->publishActivity(
Activity::SUBJECT_SHARED_EMAIL_PASSWORD_SEND,
[$userFolder->getRelativePath($share->getNode()->getPath()), $sharedWith],
$share->getSharedBy(),
$share->getNode()->getId(),
$userFolder->getRelativePath($share->getNode()->getPath())
);
}
}
/**
* publish activity if a file/folder was shared by mail
*
@ -384,13 +416,15 @@ class ShareByMailProvider implements IShareProvider {
/**
* send password to recipient of a mail share
*
* @param string $filename
* @param string $initiator
* @param string $shareWith
* @param IShare $share
* @param string $password
* @return bool
*/
protected function sendPassword($filename, $initiator, $shareWith, $password) {
protected function sendPassword(IShare $share, $password) {
$filename = $share->getNode()->getName();
$initiator = $share->getSharedBy();
$shareWith = $share->getSharedWith();
if ($password === '' || $this->settingsManager->sendPasswordByMail() === false) {
return false;
@ -422,6 +456,8 @@ class ShareByMailProvider implements IShareProvider {
$message->setHtmlBody($emailTemplate->renderHtml());
$this->mailer->send($message);
$this->createPasswordSendActivity($share, $shareWith, false);
return true;
}
@ -429,17 +465,18 @@ class ShareByMailProvider implements IShareProvider {
* send auto generated password to the owner. This happens if the admin enforces
* a password for mail shares and forbid to send the password by mail to the recipient
*
* @param string $filename
* @param string $initiator
* @param string $shareWith
* @param IShare $share
* @param string $password
* @return bool
* @throws \Exception
*/
protected function sendPasswordToOwner($filename, $initiator, $shareWith, $password) {
protected function sendPasswordToOwner(IShare $share, $password) {
$initiatorUser = $this->userManager->get($initiator);
$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
$filename = $share->getNode()->getName();
$initiator = $this->userManager->get($share->getSharedBy());
$initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null;
$initiatorDisplayName = ($initiator instanceof IUser) ? $initiator->getDisplayName() : $share->getSharedBy();
$shareWith = $share->getSharedWith();
if ($initiatorEMailAddress === null) {
throw new \Exception(
@ -469,6 +506,10 @@ class ShareByMailProvider implements IShareProvider {
$message->setBody($emailTemplate->renderText(), 'text/plain');
$message->setHtmlBody($emailTemplate->renderHTML());
$this->mailer->send($message);
$this->createPasswordSendActivity($share, $shareWith, true);
return true;
}
/**
@ -561,7 +602,7 @@ class ShareByMailProvider implements IShareProvider {
$validPassword = $plainTextPassword !== null && $plainTextPassword !== '';
if($validPassword && $originalShare->getPassword() !== $share->getPassword()) {
$this->sendPassword($share->getNode()->getName(), $share->getSharedBy(), $share->getSharedWith(), $plainTextPassword);
$this->sendPassword($share, $plainTextPassword);
}
/*
* We allow updating the permissions and password of mail shares