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>
fenn-cs 2 months ago
parent 321900d032
commit 09bf1e137b

@ -549,7 +549,8 @@ class ShareAPIController extends OCSController {
* @param string $publicUpload If public uploading is allowed
* @param string $password Password for the share
* @param string|null $sendPasswordByTalk Send the password for the share over Talk
* @param string $expireDate Expiry date of the share using user timezone at 00:00. It means date in UTC timezone will be used.
* @param ?string $expireDate The expiry date of the share in the user's timezone (UTC) at 00:00.
* If $expireDate is not supplied or set to `null`, the system default will be used.
* @param string $note Note for the share
* @param string $label Label for the share (only used in link and email)
* @param string|null $attributes Additional attributes for the share
@ -571,7 +572,7 @@ class ShareAPIController extends OCSController {
string $publicUpload = 'false',
string $password = '',
?string $sendPasswordByTalk = null,
string $expireDate = '',
?string $expireDate = null,
string $note = '',
string $label = '',
?string $attributes = null
@ -646,12 +647,17 @@ class ShareAPIController extends OCSController {
}
//Expire date
if ($expireDate !== '') {
try {
$expireDateTime = $this->parseDate($expireDate);
$share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
if ($expireDate !== null) {
if ($expireDate !== '') {
try {
$expireDateTime = $this->parseDate($expireDate);
$share->setExpirationDate($expireDateTime);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
} else {
// Client sent empty string for expire date. Do not overwrite.
$share->setNoExpirationDate(false);
}
}

@ -1781,10 +1781,10 @@
{
"name": "expireDate",
"in": "query",
"description": "Expiry date of the share using user timezone at 00:00. It means date in UTC timezone will be used.",
"description": "The expiry date of the share in the user's timezone (UTC) at 00:00. If $expireDate is not supplied or set to `null`, the system default will be used.",
"schema": {
"type": "string",
"default": ""
"nullable": true
}
},
{

@ -389,7 +389,25 @@ class Manager implements IManager {
$expirationDate = $share->getExpirationDate();
if ($expirationDate !== null) {
if ($isRemote) {
$defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
$defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
$configProp = 'remote_defaultExpDays';
$isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced();
} else {
$defaultExpireDate = $this->shareApiInternalDefaultExpireDate();
$defaultExpireDays = $this->shareApiInternalDefaultExpireDays();
$configProp = 'internal_defaultExpDays';
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
}
// If $expirationDate is falsy, overwrite flag is false, no expiration is set
if(empty($expirationDate) && !$share->getNoExpirationDate() && !$isEnforced) {
$share->setExpirationDate(null);
return $share;
}
if ($expirationDate != null) {
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
@ -409,17 +427,6 @@ class Manager implements IManager {
// This is a new share
}
if ($isRemote) {
$defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
$defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
$configProp = 'remote_defaultExpDays';
$isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced();
} else {
$defaultExpireDate = $this->shareApiInternalDefaultExpireDate();
$defaultExpireDays = $this->shareApiInternalDefaultExpireDays();
$configProp = 'internal_defaultExpDays';
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
}
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
$expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
@ -432,7 +439,7 @@ class Manager implements IManager {
// If we enforce the expiration date check that is does not exceed
if ($isEnforced) {
if ($expirationDate === null) {
if (empty($expirationDate)) {
throw new \InvalidArgumentException('Expiration date is enforced');
}
@ -474,6 +481,13 @@ class Manager implements IManager {
*/
protected function validateExpirationDateLink(IShare $share) {
$expirationDate = $share->getExpirationDate();
$isEnforced = $this->shareApiLinkDefaultExpireDateEnforced();
// If $expirationDate is falsy, overwrite flag is false, no expiration is set
if(empty($expirationDate) && !$share->getNoExpirationDate() && !$isEnforced) {
$share->setExpirationDate(null);
return $share;
}
if ($expirationDate !== null) {
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
@ -507,8 +521,8 @@ class Manager implements IManager {
}
// If we enforce the expiration date check that is does not exceed
if ($this->shareApiLinkDefaultExpireDateEnforced()) {
if ($expirationDate === null) {
if ($isEnforced) {
if (empty($expirationDate)) {
throw new \InvalidArgumentException('Expiration date is enforced');
}

@ -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,
@ -421,6 +421,21 @@ class Share implements IShare {
return $this->expireDate;
}
/**
* @inheritdoc
*/
public function setNoExpirationDate(bool $noExpirationDate) {
$this->noExpirationDate = $noExpirationDate;
return $this;
}
/**
* @inheritdoc
*/
public function getNoExpirationDate(): bool {
return $this->noExpirationDate;
}
/**
* @inheritdoc
*/

@ -385,20 +385,38 @@ 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 27.0.0
*/
public function setNoExpirationDate(bool $noExpirationDate);
/**
* Get value of overwrite falsy expiry date flag
*
* @return bool
* @since 27.0.0
*/
public function getNoExpirationDate();
/**
* Is the share expired ?
*

Loading…
Cancel
Save