2323use OCP \AppFramework \Http \DataResponse ;
2424use OCP \AppFramework \Http \RedirectResponse ;
2525use OCP \AppFramework \Http \TemplateResponse ;
26+ use OCP \AppFramework \Services \IAppConfig ;
2627use OCP \AppFramework \Services \IInitialState ;
28+ use OCP \Config \IUserConfig ;
2729use OCP \Constants ;
2830use OCP \Contacts \IManager as IContactManager ;
29- use OCP \IConfig ;
3031use OCP \IL10N ;
3132use OCP \IRequest ;
3233use OCP \IURLGenerator ;
@@ -44,7 +45,8 @@ class ConfigController extends Controller {
4445 public function __construct (
4546 string $ appName ,
4647 IRequest $ request ,
47- private IConfig $ config ,
48+ private IAppConfig $ appConfig ,
49+ private IUserConfig $ userConfig ,
4850 private IURLGenerator $ urlGenerator ,
4951 private IL10N $ l ,
5052 private IContactManager $ contactsManager ,
@@ -70,16 +72,16 @@ public function setConfig(array $values): DataResponse {
7072 return new DataResponse ([], Http::STATUS_BAD_REQUEST );
7173 }
7274 foreach ($ values as $ key => $ value ) {
73- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , $ key , $ value );
75+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , $ key , $ value, lazy: true );
7476 }
7577 $ result = [];
7678
7779 if (isset ($ values ['user_name ' ]) && $ values ['user_name ' ] === '' ) {
78- $ this ->config -> deleteUserValue ($ this ->userId , Application::APP_ID , 'user_id ' );
79- $ this ->config -> deleteUserValue ($ this ->userId , Application::APP_ID , 'user_name ' );
80- $ this ->config -> deleteUserValue ($ this ->userId , Application::APP_ID , 'refresh_token ' );
81- $ this ->config -> deleteUserValue ($ this ->userId , Application::APP_ID , 'token_expires_at ' );
82- $ this ->config -> deleteUserValue ($ this ->userId , Application::APP_ID , 'token ' );
80+ $ this ->userConfig -> deleteUserConfig ($ this ->userId , Application::APP_ID , 'user_id ' );
81+ $ this ->userConfig -> deleteUserConfig ($ this ->userId , Application::APP_ID , 'user_name ' );
82+ $ this ->userConfig -> deleteUserConfig ($ this ->userId , Application::APP_ID , 'refresh_token ' );
83+ $ this ->userConfig -> deleteUserConfig ($ this ->userId , Application::APP_ID , 'token_expires_at ' );
84+ $ this ->userConfig -> deleteUserConfig ($ this ->userId , Application::APP_ID , 'token ' );
8385 $ result ['user_name ' ] = '' ;
8486 } else {
8587 if (isset ($ values ['drive_output_dir ' ])) {
@@ -106,10 +108,8 @@ public function setAdminConfig(array $values): DataResponse {
106108 if ($ key === 'client_secret ' && $ value === 'dummySecret ' ) {
107109 continue ;
108110 }
109- if (in_array ($ key , ['client_secret ' , 'client_id ' ], true ) && $ value !== '' ) {
110- $ value = $ this ->crypto ->encrypt ($ value );
111- }
112- $ this ->config ->setAppValue (Application::APP_ID , $ key , $ value );
111+ $ sensitive = in_array ($ key , ['client_secret ' , 'client_id ' ], true );
112+ $ this ->appConfig ->setAppValueString ($ key , $ value , lazy: true , sensitive: $ sensitive );
113113 }
114114 return new DataResponse (1 );
115115 }
@@ -172,9 +172,9 @@ public function oauthRedirect(string $code = '', string $state = '', string $sco
172172 );
173173 }
174174
175- $ configState = $ this ->config -> getUserValue ($ this ->userId , Application::APP_ID , 'oauth_state ' );
176- $ clientID = $ this ->secretService -> getEncryptedAppValue ('client_id ' );
177- $ clientSecret = $ this ->secretService -> getEncryptedAppValue ('client_secret ' );
175+ $ configState = $ this ->userConfig -> getValueString ($ this ->userId , Application::APP_ID , 'oauth_state ' , lazy: true );
176+ $ clientID = $ this ->appConfig -> getAppValueString ('client_id ' , lazy: true );
177+ $ clientSecret = $ this ->appConfig -> getAppValueString ('client_secret ' , lazy: true );
178178
179179 // Store given scopes in space-separated string
180180 $ scopes = explode (' ' , $ scope );
@@ -186,13 +186,13 @@ public function oauthRedirect(string $code = '', string $state = '', string $sco
186186 'can_access_calendar ' => (in_array (self ::CALENDAR_SCOPE , $ scopes ) && in_array (self ::CALENDAR_EVENTS_SCOPE , $ scopes )) ? 1 : 0 ,
187187 ];
188188
189- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'user_scopes ' , json_encode ($ scopesArray ));
189+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'user_scopes ' , json_encode ($ scopesArray ), lazy: true );
190190
191191 // anyway, reset state
192- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'oauth_state ' , '' );
192+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'oauth_state ' , '' , lazy: true );
193193
194194 if ($ clientID && $ clientSecret && $ configState !== '' && $ configState === $ state ) {
195- $ redirect_uri = $ this ->config -> getUserValue ($ this ->userId , Application::APP_ID , 'redirect_uri ' );
195+ $ redirect_uri = $ this ->userConfig -> getValueString ($ this ->userId , Application::APP_ID , 'redirect_uri ' , lazy: true );
196196 /** @var array{access_token?:string, refresh_token?:string, expires_in?:string, error?:string} $result */
197197 $ result = $ this ->googleApiService ->requestOAuthAccessToken ([
198198 'client_id ' => $ clientID ,
@@ -207,12 +207,12 @@ public function oauthRedirect(string $code = '', string $state = '', string $sco
207207 if (isset ($ result ['expires_in ' ])) {
208208 $ nowTs = (new DateTime ())->getTimestamp ();
209209 $ expiresAt = $ nowTs + (int )$ result ['expires_in ' ];
210- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'token_expires_at ' , ( string ) $ expiresAt );
210+ $ this ->userConfig -> setValueInt ($ this ->userId , Application::APP_ID , 'token_expires_at ' , $ expiresAt, lazy: true );
211211 }
212212 $ this ->secretService ->setEncryptedUserValue ($ this ->userId , 'token ' , $ accessToken );
213213 $ this ->secretService ->setEncryptedUserValue ($ this ->userId , 'refresh_token ' , $ refreshToken );
214214 $ username = $ this ->storeUserInfo ();
215- $ usePopup = $ this ->config -> getAppValue (Application:: APP_ID , 'use_popup ' , '0 ' ) === '1 ' ;
215+ $ usePopup = $ this ->appConfig -> getAppValueString ( 'use_popup ' , '0 ' , lazy: true ) === '1 ' ;
216216 if ($ usePopup ) {
217217 return new RedirectResponse (
218218 $ this ->urlGenerator ->linkToRoute ('integration_google.config.popupSuccessPage ' , ['username ' => $ username ])
@@ -248,12 +248,12 @@ private function storeUserInfo(): string {
248248 /** @var array{id?:string, name?:string} $info */
249249 $ info = $ this ->googleApiService ->request ($ this ->userId , 'oauth2/v1/userinfo ' , ['alt ' => 'json ' ]);
250250 if (isset ($ info ['name ' ], $ info ['id ' ])) {
251- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'user_id ' , $ info ['id ' ]);
252- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'user_name ' , $ info ['name ' ]);
251+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'user_id ' , $ info ['id ' ], lazy: true );
252+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'user_name ' , $ info ['name ' ], lazy: true );
253253 return $ info ['name ' ];
254254 } else {
255- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'user_id ' , '' );
256- $ this ->config -> setUserValue ($ this ->userId , Application::APP_ID , 'user_name ' , '' );
255+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'user_id ' , '' , lazy: true );
256+ $ this ->userConfig -> setValueString ($ this ->userId , Application::APP_ID , 'user_name ' , '' , lazy: true );
257257 return '' ;
258258 }
259259 }
0 commit comments