From 3ceffe9f5beb23f7049203e08efdf8fa8ecd1b35 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 29 Jul 2025 08:12:54 -0100 Subject: [PATCH] feat(preset): add lexicon entry for custom share token Signed-off-by: Maxence Lange --- core/AppInfo/ConfigLexicon.php | 13 +++++++++++++ lib/private/Share20/Manager.php | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/AppInfo/ConfigLexicon.php b/core/AppInfo/ConfigLexicon.php index 5dad229267d..865a0a4728f 100644 --- a/core/AppInfo/ConfigLexicon.php +++ b/core/AppInfo/ConfigLexicon.php @@ -10,6 +10,7 @@ namespace OC\Core\AppInfo; use OCP\Config\Lexicon\Entry; use OCP\Config\Lexicon\ILexicon; +use OCP\Config\Lexicon\Preset; use OCP\Config\Lexicon\Strictness; use OCP\Config\ValueType; @@ -20,6 +21,7 @@ use OCP\Config\ValueType; */ class ConfigLexicon implements ILexicon { public const SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES = 'shareapi_allow_federation_on_public_shares'; + public const SHARE_CUSTOM_TOKEN = 'shareapi_allow_custom_tokens'; public function getStrictness(): Strictness { return Strictness::IGNORE; @@ -34,6 +36,17 @@ class ConfigLexicon implements ILexicon { definition: 'adds share permission to public shares to allow adding them to your Nextcloud (federation)', lazy: true, ), + new Entry( + key: self::SHARE_CUSTOM_TOKEN, + type: ValueType::BOOL, + defaultRaw: fn (Preset $p): bool => match ($p) { + Preset::FAMILY, Preset::PRIVATE => true, + default => false, + }, + definition: 'Allow users to set custom share link tokens', + lazy: true, + note: 'Shares with guessable tokens may be accessed easily. Shares with custom tokens will continue to be accessible after this setting has been disabled.', + ), ]; } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 9bfa810b108..2e538b6c33a 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -7,6 +7,7 @@ */ namespace OC\Share20; +use OC\Core\AppInfo\ConfigLexicon; use OC\Files\Mount\MoveableMount; use OC\KnownUser\KnownUserService; use OC\Share20\Exception\ProviderException; @@ -1939,7 +1940,7 @@ class Manager implements IManager { } public function allowCustomTokens(): bool { - return $this->appConfig->getValueBool('core', 'shareapi_allow_custom_tokens', false); + return $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_CUSTOM_TOKEN); } public function allowViewWithoutDownload(): bool {