Skip to content

Commit 500a9cb

Browse files
authored
Merge pull request #44485 from nextcloud/44219-share-server-respect-empty-expiry-date
Respect empty `expiryDate` value in server
2 parents b72e4e8 + d41d885 commit 500a9cb

7 files changed

Lines changed: 191 additions & 170 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,8 @@ public function deleteShare(string $id): DataResponse {
549549
* @param string $publicUpload If public uploading is allowed
550550
* @param string $password Password for the share
551551
* @param string|null $sendPasswordByTalk Send the password for the share over Talk
552-
* @param string $expireDate Expiry date of the share using user timezone at 00:00. It means date in UTC timezone will be used.
552+
* @param ?string $expireDate The expiry date of the share in the user's timezone (UTC) at 00:00.
553+
* If $expireDate is not supplied or set to `null`, the system default will be used.
553554
* @param string $note Note for the share
554555
* @param string $label Label for the share (only used in link and email)
555556
* @param string|null $attributes Additional attributes for the share
@@ -571,7 +572,7 @@ public function createShare(
571572
string $publicUpload = 'false',
572573
string $password = '',
573574
?string $sendPasswordByTalk = null,
574-
string $expireDate = '',
575+
?string $expireDate = null,
575576
string $note = '',
576577
string $label = '',
577578
?string $attributes = null
@@ -646,12 +647,18 @@ public function createShare(
646647
}
647648

648649
//Expire date
649-
if ($expireDate !== '') {
650-
try {
651-
$expireDateTime = $this->parseDate($expireDate);
652-
$share->setExpirationDate($expireDateTime);
653-
} catch (\Exception $e) {
654-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
650+
if ($expireDate !== null) {
651+
if ($expireDate !== '') {
652+
try {
653+
$expireDateTime = $this->parseDate($expireDate);
654+
$share->setExpirationDate($expireDateTime);
655+
} catch (\Exception $e) {
656+
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
657+
}
658+
} else {
659+
// Client sent empty string for expire date.
660+
// Set noExpirationDate to true so overwrite is prevented.
661+
$share->setNoExpirationDate(true);
655662
}
656663
}
657664

apps/files_sharing/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,10 +1781,10 @@
17811781
{
17821782
"name": "expireDate",
17831783
"in": "query",
1784-
"description": "Expiry date of the share using user timezone at 00:00. It means date in UTC timezone will be used.",
1784+
"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.",
17851785
"schema": {
17861786
"type": "string",
1787-
"default": ""
1787+
"nullable": true
17881788
}
17891789
},
17901790
{

build/integration/features/bootstrap/Sharing.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function asCreatingAShareWith($user, $body) {
5454
$fd = $body->getRowsHash();
5555
if (array_key_exists('expireDate', $fd)) {
5656
$dateModification = $fd['expireDate'];
57-
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
57+
if (!empty($dateModification)) {
58+
$fd['expireDate'] = date('Y-m-d', strtotime($dateModification));
59+
}
5860
}
5961
$options['form_params'] = $fd;
6062
}
@@ -301,7 +303,9 @@ public function createShare($user,
301303
public function isFieldInResponse($field, $contentExpected) {
302304
$data = simplexml_load_string($this->response->getBody())->data[0];
303305
if ((string)$field == 'expiration') {
304-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
306+
if(!empty($contentExpected)) {
307+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00";
308+
}
305309
}
306310
if (count($data->element) > 0) {
307311
foreach ($data as $element) {

build/integration/sharing_features/sharing-v1.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ Feature: sharing
229229
| url | AN_URL |
230230
| mimetype | httpd/unix-directory |
231231

232+
Scenario: Creating a new share with expiration date removed, when default expiration is set
233+
Given user "user0" exists
234+
And user "user1" exists
235+
And parameter "shareapi_default_expire_date" of app "core" is set to "yes"
236+
And As an "user0"
237+
When creating a share with
238+
| path | welcome.txt |
239+
| shareWith | user1 |
240+
| shareType | 0 |
241+
| expireDate | |
242+
Then the OCS status code should be "100"
243+
And the HTTP status code should be "200"
244+
And Getting info of last share
245+
Then the OCS status code should be "100"
246+
And the HTTP status code should be "200"
247+
And Share fields of last share match with
248+
| expiration ||
249+
232250
Scenario: Creating a new public share, updating its password and getting its info
233251
Given user "user0" exists
234252
And As an "user0"

0 commit comments

Comments
 (0)