mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
refactor(recent-files): move recent limit to app-scoped config
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
parent
48ce8c3fa1
commit
9b605de474
4 changed files with 20 additions and 34 deletions
|
|
@ -22,6 +22,7 @@ use OCP\Config\ValueType;
|
|||
*/
|
||||
class ConfigLexicon implements ILexicon {
|
||||
public const OVERWRITES_HOME_FOLDERS = 'overwrites_home_folders';
|
||||
public const RECENT_LIMIT = 'recent_limit';
|
||||
|
||||
public function getStrictness(): Strictness {
|
||||
return Strictness::IGNORE;
|
||||
|
|
@ -37,6 +38,13 @@ class ConfigLexicon implements ILexicon {
|
|||
lazy: false,
|
||||
note: 'It will be populated with app IDs of mount providers that overwrite home folders. Currently, only files_external and groupfolders.',
|
||||
),
|
||||
new Entry(
|
||||
self::RECENT_LIMIT,
|
||||
ValueType::INT,
|
||||
defaultRaw: 100,
|
||||
definition: 'Maximum number of files to display on recent files view',
|
||||
lazy: false,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace OCA\Files\Controller;
|
|||
use OC\Files\FilenameValidator;
|
||||
use OC\Files\Filesystem;
|
||||
use OCA\Files\AppInfo\Application;
|
||||
use OCA\Files\ConfigLexicon;
|
||||
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
||||
use OCA\Files\Event\LoadSearchPlugins;
|
||||
use OCA\Files\Event\LoadSidebar;
|
||||
|
|
@ -25,6 +26,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
|
||||
|
|
@ -62,6 +64,7 @@ class ViewController extends Controller {
|
|||
private ViewConfig $viewConfig,
|
||||
private FilenameValidator $filenameValidator,
|
||||
private IRegistry $twoFactorRegistry,
|
||||
private IAppConfig $appConfig,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
|
@ -174,6 +177,7 @@ class ViewController extends Controller {
|
|||
$this->initialState->provideInitialState('storageStats', $storageInfo);
|
||||
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('recent_limit', $this->appConfig->getAppValueInt(ConfigLexicon::RECENT_LIMIT, 100));
|
||||
|
||||
// File sorting user config
|
||||
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
|
||||
|
|
|
|||
|
|
@ -79,13 +79,6 @@ class UserConfig {
|
|||
'default' => true,
|
||||
'allowed' => [true, false],
|
||||
],
|
||||
[
|
||||
// Maximum number of files to display in the recent section
|
||||
'key' => 'recent_files_limit',
|
||||
'default' => 100,
|
||||
'min' => 1,
|
||||
'max' => 100,
|
||||
],
|
||||
];
|
||||
protected ?IUser $user = null;
|
||||
|
||||
|
|
@ -125,7 +118,7 @@ class UserConfig {
|
|||
* Get the default config value for a given key
|
||||
*
|
||||
* @param string $key a valid config key
|
||||
* @return string|bool|int
|
||||
* @return string|bool
|
||||
*/
|
||||
private function getDefaultConfigValue(string $key) {
|
||||
foreach (self::ALLOWED_CONFIGS as $config) {
|
||||
|
|
@ -153,15 +146,7 @@ class UserConfig {
|
|||
throw new \InvalidArgumentException('Unknown config key');
|
||||
}
|
||||
|
||||
$config = $this->getConfigDefinition($key);
|
||||
|
||||
if (isset($config['min'], $config['max'])) {
|
||||
if ((int)$value < $config['min'] || (int)$value > $config['max']) {
|
||||
throw new \InvalidArgumentException('Invalid config value');
|
||||
}
|
||||
} elseif (isset($config['min']) || isset($config['max'])) {
|
||||
throw new \InvalidArgumentException('Invalid config definition: min and max must both be defined');
|
||||
} elseif (!in_array($value, $this->getAllowedConfigValues($key))) {
|
||||
if (!in_array($value, $this->getAllowedConfigValues($key))) {
|
||||
throw new \InvalidArgumentException('Invalid config value');
|
||||
}
|
||||
|
||||
|
|
@ -194,19 +179,4 @@ class UserConfig {
|
|||
|
||||
return array_combine($this->getAllowedConfigKeys(), $userConfigs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config definition for a given key
|
||||
*
|
||||
* @param string $key
|
||||
* @return array
|
||||
*/
|
||||
private function getConfigDefinition(string $key): array {
|
||||
foreach (self::ALLOWED_CONFIGS as $config) {
|
||||
if ($config['key'] === $key) {
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use OCP\App\IAppManager;
|
|||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Authentication\TwoFactorAuth\IRegistry;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
|
|
@ -48,6 +49,7 @@ use Test\TestCase;
|
|||
class ViewControllerTest extends TestCase {
|
||||
private ContainerInterface&MockObject $container;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
private ICacheFactory&MockObject $cacheFactory;
|
||||
private IConfig&MockObject $config;
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
|
|
@ -71,6 +73,7 @@ class ViewControllerTest extends TestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->appManager = $this->createMock(IAppManager::class);
|
||||
$this->appConfig = $this->createMock(IAppConfig::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->initialState = $this->createMock(IInitialState::class);
|
||||
|
|
@ -142,6 +145,7 @@ class ViewControllerTest extends TestCase {
|
|||
$this->viewConfig,
|
||||
$filenameValidator,
|
||||
$this->twoFactorRegistry,
|
||||
$this->appConfig,
|
||||
])
|
||||
->onlyMethods([
|
||||
'getStorageInfo',
|
||||
|
|
@ -298,11 +302,11 @@ class ViewControllerTest extends TestCase {
|
|||
'backup_codes' => true,
|
||||
]);
|
||||
|
||||
$invokedCountProvideInitialState = $this->exactly(9);
|
||||
$invokedCountProvideInitialState = $this->exactly(10);
|
||||
$this->initialState->expects($invokedCountProvideInitialState)
|
||||
->method('provideInitialState')
|
||||
->willReturnCallback(function ($key, $data) use ($invokedCountProvideInitialState): void {
|
||||
if ($invokedCountProvideInitialState->numberOfInvocations() === 9) {
|
||||
if ($invokedCountProvideInitialState->numberOfInvocations() === 10) {
|
||||
$this->assertEquals('isTwoFactorEnabled', $key);
|
||||
$this->assertTrue($data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue