Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Respect empty expiryDate value in server #45604

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ public function deleteShare(string $id): DataResponse {
* @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
Expand All @@ -571,8 +572,8 @@ public function createShare(
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
Expand Down Expand Up @@ -647,12 +648,18 @@ public function createShare(
}

//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);
}
}

Expand Down Expand Up @@ -769,19 +776,19 @@ public function createShare(
$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()]));
}
Expand Down
4 changes: 2 additions & 2 deletions apps/files_sharing/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
{
Expand Down
2 changes: 0 additions & 2 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -86,7 +85,6 @@ private function getResults(array $map) {
$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),
Expand Down
8 changes: 6 additions & 2 deletions build/integration/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public function asCreatingAShareWith($user, $body) {
$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;
}
Expand Down Expand Up @@ -328,7 +330,9 @@ public function createShare($user,
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) {
Expand Down
18 changes: 18 additions & 0 deletions build/integration/sharing_features/sharing-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 5 additions & 27 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
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;
Expand Down Expand Up @@ -259,6 +258,7 @@
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;
Expand Down Expand Up @@ -1241,36 +1241,14 @@ public function __construct($webRoot, \OC\Config $config) {
/** @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);

Expand Down
Loading
Loading