summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-01-09 00:46:26 +0100
committerBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-01-15 11:55:03 +0100
commitee6a10f8f53cae62bfa6c88a42d731864b73c54f (patch)
tree9c413c9bbca5fda074ce1e81ed56ad79a8674a54
parentbaf49e395031dfa9a271998f1cf3c1a1e1029dfc (diff)
downloadnextcloud-server-ee6a10f8f53cae62bfa6c88a42d731864b73c54f.tar.gz
nextcloud-server-ee6a10f8f53cae62bfa6c88a42d731864b73c54f.zip
fix(share): use user timezone to parse share expiration date
If an user in UTC+1 try to create a share at 00:00, it's day D for him, but D-1 for the server (UTC). This fix aims to apply the correct offset Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php21
-rw-r--r--apps/files_sharing/openapi.json2
-rw-r--r--apps/files_sharing/tests/ApiTest.php5
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php16
4 files changed, 25 insertions, 19 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index a84842cd8b5..81a6646ade3 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -66,6 +66,7 @@ use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IConfig;
+use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IPreview;
@@ -120,20 +121,6 @@ class ShareAPIController extends OCSController {
/**
* Share20OCS constructor.
- *
- * @param string $appName
- * @param IRequest $request
- * @param IManager $shareManager
- * @param IGroupManager $groupManager
- * @param IUserManager $userManager
- * @param IRootFolder $rootFolder
- * @param IURLGenerator $urlGenerator
- * @param string $userId
- * @param IL10N $l10n
- * @param IConfig $config
- * @param IAppManager $appManager
- * @param IServerContainer $serverContainer
- * @param IUserStatusManager $userStatusManager
*/
public function __construct(
string $appName,
@@ -149,7 +136,8 @@ class ShareAPIController extends OCSController {
IAppManager $appManager,
IServerContainer $serverContainer,
IUserStatusManager $userStatusManager,
- IPreview $previewManager
+ IPreview $previewManager,
+ private IDateTimeZone $dateTimeZone,
) {
parent::__construct($appName, $request);
@@ -1679,11 +1667,12 @@ class ShareAPIController extends OCSController {
*/
private function parseDate(string $expireDate): \DateTime {
try {
- $date = new \DateTime(trim($expireDate, "\""));
+ $date = new \DateTime(trim($expireDate, "\""), $this->dateTimeZone->getTimeZone());
} catch (\Exception $e) {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}
+ $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$date->setTime(0, 0, 0);
return $date;
diff --git a/apps/files_sharing/openapi.json b/apps/files_sharing/openapi.json
index 59f94c5a5ea..cf81e358b5d 100644
--- a/apps/files_sharing/openapi.json
+++ b/apps/files_sharing/openapi.json
@@ -1563,7 +1563,7 @@
{
"name": "expireDate",
"in": "query",
- "description": "Expiry date of the share",
+ "description": "Expiry date of the share using user timezone at 00:00. It means date in UTC timezone will be used.",
"schema": {
"type": "string",
"default": ""
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 3484bb29d94..25e32f67b72 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -45,6 +45,7 @@ use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IConfig;
+use OCP\IDateTimeZone;
use OCP\IL10N;
use OCP\IPreview;
use OCP\IRequest;
@@ -123,6 +124,7 @@ class ApiTest extends TestCase {
$serverContainer = $this->createMock(IServerContainer::class);
$userStatusManager = $this->createMock(IUserStatusManager::class);
$previewManager = $this->createMock(IPreview::class);
+ $dateTimeZone = $this->createMock(IDateTimeZone::class);
return new ShareAPIController(
self::APP_NAME,
@@ -138,7 +140,8 @@ class ApiTest extends TestCase {
$appManager,
$serverContainer,
$userStatusManager,
- $previewManager
+ $previewManager,
+ $dateTimeZone,
);
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 2a2a7d940be..5ecb5185512 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -48,6 +48,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\Storage;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
+use OCP\IDateTimeZone;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
@@ -118,6 +119,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IPreview|\PHPUnit\Framework\MockObject\MockObject */
private $previewManager;
+ /** @var IDateTimeZone|\PHPUnit\Framework\MockObject\MockObject */
+ private $dateTimeZone;
+
protected function setUp(): void {
$this->shareManager = $this->createMock(IManager::class);
$this->shareManager
@@ -148,6 +152,7 @@ class ShareAPIControllerTest extends TestCase {
->willReturnCallback(function ($fileInfo) {
return $fileInfo->getMimeType() === 'mimeWithPreview';
});
+ $this->dateTimeZone = $this->createMock(IDateTimeZone::class);
$this->ocs = new ShareAPIController(
$this->appName,
@@ -163,7 +168,8 @@ class ShareAPIControllerTest extends TestCase {
$this->appManager,
$this->serverContainer,
$this->userStatusManager,
- $this->previewManager
+ $this->previewManager,
+ $this->dateTimeZone,
);
}
@@ -187,6 +193,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
}
@@ -775,6 +782,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['canAccessShare'])
->getMock();
@@ -1399,6 +1407,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
@@ -1738,6 +1747,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
@@ -1832,6 +1842,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
@@ -2241,6 +2252,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
@@ -2307,6 +2319,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();
@@ -2546,6 +2559,7 @@ class ShareAPIControllerTest extends TestCase {
$this->serverContainer,
$this->userStatusManager,
$this->previewManager,
+ $this->dateTimeZone,
])->setMethods(['formatShare'])
->getMock();