3838use OCP \AppFramework \Http \TemplateResponse ;
3939use OCP \AppFramework \Services \IInitialState ;
4040use OCP \BackgroundJob \IJobList ;
41+ use OCP \Config \IUserConfig ;
4142use OCP \Encryption \IManager ;
4243use OCP \EventDispatcher \IEventDispatcher ;
4344use OCP \Group \ISubAdmin ;
45+ use OCP \IAppConfig ;
4446use OCP \IConfig ;
4547use OCP \IGroup ;
4648use OCP \IGroupManager ;
@@ -59,13 +61,24 @@ class UsersController extends Controller {
5961 /** Limit for counting users for subadmins, to avoid spending too much time */
6062 private const COUNT_LIMIT_FOR_SUBADMINS = 999 ;
6163
64+ public const ALLOWED_USER_PREFERENCES = [
65+ 'user_list_show_storage_path ' ,
66+ 'user_list_show_user_backend ' ,
67+ 'user_list_show_first_login ' ,
68+ 'user_list_show_last_login ' ,
69+ 'user_list_show_new_user_form ' ,
70+ 'user_list_show_languages ' ,
71+ ];
72+
6273 public function __construct (
6374 string $ appName ,
6475 IRequest $ request ,
6576 private UserManager $ userManager ,
6677 private IGroupManager $ groupManager ,
6778 private IUserSession $ userSession ,
6879 private IConfig $ config ,
80+ private IAppConfig $ appConfig ,
81+ private IUserConfig $ userConfig ,
6982 private IL10N $ l10n ,
7083 private IMailer $ mailer ,
7184 private IFactory $ l10nFactory ,
@@ -191,12 +204,12 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
191204 }
192205
193206 /* QUOTAS PRESETS */
194- $ quotaPreset = $ this ->parseQuotaPreset ($ this ->config -> getAppValue ('files ' , 'quota_preset ' , '1 GB, 5 GB, 10 GB ' ));
195- $ allowUnlimitedQuota = $ this ->config -> getAppValue ('files ' , 'allow_unlimited_quota ' , ' 1 ' ) === ' 1 ' ;
207+ $ quotaPreset = $ this ->parseQuotaPreset ($ this ->appConfig -> getValueString ('files ' , 'quota_preset ' , '1 GB, 5 GB, 10 GB ' ));
208+ $ allowUnlimitedQuota = $ this ->appConfig -> getValueBool ('files ' , 'allow_unlimited_quota ' , true ) ;
196209 if (!$ allowUnlimitedQuota && count ($ quotaPreset ) > 0 ) {
197- $ defaultQuota = $ this ->config -> getAppValue ('files ' , 'default_quota ' , $ quotaPreset [0 ]);
210+ $ defaultQuota = $ this ->appConfig -> getValueString ('files ' , 'default_quota ' , $ quotaPreset [0 ]);
198211 } else {
199- $ defaultQuota = $ this ->config -> getAppValue ('files ' , 'default_quota ' , 'none ' );
212+ $ defaultQuota = $ this ->appConfig -> getValueString ('files ' , 'default_quota ' , 'none ' );
200213 }
201214
202215 $ event = new BeforeTemplateRenderedEvent ();
@@ -219,7 +232,7 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
219232 $ serverData ['isDelegatedAdmin ' ] = $ isDelegatedAdmin ;
220233 $ serverData ['sortGroups ' ] = $ forceSortGroupByName
221234 ? MetaData::SORT_GROUPNAME
222- : (int )$ this ->config -> getAppValue ('core ' , 'group.sortBy ' , (string )MetaData::SORT_USERCOUNT );
235+ : (int )$ this ->appConfig -> getValueString ('core ' , 'group.sortBy ' , (string )MetaData::SORT_USERCOUNT );
223236 $ serverData ['forceSortGroupByName ' ] = $ forceSortGroupByName ;
224237 $ serverData ['quotaPreset ' ] = $ quotaPreset ;
225238 $ serverData ['allowUnlimitedQuota ' ] = $ allowUnlimitedQuota ;
@@ -230,9 +243,13 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
230243 // Settings
231244 $ serverData ['defaultQuota ' ] = $ defaultQuota ;
232245 $ serverData ['canChangePassword ' ] = $ canChangePassword ;
233- $ serverData ['newUserGenerateUserID ' ] = $ this ->config ->getAppValue ('core ' , 'newUser.generateUserID ' , 'no ' ) === 'yes ' ;
234- $ serverData ['newUserRequireEmail ' ] = $ this ->config ->getAppValue ('core ' , 'newUser.requireEmail ' , 'no ' ) === 'yes ' ;
235- $ serverData ['newUserSendEmail ' ] = $ this ->config ->getAppValue ('core ' , 'newUser.sendEmail ' , 'yes ' ) === 'yes ' ;
246+ $ serverData ['newUserGenerateUserID ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.generateUserID ' , false );
247+ $ serverData ['newUserRequireEmail ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.requireEmail ' , false );
248+ $ serverData ['newUserSendEmail ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.sendEmail ' , true );
249+ $ serverData ['showConfig ' ] = [];
250+ foreach (self ::ALLOWED_USER_PREFERENCES as $ key ) {
251+ $ serverData ['showConfig ' ][$ key ] = $ this ->userConfig ->getValueBool ($ uid , $ this ->appName , $ key , false );
252+ }
236253
237254 $ this ->initialState ->provideInitialState ('usersSettings ' , $ serverData );
238255
@@ -250,13 +267,22 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
250267 */
251268 #[AuthorizedAdminSetting(settings:Users::class)]
252269 public function setPreference (string $ key , string $ value ): JSONResponse {
253- $ allowed = ['newUser.sendEmail ' , 'group.sortBy ' ];
254- if (!in_array ($ key , $ allowed , true )) {
255- return new JSONResponse ([], Http::STATUS_FORBIDDEN );
270+ switch ($ key ) {
271+ case 'newUser.sendEmail ' :
272+ $ this ->appConfig ->setValueBool ('core ' , $ key , $ value === 'yes ' );
273+ break ;
274+ case 'group.sortBy ' :
275+ $ this ->appConfig ->setValueString ('core ' , $ key , $ value );
276+ break ;
277+ default :
278+ if (in_array ($ key , self ::ALLOWED_USER_PREFERENCES , true )) {
279+ $ this ->userConfig ->setValueBool ($ this ->userSession ->getUser ()->getUID (), $ this ->appName , $ key , $ value === 'true ' );
280+ } else {
281+ return new JSONResponse ([], Http::STATUS_FORBIDDEN );
282+ }
283+ break ;
256284 }
257285
258- $ this ->config ->setAppValue ('core ' , $ key , $ value );
259-
260286 return new JSONResponse ([]);
261287 }
262288
0 commit comments