aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBenjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>2024-02-26 10:07:41 +0100
committerGitHub <noreply@github.com>2024-02-26 10:07:41 +0100
commit3f269782aae587b28552a7f7ec6dc47eb2a64026 (patch)
tree28e9e5fd0e63f99c8a5156ace5d4eb4e9658b420 /lib/private
parent71997bca39979f9cfc8ddbe7eb2b7eac3c58a9fa (diff)
parent01983d50d45fdafe49d0d5a18c3931d20a60c35e (diff)
downloadnextcloud-server-3f269782aae587b28552a7f7ec6dc47eb2a64026.tar.gz
nextcloud-server-3f269782aae587b28552a7f7ec6dc47eb2a64026.zip
Merge pull request #43428 from nextcloud/feat/share-expiration-with-time
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Server.php3
-rw-r--r--lib/private/Share20/Manager.php26
2 files changed, 18 insertions, 11 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 2783e6f49c0..1aedd7d06ac 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1266,7 +1266,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->get(IEventDispatcher::class),
$c->get(IUserSession::class),
$c->get(KnownUserService::class),
- $c->get(ShareDisableChecker::class)
+ $c->get(ShareDisableChecker::class),
+ $c->get(IDateTimeZone::class),
);
return $manager;
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 40af8546818..53f88cf14ce 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -54,6 +54,7 @@ use OCP\Files\Mount\IMountManager;
use OCP\Files\Node;
use OCP\HintException;
use OCP\IConfig;
+use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -120,6 +121,7 @@ class Manager implements IManager {
/** @var KnownUserService */
private $knownUserService;
private ShareDisableChecker $shareDisableChecker;
+ private IDateTimeZone $dateTimeZone;
public function __construct(
LoggerInterface $logger,
@@ -139,7 +141,8 @@ class Manager implements IManager {
IEventDispatcher $dispatcher,
IUserSession $userSession,
KnownUserService $knownUserService,
- ShareDisableChecker $shareDisableChecker
+ ShareDisableChecker $shareDisableChecker,
+ IDateTimeZone $dateTimeZone,
) {
$this->logger = $logger;
$this->config = $config;
@@ -162,6 +165,7 @@ class Manager implements IManager {
$this->userSession = $userSession;
$this->knownUserService = $knownUserService;
$this->shareDisableChecker = $shareDisableChecker;
+ $this->dateTimeZone = $dateTimeZone;
}
/**
@@ -382,10 +386,10 @@ class Manager implements IManager {
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
- //Make sure the expiration date is a date
+ $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
- $date = new \DateTime();
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
if ($date >= $expirationDate) {
$message = $this->l->t('Expiration date is in the past');
@@ -413,9 +417,8 @@ class Manager implements IManager {
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
}
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
- $expirationDate = new \DateTime();
+ $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
-
$days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
if ($days > $defaultExpireDays) {
$days = $defaultExpireDays;
@@ -429,7 +432,7 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Expiration date is enforced');
}
- $date = new \DateTime();
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
if ($date < $expirationDate) {
@@ -469,10 +472,10 @@ class Manager implements IManager {
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
- //Make sure the expiration date is a date
+ $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
- $date = new \DateTime();
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
if ($date >= $expirationDate) {
$message = $this->l->t('Expiration date is in the past');
@@ -489,7 +492,7 @@ class Manager implements IManager {
}
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
- $expirationDate = new \DateTime();
+ $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
@@ -505,7 +508,7 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Expiration date is enforced');
}
- $date = new \DateTime();
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
if ($date < $expirationDate) {
@@ -527,6 +530,9 @@ class Manager implements IManager {
throw new \Exception($message);
}
+ if ($expirationDate instanceof \DateTime) {
+ $expirationDate->setTimezone(new \DateTimeZone(date_default_timezone_get()));
+ }
$share->setExpirationDate($expirationDate);
return $share;