diff options
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareAPIController.php')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index dd2df96bd19..5a939e88914 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -12,14 +12,17 @@ namespace OCA\Files_Sharing\Controller; use Exception; use OC\Files\FileInfo; use OC\Files\Storage\Wrapper\Wrapper; +use OC\Share20\Exception\ProviderException; use OCA\Files\Helper; use OCA\Files_Sharing\Exceptions\SharingRightsException; use OCA\Files_Sharing\External\Storage; use OCA\Files_Sharing\ResponseDefinitions; use OCA\Files_Sharing\SharedStorage; +use OCA\ShareByMail\ShareByMailProvider; use OCP\App\IAppManager; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; @@ -46,6 +49,7 @@ use OCP\Server; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; +use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; use Psr\Container\ContainerExceptionInterface; @@ -81,6 +85,7 @@ class ShareAPIController extends OCSController { private IPreview $previewManager, private IDateTimeZone $dateTimeZone, private LoggerInterface $logger, + private IProviderFactory $factory, ?string $userId = null ) { parent::__construct($appName, $request); @@ -2025,6 +2030,50 @@ class ShareAPIController extends OCSController { } } } + } + + public function sendShareEmail(int $shareId, $emails = []) { + try { + $share = $this->shareManager->getShareById($shareId); + + // Only mail and link shares are supported + if ($share->getShareType() !== IShare::TYPE_EMAIL + && $share->getShareType() !== IShare::TYPE_LINK) { + throw new OCSBadRequestException('Only email and link shares are supported'); + } + + // Allow sending the mail again if the share is an email share + if ($share->getShareType() === IShare::TYPE_EMAIL && count($emails) !== 0) { + throw new OCSBadRequestException('Emails should not be provided for email shares'); + } + + // Allow sending a mail if the share is a link share AND a list of emails is provided + if ($share->getShareType() === IShare::TYPE_LINK && count($emails) === 0) { + throw new OCSBadRequestException('Emails should be provided for link shares'); + } + + $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', + ['token' => $share->getToken()]); + try { + /** @var ShareByMailProvider */ + $provider = $this->factory->getProviderForType(IShare::TYPE_EMAIL); + $provider->sendMailNotification( + $share->getNode()->getName(), + $link, + $share->getSharedBy(), + $share->getSharedWith(), + $share->getExpirationDate(), + $share->getNote() + ); + return new JSONResponse(['message' => 'ok']); + } catch (ProviderException $e) { + throw new OCSBadRequestException($this->l->t('Sending mail notification is not enabled')); + } catch (Exception $e) { + throw new OCSException($this->l->t('Error while sending mail notification')); + } + } catch (ShareNotFound $e) { + throw new OCSNotFoundException($this->l->t('Wrong share ID, share does not exist')); + } } } |