Skip to content

Commit ab134a3

Browse files
authored
Merge pull request #38040 from nextcloud/backport/37958/stable26
[stable26] Mutualize expireDate handling when creating and updating a share
2 parents bb81b11 + 54e5c06 commit ab134a3

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -627,16 +627,6 @@ public function createShare(
627627

628628
$share->setSendPasswordByTalk(true);
629629
}
630-
631-
//Expire date
632-
if ($expireDate !== '') {
633-
try {
634-
$expireDate = $this->parseDate($expireDate);
635-
$share->setExpirationDate($expireDate);
636-
} catch (\Exception $e) {
637-
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
638-
}
639-
}
640630
} elseif ($shareType === IShare::TYPE_REMOTE) {
641631
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
642632
throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$node->getPath(), $shareType]));
@@ -710,6 +700,16 @@ public function createShare(
710700
throw new OCSBadRequestException($this->l->t('Unknown share type'));
711701
}
712702

703+
//Expire date
704+
if ($expireDate !== '') {
705+
try {
706+
$expireDate = $this->parseDate($expireDate);
707+
$share->setExpirationDate($expireDate);
708+
} catch (\Exception $e) {
709+
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
710+
}
711+
}
712+
713713
$share->setShareType($shareType);
714714

715715
if ($note !== '') {
@@ -1216,17 +1216,6 @@ public function updateShare(
12161216
$permissions = $newPermissions;
12171217
}
12181218

1219-
if ($expireDate === '') {
1220-
$share->setExpirationDate(null);
1221-
} elseif ($expireDate !== null) {
1222-
try {
1223-
$expireDate = $this->parseDate($expireDate);
1224-
} catch (\Exception $e) {
1225-
throw new OCSBadRequestException($e->getMessage(), $e);
1226-
}
1227-
$share->setExpirationDate($expireDate);
1228-
}
1229-
12301219
if ($password === '') {
12311220
$share->setPassword(null);
12321221
} elseif ($password !== null) {
@@ -1256,17 +1245,17 @@ public function updateShare(
12561245
if ($permissions !== null) {
12571246
$share->setPermissions($permissions);
12581247
}
1248+
}
12591249

1260-
if ($expireDate === '') {
1261-
$share->setExpirationDate(null);
1262-
} elseif ($expireDate !== null) {
1263-
try {
1264-
$expireDate = $this->parseDate($expireDate);
1265-
} catch (\Exception $e) {
1266-
throw new OCSBadRequestException($e->getMessage(), $e);
1267-
}
1268-
$share->setExpirationDate($expireDate);
1250+
if ($expireDate === '') {
1251+
$share->setExpirationDate(null);
1252+
} elseif ($expireDate !== null) {
1253+
try {
1254+
$expireDate = $this->parseDate($expireDate);
1255+
} catch (\Exception $e) {
1256+
throw new OCSBadRequestException($e->getMessage(), $e);
12691257
}
1258+
$share->setExpirationDate($expireDate);
12701259
}
12711260

12721261
try {

0 commit comments

Comments
 (0)