Skip to content

Commit 6bbaebd

Browse files
committed
feat(preset): add lexicon entry for custom share tokens
Signed-off-by: Maxence Lange <[email protected]>
1 parent 0d07542 commit 6bbaebd

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

core/AppInfo/ConfigLexicon.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use NCU\Config\Lexicon\ConfigLexiconEntry;
1212
use NCU\Config\Lexicon\ConfigLexiconStrictness;
1313
use NCU\Config\Lexicon\IConfigLexicon;
14+
use NCU\Config\Lexicon\Preset;
1415
use NCU\Config\ValueType;
1516

1617
/**
@@ -20,6 +21,7 @@
2021
*/
2122
class ConfigLexicon implements IConfigLexicon {
2223
public const SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES = 'shareapi_allow_federation_on_public_shares';
24+
public const SHARE_CUSTOM_TOKEN = 'shareapi_allow_custom_tokens';
2325

2426
public function getStrictness(): ConfigLexiconStrictness {
2527
return ConfigLexiconStrictness::IGNORE;
@@ -30,9 +32,23 @@ public function getAppConfigs(): array {
3032
new ConfigLexiconEntry(
3133
key: self::SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES,
3234
type: ValueType::BOOL,
33-
lazy: true,
3435
defaultRaw: true,
3536
definition: 'adds share permission to public shares to allow adding them to your Nextcloud (federation)',
37+
lazy: true,
38+
),
39+
new ConfigLexiconEntry(
40+
key: self::SHARE_CUSTOM_TOKEN,
41+
type: ValueType::BOOL,
42+
defaultRaw: fn (Preset $p): bool => match ($p) {
43+
Preset::FAMILY, Preset::PRIVATE => true,
44+
default => false,
45+
},
46+
definition: [
47+
'definition' => 'Allow users to set custom share link tokens',
48+
'note' => 'Shares with custom tokens will continue to be accessible after this setting has been disabled',
49+
'warning' => 'Shares with guessable tokens may be accessed easily'
50+
],
51+
lazy: true,
3652
),
3753
];
3854
}

lib/private/Share20/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OC\Share20;
99

10+
use OC\Core\AppInfo\ConfigLexicon;
1011
use OC\Files\Mount\MoveableMount;
1112
use OC\KnownUser\KnownUserService;
1213
use OC\Share20\Exception\ProviderException;
@@ -1937,7 +1938,7 @@ public function ignoreSecondDisplayName(): bool {
19371938
}
19381939

19391940
public function allowCustomTokens(): bool {
1940-
return $this->appConfig->getValueBool('core', 'shareapi_allow_custom_tokens', false);
1941+
return $this->appConfig->getValueBool('core', ConfigLexicon::SHARE_CUSTOM_TOKEN);
19411942
}
19421943

19431944
public function allowViewWithoutDownload(): bool {

lib/unstable/Config/Lexicon/ConfigLexiconEntry.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class ConfigLexiconEntry {
2121
/** @experimental 32.0.0 */
2222
public const RENAME_INVERT_BOOLEAN = 1;
2323

24-
private string $definition = '';
24+
private array|string $definition = '';
2525
private ?string $default = null;
2626

2727
/**
2828
* @param string $key config key, can only contain alphanumerical chars and -._
2929
* @param ValueType $type type of config value
30-
* @param string $definition optional description of config key available when using occ command
30+
* @param array|string $definition optional description of config key available when using occ command
3131
* @param bool $lazy set config value as lazy
3232
* @param int $flags set flags
3333
* @param string|null $rename previous config key to migrate config value from
@@ -41,7 +41,7 @@ public function __construct(
4141
private readonly string $key,
4242
private readonly ValueType $type,
4343
private null|string|int|float|bool|array|Closure $defaultRaw = null,
44-
string $definition = '',
44+
string|array $definition = '',
4545
private readonly bool $lazy = false,
4646
private readonly int $flags = 0,
4747
private readonly bool $deprecated = false,
@@ -183,9 +183,34 @@ public function convertToString(string|int|float|bool|array $entry): string {
183183
* @experimental 31.0.0
184184
*/
185185
public function getDefinition(): string {
186-
return $this->definition;
186+
if (is_string($this->definition)) {
187+
return $this->definition;
188+
}
189+
190+
return (string)($this->definition['definition'] ?? '');
191+
}
192+
193+
/**
194+
* returns eventual note
195+
*
196+
* @return string
197+
* @experimental 32.0.0
198+
*/
199+
public function getNote(): string {
200+
return (string)($this->definition['note'] ?? '');
187201
}
188202

203+
/**
204+
* returns eventual warning
205+
*
206+
* @return string
207+
* @experimental 32.0.0
208+
*/
209+
public function getWarning(): string {
210+
return (string)($this->definition['warning'] ?? '');
211+
}
212+
213+
189214
/**
190215
* returns if config key is set as lazy
191216
*

0 commit comments

Comments
 (0)