1919use OC \Security \IdentityProof \Manager ;
2020use OC \User \Manager as UserManager ;
2121use OCA \Settings \BackgroundJobs \VerifyUserData ;
22+ use OCA \Settings \ConfigLexicon ;
2223use OCA \Settings \Events \BeforeTemplateRenderedEvent ;
2324use OCA \Settings \Settings \Admin \Users ;
2425use OCA \User_LDAP \User_Proxy ;
3839use OCP \AppFramework \Http \TemplateResponse ;
3940use OCP \AppFramework \Services \IInitialState ;
4041use OCP \BackgroundJob \IJobList ;
42+ use OCP \Config \IUserConfig ;
4143use OCP \Encryption \IManager ;
4244use OCP \EventDispatcher \IEventDispatcher ;
4345use OCP \Group \ISubAdmin ;
46+ use OCP \IAppConfig ;
4447use OCP \IConfig ;
4548use OCP \IGroup ;
4649use OCP \IGroupManager ;
@@ -59,13 +62,24 @@ class UsersController extends Controller {
5962 /** Limit for counting users for subadmins, to avoid spending too much time */
6063 private const COUNT_LIMIT_FOR_SUBADMINS = 999 ;
6164
65+ public const ALLOWED_USER_PREFERENCES = [
66+ ConfigLexicon::USER_LIST_SHOW_STORAGE_PATH ,
67+ ConfigLexicon::USER_LIST_SHOW_USER_BACKEND ,
68+ ConfigLexicon::USER_LIST_SHOW_FIRST_LOGIN ,
69+ ConfigLexicon::USER_LIST_SHOW_LAST_LOGIN ,
70+ ConfigLexicon::USER_LIST_SHOW_NEW_USER_FORM ,
71+ ConfigLexicon::USER_LIST_SHOW_LANGUAGES ,
72+ ];
73+
6274 public function __construct (
6375 string $ appName ,
6476 IRequest $ request ,
6577 private UserManager $ userManager ,
6678 private IGroupManager $ groupManager ,
6779 private IUserSession $ userSession ,
6880 private IConfig $ config ,
81+ private IAppConfig $ appConfig ,
82+ private IUserConfig $ userConfig ,
6983 private IL10N $ l10n ,
7084 private IMailer $ mailer ,
7185 private IFactory $ l10nFactory ,
@@ -191,12 +205,12 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
191205 }
192206
193207 /* 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 ' ;
208+ $ quotaPreset = $ this ->parseQuotaPreset ($ this ->appConfig -> getValueString ('files ' , 'quota_preset ' , '1 GB, 5 GB, 10 GB ' ));
209+ $ allowUnlimitedQuota = $ this ->appConfig -> getValueBool ('files ' , 'allow_unlimited_quota ' , true ) ;
196210 if (!$ allowUnlimitedQuota && count ($ quotaPreset ) > 0 ) {
197- $ defaultQuota = $ this ->config -> getAppValue ('files ' , 'default_quota ' , $ quotaPreset [0 ]);
211+ $ defaultQuota = $ this ->appConfig -> getValueString ('files ' , 'default_quota ' , $ quotaPreset [0 ]);
198212 } else {
199- $ defaultQuota = $ this ->config -> getAppValue ('files ' , 'default_quota ' , 'none ' );
213+ $ defaultQuota = $ this ->appConfig -> getValueString ('files ' , 'default_quota ' , 'none ' );
200214 }
201215
202216 $ event = new BeforeTemplateRenderedEvent ();
@@ -219,7 +233,7 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
219233 $ serverData ['isDelegatedAdmin ' ] = $ isDelegatedAdmin ;
220234 $ serverData ['sortGroups ' ] = $ forceSortGroupByName
221235 ? MetaData::SORT_GROUPNAME
222- : (int )$ this ->config -> getAppValue ('core ' , 'group.sortBy ' , (string )MetaData::SORT_USERCOUNT );
236+ : (int )$ this ->appConfig -> getValueString ('core ' , 'group.sortBy ' , (string )MetaData::SORT_USERCOUNT );
223237 $ serverData ['forceSortGroupByName ' ] = $ forceSortGroupByName ;
224238 $ serverData ['quotaPreset ' ] = $ quotaPreset ;
225239 $ serverData ['allowUnlimitedQuota ' ] = $ allowUnlimitedQuota ;
@@ -230,9 +244,13 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
230244 // Settings
231245 $ serverData ['defaultQuota ' ] = $ defaultQuota ;
232246 $ 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 ' ;
247+ $ serverData ['newUserGenerateUserID ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.generateUserID ' , false );
248+ $ serverData ['newUserRequireEmail ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.requireEmail ' , false );
249+ $ serverData ['newUserSendEmail ' ] = $ this ->appConfig ->getValueBool ('core ' , 'newUser.sendEmail ' , true );
250+ $ serverData ['showConfig ' ] = [];
251+ foreach (self ::ALLOWED_USER_PREFERENCES as $ key ) {
252+ $ serverData ['showConfig ' ][$ key ] = $ this ->userConfig ->getValueBool ($ uid , $ this ->appName , $ key , false );
253+ }
236254
237255 $ this ->initialState ->provideInitialState ('usersSettings ' , $ serverData );
238256
@@ -250,13 +268,22 @@ public function usersList(INavigationManager $navigationManager, ISubAdmin $subA
250268 */
251269 #[AuthorizedAdminSetting(settings:Users::class)]
252270 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 );
271+ switch ($ key ) {
272+ case 'newUser.sendEmail ' :
273+ $ this ->appConfig ->setValueBool ('core ' , $ key , $ value === 'yes ' );
274+ break ;
275+ case 'group.sortBy ' :
276+ $ this ->appConfig ->setValueString ('core ' , $ key , $ value );
277+ break ;
278+ default :
279+ if (in_array ($ key , self ::ALLOWED_USER_PREFERENCES , true )) {
280+ $ this ->userConfig ->setValueBool ($ this ->userSession ->getUser ()->getUID (), $ this ->appName , $ key , $ value === 'true ' );
281+ } else {
282+ return new JSONResponse ([], Http::STATUS_FORBIDDEN );
283+ }
284+ break ;
256285 }
257286
258- $ this ->config ->setAppValue ('core ' , $ key , $ value );
259-
260287 return new JSONResponse ([]);
261288 }
262289
0 commit comments