Skip to content

Commit ecddfa9

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

File tree

4 files changed

+73
-8
lines changed

4 files changed

+73
-8
lines changed

core/AppInfo/ConfigLexicon.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
class ConfigLexicon implements ILexicon {
2222
public const SHAREAPI_ALLOW_FEDERATION_ON_PUBLIC_SHARES = 'shareapi_allow_federation_on_public_shares';
23+
public const SHARE_CUSTOM_TOKEN = 'shareapi_allow_custom_tokens';
2324

2425
public function getStrictness(): Strictness {
2526
return Strictness::IGNORE;
@@ -34,6 +35,20 @@ public function getAppConfigs(): array {
3435
definition: 'adds share permission to public shares to allow adding them to your Nextcloud (federation)',
3536
lazy: true,
3637
),
38+
new Entry(
39+
key: self::SHARE_CUSTOM_TOKEN,
40+
type: ValueType::BOOL,
41+
defaultRaw: fn (Preset $p): bool => match ($p) {
42+
Preset::FAMILY, Preset::PRIVATE => true,
43+
default => false,
44+
},
45+
definition: [
46+
'definition' => 'Allow users to set custom share link tokens',
47+
'note' => 'Shares with custom tokens will continue to be accessible after this setting has been disabled',
48+
'warning' => 'Shares with guessable tokens may be accessed easily'
49+
],
50+
lazy: true,
51+
),
3752
];
3853
}
3954

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/public/Config/Lexicon/Entry.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Entry {
2121
/** @since 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
/**
@@ -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,7 +183,31 @@ public function convertToString(string|int|float|bool|array $entry): string {
183183
* @since 32.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+
* @since 32.0.0
198+
*/
199+
public function getNote(): string {
200+
return (string)($this->definition['note'] ?? '');
201+
}
202+
203+
/**
204+
* returns eventual warning
205+
*
206+
* @return string
207+
* @since 32.0.0
208+
*/
209+
public function getWarning(): string {
210+
return (string)($this->definition['warning'] ?? '');
187211
}
188212

189213
/**

lib/unstable/Config/Lexicon/ConfigLexiconEntry.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class ConfigLexiconEntry {
2828
*/
2929
public const RENAME_INVERT_BOOLEAN = 1;
3030

31-
private string $definition = '';
31+
private array|string $definition = '';
3232
private ?string $default = null;
3333

3434
/**
3535
* @param string $key config key, can only contain alphanumerical chars and -._
3636
* @param ValueType $type type of config value
37-
* @param string $definition optional description of config key available when using occ command
37+
* @param array|string $definition optional description of config key available when using occ command
3838
* @param bool $lazy set config value as lazy
3939
* @param int $flags set flags
4040
* @param string|null $rename previous config key to migrate config value from
@@ -50,7 +50,7 @@ public function __construct(
5050
private readonly string $key,
5151
private readonly ValueType $type,
5252
private null|string|int|float|bool|array|Closure $defaultRaw = null,
53-
string $definition = '',
53+
string|array $definition = '',
5454
private readonly bool $lazy = false,
5555
private readonly int $flags = 0,
5656
private readonly bool $deprecated = false,
@@ -218,9 +218,34 @@ public function convertToString(string|int|float|bool|array $entry): string {
218218
* @see \OCP\Config\Lexicon\Entry
219219
*/
220220
public function getDefinition(): string {
221-
return $this->definition;
221+
if (is_string($this->definition)) {
222+
return $this->definition;
223+
}
224+
225+
return (string)($this->definition['definition'] ?? '');
226+
}
227+
228+
/**
229+
* returns eventual note
230+
*
231+
* @return string
232+
* @experimental 32.0.0
233+
*/
234+
public function getNote(): string {
235+
return (string)($this->definition['note'] ?? '');
222236
}
223237

238+
/**
239+
* returns eventual warning
240+
*
241+
* @return string
242+
* @experimental 32.0.0
243+
*/
244+
public function getWarning(): string {
245+
return (string)($this->definition['warning'] ?? '');
246+
}
247+
248+
224249
/**
225250
* returns if config key is set as lazy
226251
*

0 commit comments

Comments
 (0)