F. E Noel Nfebe 2 weeks ago committed by GitHub
commit 4dd1d3efb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 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
}
},
{

@ -85,86 +85,34 @@ use Psr\Log\LoggerInterface;
* This class is the communication hub for all sharing related operations.
*/
class Manager implements IManager {
/** @var IProviderFactory */
private $factory;
private LoggerInterface $logger;
/** @var IConfig */
private $config;
/** @var ISecureRandom */
private $secureRandom;
/** @var IHasher */
private $hasher;
/** @var IMountManager */
private $mountManager;
/** @var IGroupManager */
private $groupManager;
/** @var IL10N */
private $l;
/** @var IFactory */
private $l10nFactory;
/** @var IUserManager */
private $userManager;
/** @var IRootFolder */
private $rootFolder;
/** @var LegacyHooks */
private $legacyHooks;
/** @var IMailer */
private $mailer;
/** @var IURLGenerator */
private $urlGenerator;
/** @var \OC_Defaults */
private $defaults;
/** @var IEventDispatcher */
private $dispatcher;
/** @var IUserSession */
private $userSession;
/** @var KnownUserService */
private $knownUserService;
private ShareDisableChecker $shareDisableChecker;
private IDateTimeZone $dateTimeZone;
private IL10N $l;
private LegacyHooks $legacyHooks;
public function __construct(
LoggerInterface $logger,
IConfig $config,
ISecureRandom $secureRandom,
IHasher $hasher,
IMountManager $mountManager,
IGroupManager $groupManager,
IFactory $l10nFactory,
IProviderFactory $factory,
IUserManager $userManager,
IRootFolder $rootFolder,
IMailer $mailer,
IURLGenerator $urlGenerator,
\OC_Defaults $defaults,
IEventDispatcher $dispatcher,
IUserSession $userSession,
KnownUserService $knownUserService,
ShareDisableChecker $shareDisableChecker,
IDateTimeZone $dateTimeZone,
private LoggerInterface $logger,
private IConfig $config,
private ISecureRandom $secureRandom,
private IHasher $hasher,
private IMountManager $mountManager,
private IGroupManager $groupManager,
private IFactory $l10nFactory,
private IProviderFactory $factory,
private IUserManager $userManager,
private IRootFolder $rootFolder,
private IMailer $mailer,
private IURLGenerator $urlGenerator,
private \OC_Defaults $defaults,
private IEventDispatcher $dispatcher,
private IUserSession $userSession,
private KnownUserService $knownUserService,
private ShareDisableChecker $shareDisableChecker,
private IDateTimeZone $dateTimeZone
) {
$this->logger = $logger;
$this->config = $config;
$this->secureRandom = $secureRandom;
$this->hasher = $hasher;
$this->mountManager = $mountManager;
$this->groupManager = $groupManager;
$this->l = $l10nFactory->get('lib');
$this->l10nFactory = $l10nFactory;
$this->factory = $factory;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->l = $this->l10nFactory->get('lib');
// The constructor of LegacyHooks registers the listeners of share events
// do not remove if those are not properly migrated
$this->legacyHooks = new LegacyHooks($dispatcher);
$this->mailer = $mailer;
$this->urlGenerator = $urlGenerator;
$this->defaults = $defaults;
$this->dispatcher = $dispatcher;
$this->userSession = $userSession;
$this->knownUserService = $knownUserService;
$this->shareDisableChecker = $shareDisableChecker;
$this->dateTimeZone = $dateTimeZone;
$this->legacyHooks = new LegacyHooks($this->dispatcher);
}
/**
@ -389,7 +337,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 +375,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 +387,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 +429,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 +469,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