@@ -183,6 +183,15 @@ async def lifespan(app: FastAPI):
183183 default = "foo" ,
184184 options = {_ ("First radio" ): "foo" , _ ("Second radio" ): "bar" , _ ("Third radio" ): "baz" },
185185 ),
186+ SettingsField (
187+ id = "test_ex_app_sensitive_field" ,
188+ title = _ ("Password" ),
189+ description = _ ("Set some secure value setting with encryption" ),
190+ type = SettingsFieldType .PASSWORD ,
191+ default = "" ,
192+ placeholder = _ ("Set secure value" ),
193+ sensitive = True ,
194+ ),
186195 ],
187196)
188197
@@ -194,7 +203,10 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
194203 "top_menu" ,
195204 "first_menu" ,
196205 "ui_example_state" ,
197- {"initial_value" : "test init value" },
206+ {
207+ "initial_value" : "test init value" ,
208+ "initial_sensitive_value" : "test_sensitive_value" ,
209+ },
198210 )
199211 nc .ui .resources .set_script ("top_menu" , "first_menu" , "js/ui_example-main" )
200212 nc .ui .top_menu .register ("first_menu" , "UI example" , "img/app.svg" )
@@ -234,6 +246,8 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
234246 ],
235247 )
236248
249+ nc .appconfig_ex .set_value ("test_ex_app_sensitive_field" , "test_sensitive_value" , sensitive = True )
250+
237251 if nc .srv_version ["major" ] >= 29 :
238252 nc .ui .settings .register_form (SETTINGS_EXAMPLE )
239253 else :
@@ -247,13 +261,21 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
247261 nc .occ_commands .unregister ("ui_example:ping" )
248262 nc .occ_commands .unregister ("ui_example:setup" )
249263 nc .occ_commands .unregister ("ui_example:stream" )
264+ nc .appconfig_ex .delete ("test_ex_app_sensitive_field" )
250265 return ""
251266
252267
253268class Button1Format (BaseModel ):
254269 initial_value : str
255270
256271
272+ class Button2Format (BaseModel ):
273+ sensitive_value : str
274+
275+ class Button3Format (BaseModel ):
276+ preference_value : str
277+
278+
257279@APP .post ("/api/verify_initial_value" )
258280async def verify_initial_value (
259281 input1 : Button1Format ,
@@ -263,6 +285,28 @@ async def verify_initial_value(
263285 content = {"initial_value" : str (random .randint (0 , 100 ))}, status_code = 200
264286 )
265287
288+ @APP .post ("/api/verify_sensitive_value" )
289+ async def verify_sensitive_value (
290+ input1 : Button2Format ,
291+ nc : Annotated [NextcloudApp , Depends (nc_app )],
292+ ):
293+ print ("Old sensitive value: " , input1 .sensitive_value )
294+ sensitive_value = nc .appconfig_ex .get_value ("test_ex_app_sensitive_field" )
295+ print ("Sensitive value: " , sensitive_value )
296+ return responses .JSONResponse (content = {"sensitive_value" : sensitive_value }, status_code = 200 )
297+
298+
299+ @APP .post ("/api/verify_preference_value" )
300+ async def verify_preference_value (
301+ input1 : Button3Format ,
302+ nc : Annotated [NextcloudApp , Depends (nc_app )],
303+ ):
304+ nc .preferences_ex .set_value ("test_ex_app_sensitive_field" , input1 .preference_value , sensitive = True )
305+ preference_value = nc .preferences_ex .get_value ("test_ex_app_sensitive_field" )
306+ print ("Old preference value: " , input1 .preference_value )
307+ print ("Preference value: " , preference_value )
308+ return responses .JSONResponse (content = {"preference_value" : preference_value }, status_code = 200 )
309+
266310
267311@APP .post ("/api/test_menu" )
268312async def test_menu_handler (
0 commit comments