aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2024-12-16 15:53:12 -0800
committerChristopher Ng <chrng8@gmail.com>2025-01-15 15:49:19 -0800
commitf92875cf6acc698c81c9b1b6959536d3f80d28de (patch)
treec496e27a15db41dec41bdb6fe559bebebea50799
parent6ccd90b2a340b30c4dd5639da639ea7f0a318227 (diff)
downloadnextcloud-server-f92875cf6acc698c81c9b1b6959536d3f80d28de.tar.gz
nextcloud-server-f92875cf6acc698c81c9b1b6959536d3f80d28de.zip
feat(sharing): Allow updating share token
Signed-off-by: Christopher Ng <chrng8@gmail.com>
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php22
1 files changed, 21 insertions, 1 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index ff20a0acf3c..57022f7ea1c 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -1164,6 +1164,7 @@ class ShareAPIController extends OCSController {
* Considering the share already exists, no mail will be send after the share is updated.
* You will have to use the sendMail action to send the mail.
* @param string|null $shareWith New recipient for email shares
+ * @param string|null $token New token
* @return DataResponse<Http::STATUS_OK, Files_SharingShare, array{}>
* @throws OCSBadRequestException Share could not be updated because the requested changes are invalid
* @throws OCSForbiddenException Missing permissions to update the share
@@ -1184,6 +1185,7 @@ class ShareAPIController extends OCSController {
?string $hideDownload = null,
?string $attributes = null,
?string $sendMail = null,
+ ?string $token = null,
): DataResponse {
try {
$share = $this->getShareById($id);
@@ -1211,7 +1213,8 @@ class ShareAPIController extends OCSController {
$label === null &&
$hideDownload === null &&
$attributes === null &&
- $sendMail === null
+ $sendMail === null &&
+ $token === null
) {
throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given'));
}
@@ -1324,6 +1327,13 @@ class ShareAPIController extends OCSController {
} elseif ($sendPasswordByTalk !== null) {
$share->setSendPasswordByTalk(false);
}
+
+ if ($token !== null) {
+ if (!$this->validateToken($token)) {
+ throw new OCSBadRequestException($this->l->t('Tokens must contain at least 1 character and may only contain letters, numbers, or a hyphen'));
+ }
+ $share->setToken($token);
+ }
}
// NOT A LINK SHARE
@@ -1357,6 +1367,16 @@ class ShareAPIController extends OCSController {
return new DataResponse($this->formatShare($share));
}
+ private function validateToken(string $token): bool {
+ if (mb_strlen($token) === 0) {
+ return false;
+ }
+ if (!preg_match('/^[a-z0-9-]+$/i', $token)) {
+ return false;
+ }
+ return true;
+ }
+
/**
* Get all shares that are still pending
*