aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-02-29 11:33:03 +0100
committerGitHub <noreply@github.com>2024-02-29 11:33:03 +0100
commitf318c296ee76115668287fdb20a6b9c0f6d0708a (patch)
tree76f258c2ad3278ec2d08be3f76b85a436d70f70c /apps
parentad6f72d0d18181bd03fbf8e7269fa28160ab5c6e (diff)
parenta4a7d82a0cb9e2023a0d0719e50738b6fc0a092a (diff)
downloadnextcloud-server-f318c296ee76115668287fdb20a6b9c0f6d0708a.tar.gz
nextcloud-server-f318c296ee76115668287fdb20a6b9c0f6d0708a.zip
Merge pull request #43833 from nextcloud/backport/43428/stable28
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php5
-rw-r--r--apps/files_sharing/tests/ApiTest.php20
-rw-r--r--apps/files_sharing/tests/CapabilitiesTest.php4
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php2
4 files changed, 21 insertions, 10 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index aa239ae8bb6..77faa2ab0c9 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -240,6 +240,7 @@ class ShareAPIController extends OCSController {
$expiration = $share->getExpirationDate();
if ($expiration !== null) {
+ $expiration->setTimezone($this->dateTimeZone->getTimeZone());
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}
@@ -1695,12 +1696,14 @@ class ShareAPIController extends OCSController {
private function parseDate(string $expireDate): \DateTime {
try {
$date = new \DateTime(trim($expireDate, "\""), $this->dateTimeZone->getTimeZone());
+ // Make sure it expires at midnight in owner timezone
+ $date->setTime(0, 0, 0);
} catch (\Exception $e) {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}
+ // Use server timezone to store the date
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
- $date->setTime(0, 0, 0);
return $date;
}
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 7e916f621aa..98f87c96f31 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -124,6 +124,7 @@ class ApiTest extends TestCase {
$userStatusManager = $this->createMock(IUserStatusManager::class);
$previewManager = $this->createMock(IPreview::class);
$dateTimeZone = $this->createMock(IDateTimeZone::class);
+ $dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));
return new ShareAPIController(
self::APP_NAME,
@@ -1060,10 +1061,9 @@ class ApiTest extends TestCase {
$config->setAppValue('core', 'shareapi_enforce_expire_date', 'yes');
$dateWithinRange = new \DateTime();
- $dateWithinRange->setTime(0, 0, 0);
- $dateWithinRange->add(new \DateInterval('P5D'));
+ $dateWithinRange->add(new \DateInterval('P6D'));
+
$dateOutOfRange = new \DateTime();
- $dateOutOfRange->setTime(0, 0, 0);
$dateOutOfRange->add(new \DateInterval('P8D'));
// update expire date to a valid value
@@ -1074,6 +1074,8 @@ class ApiTest extends TestCase {
$share1 = $this->shareManager->getShareById($share1->getFullId());
// date should be changed
+ $dateWithinRange->setTime(0, 0, 0);
+ $dateWithinRange->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
// update expire date to a value out of range
@@ -1287,12 +1289,14 @@ class ApiTest extends TestCase {
public function datesProvider() {
$date = new \DateTime();
+ $date->setTime(0, 0);
$date->add(new \DateInterval('P5D'));
+ $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
return [
- [$date->format('Y-m-d'), true],
+ [$date->format('Y-m-d H:i:s'), true],
['abc', false],
- [$date->format('Y-m-d') . 'xyz', false],
+ [$date->format('Y-m-d H:i:s') . 'xyz', false],
];
}
@@ -1318,7 +1322,7 @@ class ApiTest extends TestCase {
$data = $result->getData();
$this->assertTrue(is_string($data['token']));
- $this->assertEquals($date, substr($data['expiration'], 0, 10));
+ $this->assertEquals(substr($date, 0, 10), substr($data['expiration'], 0, 10));
// check for correct link
$url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
@@ -1326,7 +1330,7 @@ class ApiTest extends TestCase {
$share = $this->shareManager->getShareById('ocinternal:'.$data['id']);
- $this->assertEquals($date, $share->getExpirationDate()->format('Y-m-d'));
+ $this->assertEquals($date, $share->getExpirationDate()->format('Y-m-d H:i:s'));
$this->shareManager->deleteShare($share);
}
@@ -1350,7 +1354,7 @@ class ApiTest extends TestCase {
$data = $result->getData();
$this->assertTrue(is_string($data['token']));
- $this->assertEquals($date->format('Y-m-d') . ' 00:00:00', $data['expiration']);
+ $this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']);
// check for correct link
$url = \OC::$server->getURLGenerator()->getAbsoluteURL('/index.php/s/' . $data['token']);
diff --git a/apps/files_sharing/tests/CapabilitiesTest.php b/apps/files_sharing/tests/CapabilitiesTest.php
index 1a3c416b10c..d7c3f218d9f 100644
--- a/apps/files_sharing/tests/CapabilitiesTest.php
+++ b/apps/files_sharing/tests/CapabilitiesTest.php
@@ -36,6 +36,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\IConfig;
+use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -96,7 +97,8 @@ class CapabilitiesTest extends \Test\TestCase {
$this->createMock(IEventDispatcher::class),
$this->createMock(IUserSession::class),
$this->createMock(KnownUserService::class),
- $this->createMock(ShareDisableChecker::class)
+ $this->createMock(ShareDisableChecker::class),
+ $this->createMock(IDateTimeZone::class),
);
$cap = new Capabilities($config, $shareManager);
$result = $this->getFilesSharingPart($cap->getCapabilities());
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index 822212ae86f..22b1da0f285 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -845,6 +845,7 @@ class ShareAPIControllerTest extends TestCase {
$this->groupManager->method('get')->willReturnMap([
['group', $group],
]);
+ $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
$d = $ocs->getShare($share->getId())->getData()[0];
@@ -4647,6 +4648,7 @@ class ShareAPIControllerTest extends TestCase {
$this->rootFolder->method('getUserFolder')
->with($this->currentUser)
->willReturnSelf();
+ $this->dateTimeZone->method('getTimezone')->willReturn(new \DateTimeZone('UTC'));
if (!$exception) {
$this->rootFolder->method('getById')