mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 09:13:19 -04:00
Merge pull request #45604 from nextcloud/backport/45483/stable28
[stable28] Respect empty `expiryDate` value in server
This commit is contained in:
commit
22a2483362
10 changed files with 221 additions and 381 deletions
|
|
@ -550,7 +550,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,8 +572,8 @@ class ShareAPIController extends OCSController {
|
|||
string $shareWith = null,
|
||||
string $publicUpload = 'false',
|
||||
string $password = '',
|
||||
string $sendPasswordByTalk = null,
|
||||
string $expireDate = '',
|
||||
?string $sendPasswordByTalk = null,
|
||||
?string $expireDate = null,
|
||||
string $note = '',
|
||||
string $label = '',
|
||||
string $attributes = null
|
||||
|
|
@ -647,12 +648,18 @@ 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.
|
||||
// Set noExpirationDate to true so overwrite is prevented.
|
||||
$share->setNoExpirationDate(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -769,19 +776,19 @@ class ShareAPIController extends OCSController {
|
|||
$share->setPermissions($permissions);
|
||||
} elseif ($shareType === IShare::TYPE_ROOM) {
|
||||
try {
|
||||
$this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
|
||||
$this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate ?? '');
|
||||
} catch (QueryException $e) {
|
||||
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$node->getPath()]));
|
||||
}
|
||||
} elseif ($shareType === IShare::TYPE_DECK) {
|
||||
try {
|
||||
$this->getDeckShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
|
||||
$this->getDeckShareHelper()->createShare($share, $shareWith, $permissions, $expireDate ?? '');
|
||||
} catch (QueryException $e) {
|
||||
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$node->getPath()]));
|
||||
}
|
||||
} elseif ($shareType === IShare::TYPE_SCIENCEMESH) {
|
||||
try {
|
||||
$this->getSciencemeshShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
|
||||
$this->getSciencemeshShareHelper()->createShare($share, $shareWith, $permissions, $expireDate ?? '');
|
||||
} catch (QueryException $e) {
|
||||
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support ScienceMesh shares', [$node->getPath()]));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1755,10 +1755,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 at 00:00. If $expireDate is not supplied or set to `null`, the system default will be used.",
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"default": ""
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ use OCP\Files\Mount\IMountManager;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDateTimeZone;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
|
@ -86,7 +85,6 @@ class CapabilitiesTest extends \Test\TestCase {
|
|||
$this->createMock(IHasher::class),
|
||||
$this->createMock(IMountManager::class),
|
||||
$this->createMock(IGroupManager::class),
|
||||
$this->createMock(IL10N::class),
|
||||
$this->createMock(IFactory::class),
|
||||
$this->createMock(IProviderFactory::class),
|
||||
$this->createMock(IUserManager::class),
|
||||
|
|
|
|||
|
|
@ -81,7 +81,9 @@ trait Sharing {
|
|||
$fd = $body->getRowsHash();
|
||||
if (array_key_exists('expireDate', $fd)) {
|
||||
$dateModification = $fd['expireDate'];
|
||||
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
|
||||
if (!empty($dateModification)) {
|
||||
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
|
||||
}
|
||||
}
|
||||
$options['form_params'] = $fd;
|
||||
}
|
||||
|
|
@ -328,7 +330,9 @@ trait Sharing {
|
|||
public function isFieldInResponse($field, $contentExpected) {
|
||||
$data = simplexml_load_string($this->response->getBody())->data[0];
|
||||
if ((string)$field == 'expiration') {
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
|
||||
if (!empty($contentExpected)) {
|
||||
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
|
||||
}
|
||||
}
|
||||
if (count($data->element) > 0) {
|
||||
foreach ($data as $element) {
|
||||
|
|
|
|||
|
|
@ -229,6 +229,24 @@ Feature: sharing
|
|||
| url | AN_URL |
|
||||
| mimetype | httpd/unix-directory |
|
||||
|
||||
Scenario: Creating a new share with expiration date removed, when default expiration is set
|
||||
Given user "user0" exists
|
||||
And user "user1" exists
|
||||
And parameter "shareapi_default_expire_date" of app "core" is set to "yes"
|
||||
And As an "user0"
|
||||
When creating a share with
|
||||
| path | welcome.txt |
|
||||
| shareWith | user1 |
|
||||
| shareType | 0 |
|
||||
| expireDate | |
|
||||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
And Getting info of last share
|
||||
Then the OCS status code should be "100"
|
||||
And the HTTP status code should be "200"
|
||||
And Share fields of last share match with
|
||||
| expiration ||
|
||||
|
||||
Scenario: Creating a new public share, updating its password and getting its info
|
||||
Given user "user0" exists
|
||||
And As an "user0"
|
||||
|
|
|
|||
|
|
@ -151,7 +151,6 @@ use OC\Security\VerificationToken\VerificationToken;
|
|||
use OC\Session\CryptoWrapper;
|
||||
use OC\SetupCheck\SetupCheckManager;
|
||||
use OC\Share20\ProviderFactory;
|
||||
use OC\Share20\ShareDisableChecker;
|
||||
use OC\Share20\ShareHelper;
|
||||
use OC\SpeechToText\SpeechToTextManager;
|
||||
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
|
||||
|
|
@ -259,6 +258,7 @@ use OCP\Security\ITrustedDomainHelper;
|
|||
use OCP\Security\RateLimiting\ILimiter;
|
||||
use OCP\Security\VerificationToken\IVerificationToken;
|
||||
use OCP\SetupCheck\ISetupCheckManager;
|
||||
use OCP\Share\IProviderFactory;
|
||||
use OCP\Share\IShareHelper;
|
||||
use OCP\SpeechToText\ISpeechToTextManager;
|
||||
use OCP\SystemTag\ISystemTagManager;
|
||||
|
|
@ -1241,36 +1241,14 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
/** @deprecated 19.0.0 */
|
||||
$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
|
||||
|
||||
$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
|
||||
$this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
|
||||
$config = $c->get(\OCP\IConfig::class);
|
||||
$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
|
||||
/** @var \OCP\Share\IProviderFactory $factory */
|
||||
$factory = new $factoryClass($this);
|
||||
|
||||
$manager = new \OC\Share20\Manager(
|
||||
$c->get(LoggerInterface::class),
|
||||
$c->get(\OCP\IConfig::class),
|
||||
$c->get(ISecureRandom::class),
|
||||
$c->get(IHasher::class),
|
||||
$c->get(IMountManager::class),
|
||||
$c->get(IGroupManager::class),
|
||||
$c->getL10N('lib'),
|
||||
$c->get(IFactory::class),
|
||||
$factory,
|
||||
$c->get(IUserManager::class),
|
||||
$c->get(IRootFolder::class),
|
||||
$c->get(IMailer::class),
|
||||
$c->get(IURLGenerator::class),
|
||||
$c->get('ThemingDefaults'),
|
||||
$c->get(IEventDispatcher::class),
|
||||
$c->get(IUserSession::class),
|
||||
$c->get(KnownUserService::class),
|
||||
$c->get(ShareDisableChecker::class),
|
||||
$c->get(IDateTimeZone::class),
|
||||
);
|
||||
|
||||
return $manager;
|
||||
return new $factoryClass($this);
|
||||
});
|
||||
|
||||
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
|
||||
/** @deprecated 19.0.0 */
|
||||
$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -84,87 +84,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|null $l;
|
||||
private LegacyHooks $legacyHooks;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
IConfig $config,
|
||||
ISecureRandom $secureRandom,
|
||||
IHasher $hasher,
|
||||
IMountManager $mountManager,
|
||||
IGroupManager $groupManager,
|
||||
IL10N $l,
|
||||
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 = $l;
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -349,26 +296,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();
|
||||
|
|
@ -380,28 +307,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;
|
||||
}
|
||||
$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 $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);
|
||||
}
|
||||
}
|
||||
|
||||
$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 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 && $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,51 +386,57 @@ class Manager implements IManager {
|
|||
*/
|
||||
protected function validateExpirationDateLink(IShare $share) {
|
||||
$expirationDate = $share->getExpirationDate();
|
||||
$isEnforced = $this->shareApiLinkDefaultExpireDateEnforced();
|
||||
|
||||
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();
|
||||
}
|
||||
$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 $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);
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
// 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'));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$accepted = true;
|
||||
|
|
|
|||
|
|
@ -99,10 +99,11 @@ class Share implements IShare {
|
|||
|
||||
/** @var ICacheEntry|null */
|
||||
private $nodeCacheEntry;
|
||||
|
||||
/** @var bool */
|
||||
private $hideDownload = false;
|
||||
|
||||
private bool $noExpirationDate = false;
|
||||
|
||||
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userManager = $userManager;
|
||||
|
|
@ -421,6 +422,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 28.0.7
|
||||
*/
|
||||
public function setNoExpirationDate(bool $noExpirationDate);
|
||||
|
||||
|
||||
/**
|
||||
* Get value of overwrite falsy expiry date flag
|
||||
*
|
||||
* @return bool
|
||||
* @since 28.0.7
|
||||
*/
|
||||
public function getNoExpirationDate();
|
||||
|
||||
/**
|
||||
* Is the share expired ?
|
||||
*
|
||||
|
|
|
|||
|
|
@ -151,19 +151,27 @@ class ManagerTest extends \Test\TestCase {
|
|||
->willReturnCallback(function ($singular, $plural, $count, $parameters = []) {
|
||||
return vsprintf(str_replace('%n', $count, ($count === 1) ? $singular : $plural), $parameters);
|
||||
});
|
||||
$this->l10nFactory->method('get')->willReturn($this->l);
|
||||
|
||||
$this->factory = new DummyFactory(\OC::$server);
|
||||
|
||||
$this->manager = new Manager(
|
||||
$this->manager = $this->createManager($this->factory);
|
||||
|
||||
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
|
||||
$this->defaultProvider->method('identifier')->willReturn('default');
|
||||
$this->factory->setProvider($this->defaultProvider);
|
||||
}
|
||||
|
||||
private function createManager(IProviderFactory $factory): Manager {
|
||||
return new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$this->factory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
|
|
@ -175,10 +183,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
|
||||
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
|
||||
$this->defaultProvider->method('identifier')->willReturn('default');
|
||||
$this->factory->setProvider($this->defaultProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +197,6 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$this->factory,
|
||||
$this->userManager,
|
||||
|
|
@ -2802,27 +2805,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$factory = $this->createMock(IProviderFactory::class);
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
||||
|
|
@ -2851,27 +2834,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$factory = $this->createMock(IProviderFactory::class);
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
||||
|
|
@ -2907,27 +2870,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
$factory = $this->createMock(IProviderFactory::class);
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$share = $this->createMock(IShare::class);
|
||||
|
||||
|
|
@ -4308,27 +4251,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
throw new Exception\ProviderException();
|
||||
});
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
$this->assertSame($expected,
|
||||
$manager->shareProviderExists($shareType)
|
||||
);
|
||||
|
|
@ -4344,27 +4267,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testGetSharesInFolder() {
|
||||
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
$extraProvider = $this->createMock(IShareProvider::class);
|
||||
|
|
@ -4411,27 +4314,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testGetAccessList() {
|
||||
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
$extraProvider = $this->createMock(IShareProvider::class);
|
||||
|
|
@ -4530,27 +4413,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testGetAccessListWithCurrentAccess() {
|
||||
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
$extraProvider = $this->createMock(IShareProvider::class);
|
||||
|
|
@ -4658,27 +4521,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testGetAllShares() {
|
||||
$factory = new DummyFactory2($this->createMock(IServerContainer::class));
|
||||
|
||||
$manager = new Manager(
|
||||
$this->logger,
|
||||
$this->config,
|
||||
$this->secureRandom,
|
||||
$this->hasher,
|
||||
$this->mountManager,
|
||||
$this->groupManager,
|
||||
$this->l,
|
||||
$this->l10nFactory,
|
||||
$factory,
|
||||
$this->userManager,
|
||||
$this->rootFolder,
|
||||
$this->mailer,
|
||||
$this->urlGenerator,
|
||||
$this->defaults,
|
||||
$this->dispatcher,
|
||||
$this->userSession,
|
||||
$this->knownUserService,
|
||||
$this->shareDisabledChecker,
|
||||
$this->dateTimeZone,
|
||||
);
|
||||
$manager = $this->createManager($factory);
|
||||
|
||||
$factory->setProvider($this->defaultProvider);
|
||||
$extraProvider = $this->createMock(IShareProvider::class);
|
||||
|
|
|
|||
Loading…
Reference in a new issue