aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorfenn-cs <fenn25.fn@gmail.com>2024-03-20 16:41:26 +0100
committerfenn-cs <fenn25.fn@gmail.com>2024-05-23 14:11:33 +0100
commit59a5b4e0bddbc29d4e16a930972be34873a73e0c (patch)
tree49c2f2dc7ee1573b7e225f951e78e781345f244b /lib
parent2fa099a6e1c905abe0d12167082e2946d8065a3a (diff)
downloadnextcloud-server-59a5b4e0bddbc29d4e16a930972be34873a73e0c.tar.gz
nextcloud-server-59a5b4e0bddbc29d4e16a930972be34873a73e0c.zip
fix(shareManager): Respect empty `expireDate` in server
If `expireDate` is an empty string and not `null` then the server should not set a default. Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php167
-rw-r--r--lib/private/Share20/Share.php19
-rw-r--r--lib/public/Share/IShare.php24
3 files changed, 127 insertions, 83 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 4f097cdc3e2..4b44edd8b01 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -348,26 +348,6 @@ class Manager implements IManager {
$expirationDate = $share->getExpirationDate();
- if ($expirationDate !== null) {
- $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
- $expirationDate->setTime(0, 0, 0);
-
- $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');
- throw new GenericShareException($message, $message, 404);
- }
- }
-
- // If expiredate is empty set a default one if there is a default
- $fullId = null;
- try {
- $fullId = $share->getFullId();
- } catch (\UnexpectedValueException $e) {
- // This is a new share
- }
-
if ($isRemote) {
$defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
$defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
@@ -379,28 +359,53 @@ class Manager implements IManager {
$configProp = 'internal_defaultExpDays';
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
}
- if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
- $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;
+
+ // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced
+ // Then skip expiration date validation as null is accepted
+ if(!($share->getNoExpirationDate() && !$isEnforced)) {
+ if ($expirationDate != null) {
+ $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
+ $expirationDate->setTime(0, 0, 0);
+
+ $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');
+ throw new GenericShareException($message, $message, 404);
+ }
}
- $expirationDate->add(new \DateInterval('P' . $days . 'D'));
- }
- // If we enforce the expiration date check that is does not exceed
- if ($isEnforced) {
- if ($expirationDate === null) {
- throw new \InvalidArgumentException('Expiration date is enforced');
+ // If expiredate is empty set a default one if there is a default
+ $fullId = null;
+ try {
+ $fullId = $share->getFullId();
+ } catch (\UnexpectedValueException $e) {
+ // This is a new share
}
- $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
- $date->setTime(0, 0, 0);
- $date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
- if ($date < $expirationDate) {
- $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays);
- throw new GenericShareException($message, $message, 404);
+ if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
+ $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;
+ }
+ $expirationDate->add(new \DateInterval('P' . $days . 'D'));
+ }
+
+ // If we enforce the expiration date check that is does not exceed
+ if ($isEnforced) {
+ if (empty($expirationDate)) {
+ throw new \InvalidArgumentException('Expiration date is enforced');
+ }
+
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
+ $date->setTime(0, 0, 0);
+ $date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
+ if ($date < $expirationDate) {
+ $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays);
+ throw new GenericShareException($message, $message, 404);
+ }
}
}
@@ -433,51 +438,57 @@ class Manager implements IManager {
*/
protected function validateExpirationDateLink(IShare $share) {
$expirationDate = $share->getExpirationDate();
-
- if ($expirationDate !== null) {
- $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
- $expirationDate->setTime(0, 0, 0);
-
- $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');
- throw new GenericShareException($message, $message, 404);
+ $isEnforced = $this->shareApiLinkDefaultExpireDateEnforced();
+
+ // If $expirationDate is falsy, noExpirationDate is true and expiration not enforced
+ // Then skip expiration date validation as null is accepted
+ if(!($share->getNoExpirationDate() && !$isEnforced)) {
+ if ($expirationDate !== null) {
+ $expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
+ $expirationDate->setTime(0, 0, 0);
+
+ $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');
+ throw new GenericShareException($message, $message, 404);
+ }
}
- }
-
- // If expiredate is empty set a default one if there is a default
- $fullId = null;
- try {
- $fullId = $share->getFullId();
- } catch (\UnexpectedValueException $e) {
- // This is a new share
- }
- if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
- $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
- $expirationDate->setTime(0, 0, 0);
-
- $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
- if ($days > $this->shareApiLinkDefaultExpireDays()) {
- $days = $this->shareApiLinkDefaultExpireDays();
+ // If expiredate is empty set a default one if there is a default
+ $fullId = null;
+ try {
+ $fullId = $share->getFullId();
+ } catch (\UnexpectedValueException $e) {
+ // This is a new share
+ }
+
+ if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
+ $expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
+ $expirationDate->setTime(0, 0, 0);
+
+ $days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
+ if ($days > $this->shareApiLinkDefaultExpireDays()) {
+ $days = $this->shareApiLinkDefaultExpireDays();
+ }
+ $expirationDate->add(new \DateInterval('P' . $days . 'D'));
}
- $expirationDate->add(new \DateInterval('P' . $days . 'D'));
- }
-
- // If we enforce the expiration date check that is does not exceed
- if ($this->shareApiLinkDefaultExpireDateEnforced()) {
- if ($expirationDate === null) {
- throw new \InvalidArgumentException('Expiration date is enforced');
+
+ // If we enforce the expiration date check that is does not exceed
+ if ($isEnforced) {
+ if (empty($expirationDate)) {
+ throw new \InvalidArgumentException('Expiration date is enforced');
+ }
+
+ $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
+ $date->setTime(0, 0, 0);
+ $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
+ if ($date < $expirationDate) {
+ $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays());
+ throw new GenericShareException($message, $message, 404);
+ }
}
- $date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
- $date->setTime(0, 0, 0);
- $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
- if ($date < $expirationDate) {
- $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays());
- throw new GenericShareException($message, $message, 404);
- }
}
$accepted = true;
diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php
index e1d8818216b..0bc85712647 100644
--- a/lib/private/Share20/Share.php
+++ b/lib/private/Share20/Share.php
@@ -90,13 +90,13 @@ class Share implements IShare {
private $mailSend;
/** @var string */
private $label = '';
-
/** @var ICacheEntry|null */
private $nodeCacheEntry;
-
/** @var bool */
private $hideDownload = false;
+ private bool $noExpirationDate = false;
+
public function __construct(
private IRootFolder $rootFolder,
private IUserManager $userManager,
@@ -424,6 +424,21 @@ class Share implements IShare {
/**
* @inheritdoc
*/
+ public function setNoExpirationDate(bool $noExpirationDate) {
+ $this->noExpirationDate = $noExpirationDate;
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getNoExpirationDate(): bool {
+ return $this->noExpirationDate;
+ }
+
+ /**
+ * @inheritdoc
+ */
public function isExpired() {
return $this->getExpirationDate() !== null &&
$this->getExpirationDate() <= new \DateTime();
diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php
index 0961631ea92..0f4f9561eeb 100644
--- a/lib/public/Share/IShare.php
+++ b/lib/public/Share/IShare.php
@@ -385,21 +385,39 @@ interface IShare {
/**
* Set the expiration date
*
- * @param null|\DateTime $expireDate
+ * @param \DateTime|null $expireDate
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
- public function setExpirationDate($expireDate);
+ public function setExpirationDate(\DateTime|null $expireDate);
/**
* Get the expiration date
*
- * @return null|\DateTime
+ * @return \DateTime|null
* @since 9.0.0
*/
public function getExpirationDate();
/**
+ * Set overwrite flag for falsy expiry date vavlues
+ *
+ * @param bool $noExpirationDate
+ * @return \OCP\Share\IShare The modified object
+ * @since 30.0.0
+ */
+ public function setNoExpirationDate(bool $noExpirationDate);
+
+
+ /**
+ * Get value of overwrite falsy expiry date flag
+ *
+ * @return bool
+ * @since 30.0.0
+ */
+ public function getNoExpirationDate();
+
+ /**
* Is the share expired ?
*
* @return boolean