]> source.dussan.org Git - nextcloud-server.git/commitdiff
Adjust settings for mail link password 31975/head
authorVincent Petry <vincent@nextcloud.com>
Thu, 14 Apr 2022 12:06:25 +0000 (14:06 +0200)
committerVincent Petry <vincent@nextcloud.com>
Thu, 14 Apr 2022 12:13:47 +0000 (14:13 +0200)
Rename the settings and invert the meaning.
Increase default interval to one hour.
Changed the interval to be a number of seconds, to align with other
setting styles.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
apps/sharebymail/lib/ShareByMailProvider.php
apps/sharebymail/tests/ShareByMailProviderTest.php
config/config.sample.php
lib/private/Share20/Manager.php

index 70af8d0c746a10bae39858efd25d3263bcc050ff..1aa2307a27db7b67280b2c4fde25decd4499ae6c 100644 (file)
@@ -198,7 +198,7 @@ class ShareByMailProvider implements IShareProvider {
 
                // Sends share password to receiver when it's a permanent one (otherwise she will have to request it via the showShare UI)
                // or to owner when the password shall be given during a Talk session
-               if ($this->config->getSystemValue('allow_mail_share_permanent_password', true) || $share->getSendPasswordByTalk()) {
+               if ($this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false) === true || $share->getSendPasswordByTalk()) {
                        $send = $this->sendPassword($share, $password);
                        if ($passwordEnforced && $send === false) {
                                $this->sendPasswordToOwner($share, $password);
index b00ef13630fdd0224daa31b31f78126eca943231..b3e344d3ec5501b353f50c388357f79d89be4887 100644 (file)
@@ -277,7 +277,7 @@ class ShareByMailProviderTest extends TestCase {
                // The given password (but not the autogenerated password) should not be
                // mailed to the receiver of the share because permanent passwords are not enforced.
                $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
-               $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
+               $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
                $instance->expects($this->never())->method('autoGeneratePassword');
 
                $this->assertSame('shareObject',
@@ -310,7 +310,7 @@ class ShareByMailProviderTest extends TestCase {
                // The given password (but not the autogenerated password) should be
                // mailed to the receiver of the share because permanent passwords are enforced.
                $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
-               $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
+               $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
                $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
                $instance->expects($this->never())->method('autoGeneratePassword');
 
@@ -363,7 +363,7 @@ class ShareByMailProviderTest extends TestCase {
 
                // The autogenerated password should be mailed to the receiver of the share because permanent passwords are enforced.
                $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
-               $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
+               $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
                $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
 
                $message = $this->createMock(IMessage::class);
@@ -408,7 +408,7 @@ class ShareByMailProviderTest extends TestCase {
                // The given password (but not the autogenerated password) should be
                // mailed to the receiver of the share.
                $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
-               $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
+               $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
                $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
                $instance->expects($this->never())->method('autoGeneratePassword');
 
@@ -453,7 +453,7 @@ class ShareByMailProviderTest extends TestCase {
 
                // The autogenerated password should be mailed to the owner of the share.
                $this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
-               $this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
+               $this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
                $this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
                $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
 
index 4d8dcfa5660ab724e7b63b1dbe16a684031ee6a5..41c3f0bf20ac3773599b95fbf5babe5d142d39bc 100644 (file)
@@ -1540,6 +1540,18 @@ $CONFIG = [
  */
 'sharing.managerFactory' => '\OC\Share20\ProviderFactory',
 
+/**
+ * Enables expiration for link share passwords sent by email (sharebymail).
+ * The passwords will expire after the configured interval, the users can
+ * still request a new one in the public link page.
+ */
+'sharing.enable_mail_link_password_expiration' => false,
+
+/**
+ * Expiration interval for passwords, in seconds.
+ */
+'sharing.mail_link_password_expiration_interval' => 3600,
+
 /**
  * Define max number of results returned by the search for auto-completion of
  * users, groups, etc. The value must not be lower than 0 (for unlimited).
index 191b59d2b8887bb948c53462c4ad9b268445fc64..aab69eae597ebd71e0cfe96ab02e7b0a480191d4 100644 (file)
@@ -1175,29 +1175,17 @@ class Manager implements IManager {
         * Set the share's password expiration time
         */
        private function setSharePasswordExpirationTime(IShare $share): void {
-               if ($this->config->getSystemValue('allow_mail_share_permanent_password', true)) {
+               if (!$this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false)) {
                        // Sets password expiration date to NULL
                        $share->setPasswordExpirationTime();
                        return;
                }
                // Sets password expiration date
                $expirationTime = null;
-               try {
-                       $now = new \DateTime();
-                       $expirationInterval = $this->config->getSystemValue('share_temporary_password_expiration_interval');
-                       if ($expirationInterval === '' || is_null($expirationInterval)) {
-                               $expirationInterval = 'P0DT15M';
-                       }
-                       $expirationTime = $now->add(new \DateInterval($expirationInterval));
-               } catch (\Exception $e) {
-                       // Catches invalid format for system value 'share_temporary_password_expiration_interval'
-                       \OC::$server->getLogger()->logException($e, [
-                               'message' => 'The \'share_temporary_password_expiration_interval\' system setting does not respect the DateInterval::__construct() format. Setting it to \'P0DT15M\''
-                       ]);
-                       $expirationTime = $now->add(new \DateInterval('P0DT15M'));
-               } finally {
-                       $share->setPasswordExpirationTime($expirationTime);
-               }
+               $now = new \DateTime();
+               $expirationInterval = $this->config->getSystemValue('sharing.mail_link_password_expiration_interval', 3600);
+               $expirationTime = $now->add(new \DateInterval('PT' . $expirationInterval . 'S'));
+               $share->setPasswordExpirationTime($expirationTime);
        }