Skip to content

Commit 82f1344

Browse files
committed
Adjust settings for mail link password
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>
1 parent e827e0a commit 82f1344

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

apps/sharebymail/lib/ShareByMailProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function create(IShare $share) {
198198

199199
// Sends share password to receiver when it's a permanent one (otherwise she will have to request it via the showShare UI)
200200
// or to owner when the password shall be given during a Talk session
201-
if ($this->config->getSystemValue('allow_mail_share_permanent_password', true) || $share->getSendPasswordByTalk()) {
201+
if ($this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false) === true || $share->getSendPasswordByTalk()) {
202202
$send = $this->sendPassword($share, $password);
203203
if ($passwordEnforced && $send === false) {
204204
$this->sendPasswordToOwner($share, $password);

apps/sharebymail/tests/ShareByMailProviderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
277277
// The given password (but not the autogenerated password) should not be
278278
// mailed to the receiver of the share because permanent passwords are not enforced.
279279
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
280-
$this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
280+
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
281281
$instance->expects($this->never())->method('autoGeneratePassword');
282282

283283
$this->assertSame('shareObject',
@@ -310,7 +310,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswo
310310
// The given password (but not the autogenerated password) should be
311311
// mailed to the receiver of the share because permanent passwords are enforced.
312312
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
313-
$this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
313+
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
314314
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
315315
$instance->expects($this->never())->method('autoGeneratePassword');
316316

@@ -363,7 +363,7 @@ public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPe
363363

364364
// The autogenerated password should be mailed to the receiver of the share because permanent passwords are enforced.
365365
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
366-
$this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
366+
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
367367
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
368368

369369
$message = $this->createMock(IMessage::class);
@@ -408,7 +408,7 @@ public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordP
408408
// The given password (but not the autogenerated password) should be
409409
// mailed to the receiver of the share.
410410
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
411-
$this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(true);
411+
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(true);
412412
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
413413
$instance->expects($this->never())->method('autoGeneratePassword');
414414

@@ -453,7 +453,7 @@ public function testCreateSendPasswordByTalkWithEnforcedPasswordProtection() {
453453

454454
// The autogenerated password should be mailed to the owner of the share.
455455
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(true);
456-
$this->config->expects($this->once())->method('getSystemValue')->with('allow_mail_share_permanent_password')->willReturn(false);
456+
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
457457
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
458458
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
459459

config/config.sample.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,18 @@
15401540
*/
15411541
'sharing.managerFactory' => '\OC\Share20\ProviderFactory',
15421542

1543+
/**
1544+
* Enables expiration for link share passwords sent by email (sharebymail).
1545+
* The passwords will expire after the configured interval, the users can
1546+
* still request a new one in the public link page.
1547+
*/
1548+
'sharing.enable_mail_link_password_expiration' => false,
1549+
1550+
/**
1551+
* Expiration interval for passwords, in seconds.
1552+
*/
1553+
'sharing.mail_link_password_expiration_interval' => 3600,
1554+
15431555
/**
15441556
* Define max number of results returned by the search for auto-completion of
15451557
* users, groups, etc. The value must not be lower than 0 (for unlimited).

lib/private/Share20/Manager.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,29 +1175,17 @@ private function updateSharePasswordIfNeeded(IShare $share, IShare $originalShar
11751175
* Set the share's password expiration time
11761176
*/
11771177
private function setSharePasswordExpirationTime(IShare $share): void {
1178-
if ($this->config->getSystemValue('allow_mail_share_permanent_password', true)) {
1178+
if (!$this->config->getSystemValue('sharing.enable_mail_link_password_expiration', false)) {
11791179
// Sets password expiration date to NULL
11801180
$share->setPasswordExpirationTime();
11811181
return;
11821182
}
11831183
// Sets password expiration date
11841184
$expirationTime = null;
1185-
try {
1186-
$now = new \DateTime();
1187-
$expirationInterval = $this->config->getSystemValue('share_temporary_password_expiration_interval');
1188-
if ($expirationInterval === '' || is_null($expirationInterval)) {
1189-
$expirationInterval = 'P0DT15M';
1190-
}
1191-
$expirationTime = $now->add(new \DateInterval($expirationInterval));
1192-
} catch (\Exception $e) {
1193-
// Catches invalid format for system value 'share_temporary_password_expiration_interval'
1194-
\OC::$server->getLogger()->logException($e, [
1195-
'message' => 'The \'share_temporary_password_expiration_interval\' system setting does not respect the DateInterval::__construct() format. Setting it to \'P0DT15M\''
1196-
]);
1197-
$expirationTime = $now->add(new \DateInterval('P0DT15M'));
1198-
} finally {
1199-
$share->setPasswordExpirationTime($expirationTime);
1200-
}
1185+
$now = new \DateTime();
1186+
$expirationInterval = $this->config->getSystemValue('sharing.mail_link_password_expiration_interval', 3600);
1187+
$expirationTime = $now->add(new \DateInterval('PT' . $expirationInterval . 'S'));
1188+
$share->setPasswordExpirationTime($expirationTime);
12011189
}
12021190

12031191

0 commit comments

Comments
 (0)