fix(share): Set expiration time to end of day (23:59:59)

Shares now expire at the end of the selected day instead of the
beginning, allowing access throughout the entire expiration day.

Also return actual stored time in API response instead of hardcoded
00:00:00 to prevent timezone-related display issues in the UI.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
pull/58128/head
nfebe 7 months ago committed by fenn-cs
parent c25160d7eb
commit 2d20ee2e4e
  1. 2
      apps/files_sharing/lib/Controller/ShareAPIController.php
  2. 12
      lib/private/Share20/Manager.php

@ -236,7 +236,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');
$result['expiration'] = $expiration->format('Y-m-d H:i:s');
}
if ($share->getShareType() === IShare::TYPE_USER) {

@ -302,7 +302,7 @@ class Manager implements IManager {
if (!$share->getNoExpirationDate() || $isEnforced) {
if ($expirationDate !== null) {
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
$expirationDate->setTime(23, 59, 59);
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
@ -321,7 +321,7 @@ class Manager implements IManager {
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
$expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
$expirationDate->setTime(23, 59, 59);
$days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
if ($days > $defaultExpireDays) {
$days = $defaultExpireDays;
@ -336,7 +336,7 @@ class Manager implements IManager {
}
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
$date->setTime(23, 59, 59);
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
if ($date < $expirationDate) {
throw new GenericShareException($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), code: 404);
@ -380,7 +380,7 @@ class Manager implements IManager {
if (!($share->getNoExpirationDate() && !$isEnforced)) {
if ($expirationDate !== null) {
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
$expirationDate->setTime(23, 59, 59);
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
@ -399,7 +399,7 @@ class Manager implements IManager {
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
$expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$expirationDate->setTime(0, 0, 0);
$expirationDate->setTime(23, 59, 59);
$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
if ($days > $this->shareApiLinkDefaultExpireDays()) {
@ -415,7 +415,7 @@ class Manager implements IManager {
}
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
$date->setTime(0, 0, 0);
$date->setTime(23, 59, 59);
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
if ($date < $expirationDate) {
throw new GenericShareException(

Loading…
Cancel
Save