refactor(settings): use ConfigLexicon for user list preferences

Signed-off-by: Peter Ringelmann <4850521+Pringels@users.noreply.github.com>
This commit is contained in:
Peter Ringelmann 2025-12-17 18:39:22 +01:00
parent e7aaaff69d
commit 11eaa0479f
5 changed files with 66 additions and 18 deletions

View file

@ -8,7 +8,6 @@ declare(strict_types=1);
*/
namespace OCA\Settings;
use OCP\Config\IUserConfig;
use OCP\Config\Lexicon\Entry;
use OCP\Config\Lexicon\ILexicon;
use OCP\Config\Lexicon\Strictness;
@ -20,7 +19,12 @@ use OCP\Config\ValueType;
* Please Add & Manage your Config Keys in that file and keep the Lexicon up to date!
*/
class ConfigLexicon implements ILexicon {
public const USER_SETTINGS_EMAIL = 'email';
public const USER_LIST_SHOW_STORAGE_PATH = 'user_list_show_storage_path';
public const USER_LIST_SHOW_USER_BACKEND = 'user_list_show_user_backend';
public const USER_LIST_SHOW_LAST_LOGIN = 'user_list_show_last_login';
public const USER_LIST_SHOW_FIRST_LOGIN = 'user_list_show_first_login';
public const USER_LIST_SHOW_NEW_USER_FORM = 'user_list_show_new_user_form';
public const USER_LIST_SHOW_LANGUAGES = 'user_list_show_languages';
public function getStrictness(): Strictness {
return Strictness::IGNORE;
@ -32,7 +36,48 @@ class ConfigLexicon implements ILexicon {
public function getUserConfigs(): array {
return [
new Entry(key: self::USER_SETTINGS_EMAIL, type: ValueType::STRING, defaultRaw: '', definition: 'account mail address', flags: IUserConfig::FLAG_INDEXED),
new Entry(
key: self::USER_LIST_SHOW_STORAGE_PATH,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show storage path column in user list',
lazy: true,
),
new Entry(
key: self::USER_LIST_SHOW_USER_BACKEND,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show user account backend column in user list',
lazy: true,
),
new Entry(
key: self::USER_LIST_SHOW_LAST_LOGIN,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show last login date column in user list',
lazy: true,
),
new Entry(
key: self::USER_LIST_SHOW_FIRST_LOGIN,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show first login date column in user list',
lazy: true,
),
new Entry(
key: self::USER_LIST_SHOW_NEW_USER_FORM,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show new user form in user list',
lazy: true,
),
new Entry(
key: self::USER_LIST_SHOW_LANGUAGES,
type: ValueType::BOOL,
defaultRaw: false,
definition: 'Show languages in user list',
lazy: true,
),
];
}
}

View file

@ -19,6 +19,7 @@ use OC\KnownUser\KnownUserService;
use OC\Security\IdentityProof\Manager;
use OC\User\Manager as UserManager;
use OCA\Settings\BackgroundJobs\VerifyUserData;
use OCA\Settings\ConfigLexicon;
use OCA\Settings\Events\BeforeTemplateRenderedEvent;
use OCA\Settings\Settings\Admin\Users;
use OCA\User_LDAP\User_Proxy;
@ -62,12 +63,12 @@ class UsersController extends Controller {
private const COUNT_LIMIT_FOR_SUBADMINS = 999;
public const ALLOWED_USER_PREFERENCES = [
'user_list_show_storage_path',
'user_list_show_user_backend',
'user_list_show_first_login',
'user_list_show_last_login',
'user_list_show_new_user_form',
'user_list_show_languages',
ConfigLexicon::USER_LIST_SHOW_STORAGE_PATH,
ConfigLexicon::USER_LIST_SHOW_USER_BACKEND,
ConfigLexicon::USER_LIST_SHOW_FIRST_LOGIN,
ConfigLexicon::USER_LIST_SHOW_LAST_LOGIN,
ConfigLexicon::USER_LIST_SHOW_NEW_USER_FORM,
ConfigLexicon::USER_LIST_SHOW_LANGUAGES,
];
public function __construct(

View file

@ -14,6 +14,7 @@ use OC\ForbiddenException;
use OC\Group\Manager;
use OC\KnownUser\KnownUserService;
use OC\User\Manager as UserManager;
use OCA\Settings\ConfigLexicon;
use OCA\Settings\Controller\UsersController;
use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
@ -1043,13 +1044,14 @@ class UsersControllerTest extends \Test\TestCase {
public static function dataSetPreference(): array {
return [
['newUser.sendEmail', 'yes', false, true, Http::STATUS_OK],
['newUser.sendEmail', 'no', false, true, Http::STATUS_OK],
['group.sortBy', '1', false, true, Http::STATUS_OK],
['user_list_show_storage_path', 'true', true, false, Http::STATUS_OK],
['user_list_show_user_backend', 'false', true, false, Http::STATUS_OK],
['user_list_show_first_login', 'true', true, false, Http::STATUS_OK],
['user_list_show_last_login', 'true', true, false, Http::STATUS_OK],
['user_list_show_new_user_form', 'true', true, false, Http::STATUS_OK],
['user_list_show_languages', 'true', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_STORAGE_PATH, 'true', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_USER_BACKEND, 'false', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_FIRST_LOGIN, 'true', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_LAST_LOGIN, 'true', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_NEW_USER_FORM, 'true', true, false, Http::STATUS_OK],
[ConfigLexicon::USER_LIST_SHOW_LANGUAGES, 'true', true, false, Http::STATUS_OK],
['invalidKey', 'value', false, false, Http::STATUS_FORBIDDEN],
];
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long