diff --git a/lib/Listeners/Files/PreppingMemberSendMail.php b/lib/Listeners/Files/PreppingMemberSendMail.php index 84c763bfa..62bbbd30a 100644 --- a/lib/Listeners/Files/PreppingMemberSendMail.php +++ b/lib/Listeners/Files/PreppingMemberSendMail.php @@ -113,7 +113,8 @@ public function __construct( * @throws UnknownRemoteException */ public function handle(Event $event): void { - if (!$event instanceof PreppingCircleMemberEvent) { + if (!$event instanceof PreppingCircleMemberEvent + || !$this->configService->enforcePasswordOnSharedFile()) { return; } diff --git a/lib/Listeners/Files/PreppingShareSendMail.php b/lib/Listeners/Files/PreppingShareSendMail.php index 961228b34..53ff481ef 100644 --- a/lib/Listeners/Files/PreppingShareSendMail.php +++ b/lib/Listeners/Files/PreppingShareSendMail.php @@ -113,7 +113,8 @@ public function __construct( * @throws UnknownRemoteException */ public function handle(Event $event): void { - if (!$event instanceof PreppingFileShareEvent) { + if (!$event instanceof PreppingFileShareEvent + || !$this->configService->enforcePasswordOnSharedFile()) { return; } diff --git a/lib/Model/ShareWrapper.php b/lib/Model/ShareWrapper.php index 02673c8f1..d5772ae58 100644 --- a/lib/Model/ShareWrapper.php +++ b/lib/Model/ShareWrapper.php @@ -623,7 +623,7 @@ public function getShare( $share->setTarget($this->getFileTarget()); $share->setProviderId($this->getProviderId()); $share->setStatus($this->getStatus()); - if ($this->hasShareToken()) { + if ($this->hasShareToken() && $this->getShareToken()->getPassword() !== '') { $share->setPassword($this->getShareToken()->getPassword()); } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index b633d587a..05626f5cb 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -99,6 +99,7 @@ class ConfigService { public const KEYHOLE_CFG_REQUEST = 'keyhole_cfg_request'; public const ROUTE_TO_CIRCLE = 'route_to_circle'; public const EVENT_EXAMPLES = 'event_examples'; + public const ENFORCE_PASSWORD = 'enforce_password'; public const SELF_SIGNED_CERT = 'self_signed_cert'; public const MEMBERS_LIMIT = 'members_limit'; @@ -129,7 +130,7 @@ class ConfigService { public const TEST_NC_BASE = 'test_nc_base'; - private $defaults = [ + private static $defaults = [ self::FRONTAL_CLOUD_BASE => '', self::FRONTAL_CLOUD_ID => '', self::FRONTAL_CLOUD_SCHEME => 'https', @@ -173,6 +174,7 @@ class ConfigService { self::KEYHOLE_CFG_REQUEST => '0', self::ROUTE_TO_CIRCLE => 'contacts.contacts.directcircle', self::EVENT_EXAMPLES => '0', + self::ENFORCE_PASSWORD => '2', self::SELF_SIGNED_CERT => '0', self::MEMBERS_LIMIT => '-1', @@ -237,7 +239,7 @@ public function getAppValue(string $key): string { return $value; } - return $this->get($key, $this->defaults); + return $this->get($key, self::$defaults); } /** @@ -327,26 +329,45 @@ public function contactsBackendType(): int { /** * @return bool - * + * @deprecated * should the password for a mail share be send to the recipient */ public function sendPasswordByMail(): bool { - return true; -// return ($this->config->getAppValue('sharebymail', 'sendpasswordmail', 'yes') === 'yes'); + return false; } - public function enforcePasswordOnFileShare(): bool { - return true; + + /** + * @return bool + */ + public function enforcePasswordOnSharedFile(): bool { + $localPolicy = $this->getAppValueInt(ConfigService::ENFORCE_PASSWORD); + if ($localPolicy !== $this->getInt(ConfigService::ENFORCE_PASSWORD, self::$defaults)) { + return ($localPolicy === 1); + } // TODO: reimplement a way to set password protection on a single Circle // if ($circle->getSetting('password_enforcement') === 'true') { // return true; // } -// return ($this->config->getAppValue('sharebymail', 'enforcePasswordProtection', 'no') === 'yes'); + $sendPasswordMail = $this->config->getAppValue( + 'sharebymail', + 'sendpasswordmail', + 'yes' + ); + + $enforcePasswordProtection = $this->config->getAppValue( + 'core', + 'shareapi_enforce_links_password', + 'no' + ); + + return ($sendPasswordMail === 'yes' + && $enforcePasswordProtection === 'yes'); } - + /** * @param DeprecatedCircle $circle * @@ -356,15 +377,7 @@ public function enforcePasswordOnFileShare(): bool { * */ public function enforcePasswordProtection(DeprecatedCircle $circle) { - if ($this->isContactsBackend()) { - return false; - } - - if ($circle->getSetting('password_enforcement') === 'true') { - return true; - } - - return ($this->config->getAppValue('sharebymail', 'enforcePasswordProtection', 'no') === 'yes'); + return false; } diff --git a/lib/Service/SendMailService.php b/lib/Service/SendMailService.php index 84d9f577d..1e91adff6 100644 --- a/lib/Service/SendMailService.php +++ b/lib/Service/SendMailService.php @@ -224,22 +224,11 @@ private function sendMailPassword( string $email, string $password ): void { - if (!$this->configService->sendPasswordByMail() || $password === '') { + if (!$this->configService->enforcePasswordOnSharedFile() || $password === '') { return; } $message = $this->mailer->createMessage(); -// $filename = $share->getNode() -// ->getName(); -// $initiator = $share->getSharedBy(); -// $shareWith = $share->getSharedWith(); -// -// $initiatorUser = $this->userManager->get($initiator); -// $initiatorDisplayName = -// ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; -// $initiatorEmailAddress = -// ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null; - $plainBodyPart = $this->l10n->t( "%1\$s shared some content with you.\nYou should have already received a separate email with a link to access it.\n", [$author]