diff --git a/lib/main.py b/lib/main.py
index fe55d5a..2abea82 100644
--- a/lib/main.py
+++ b/lib/main.py
@@ -183,6 +183,15 @@ async def lifespan(app: FastAPI):
default="foo",
options={_("First radio"): "foo", _("Second radio"): "bar", _("Third radio"): "baz"},
),
+ SettingsField(
+ id="test_ex_app_sensitive_field",
+ title=_("Password"),
+ description=_("Set some secure value setting with encryption"),
+ type=SettingsFieldType.PASSWORD,
+ default="",
+ placeholder=_("Set secure value"),
+ sensitive=True,
+ ),
],
)
@@ -194,7 +203,10 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
"top_menu",
"first_menu",
"ui_example_state",
- {"initial_value": "test init value"},
+ {
+ "initial_value": "test init value",
+ "initial_sensitive_value": "test_sensitive_value",
+ },
)
nc.ui.resources.set_script("top_menu", "first_menu", "js/ui_example-main")
nc.ui.top_menu.register("first_menu", "UI example", "img/app.svg")
@@ -234,6 +246,8 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
],
)
+ nc.appconfig_ex.set_value("test_ex_app_sensitive_field", "test_sensitive_value", sensitive=True)
+
if nc.srv_version["major"] >= 29:
nc.ui.settings.register_form(SETTINGS_EXAMPLE)
else:
@@ -247,6 +261,7 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
nc.occ_commands.unregister("ui_example:ping")
nc.occ_commands.unregister("ui_example:setup")
nc.occ_commands.unregister("ui_example:stream")
+ nc.appconfig_ex.delete("test_ex_app_sensitive_field")
return ""
@@ -254,6 +269,13 @@ class Button1Format(BaseModel):
initial_value: str
+class Button2Format(BaseModel):
+ sensitive_value: str
+
+class Button3Format(BaseModel):
+ preference_value: str
+
+
@APP.post("/api/verify_initial_value")
async def verify_initial_value(
input1: Button1Format,
@@ -263,6 +285,28 @@ async def verify_initial_value(
content={"initial_value": str(random.randint(0, 100))}, status_code=200
)
+@APP.post("/api/verify_sensitive_value")
+async def verify_sensitive_value(
+ input1: Button2Format,
+ nc: Annotated[NextcloudApp, Depends(nc_app)],
+):
+ print("Old sensitive value: ", input1.sensitive_value)
+ sensitive_value = nc.appconfig_ex.get_value("test_ex_app_sensitive_field")
+ print("Sensitive value: ", sensitive_value)
+ return responses.JSONResponse(content={"sensitive_value": sensitive_value}, status_code=200)
+
+
+@APP.post("/api/verify_preference_value")
+async def verify_preference_value(
+ input1: Button3Format,
+ nc: Annotated[NextcloudApp, Depends(nc_app)],
+):
+ nc.preferences_ex.set_value("test_ex_app_sensitive_field", input1.preference_value, sensitive=True)
+ preference_value = nc.preferences_ex.get_value("test_ex_app_sensitive_field")
+ print("Old preference value: ", input1.preference_value)
+ print("Preference value: ", preference_value)
+ return responses.JSONResponse(content={"preference_value": preference_value}, status_code=200)
+
@APP.post("/api/test_menu")
async def test_menu_handler(
diff --git a/requirements.txt b/requirements.txt
index 46dc28f..d884097 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
-nc-py-api[app]>=0.10.0
+nc-py-api[app]>=0.20.2
fastapi
pydantic
diff --git a/src/store/example.js b/src/store/example.js
index 7b32d08..aec8533 100644
--- a/src/store/example.js
+++ b/src/store/example.js
@@ -37,6 +37,38 @@ const actions = {
})
},
+ verifySensitiveValue(context, value) {
+ axios.post(generateUrl(`${APP_API_PROXY_URL_PREFIX}/${EX_APP_ID}/api/verify_sensitive_value`), {
+ sensitive_value: value,
+ })
+ .then((res) => {
+ if ('sensitive_value' in res.data && res.data.sensitive_value === value) {
+ showSuccess(t('ui_example', 'Sensitive value is correct'))
+ } else {
+ showError(t('ui_example', 'Sensitive value is incorrect'))
+ }
+ })
+ .catch(() => {
+ showError(t('ui_example', 'Sensitive value is incorrect'))
+ })
+ },
+
+ verifyPreferenceValue(context, value) {
+ axios.post(generateUrl(`${APP_API_PROXY_URL_PREFIX}/${EX_APP_ID}/api/verify_preference_value`), {
+ preference_value: value,
+ })
+ .then((res) => {
+ if ('preference_value' in res.data && res.data.preference_value === value) {
+ showSuccess(t('ui_example', 'Preference value is correct'))
+ } else {
+ showError(t('ui_example', 'Preference value is incorrect'))
+ }
+ })
+ .catch(() => {
+ showError(t('ui_example', 'Preference value is incorrect'))
+ })
+ },
+
sendNextcloudFileToExApp(context, fileInfo) {
axios.post(generateUrl(`${APP_API_PROXY_URL_PREFIX}/${EX_APP_ID}/api/nextcloud_file`), {
file_info: fileInfo,
diff --git a/src/views/ExAppView.vue b/src/views/ExAppView.vue
index c63cd70..6ed2f9b 100644
--- a/src/views/ExAppView.vue
+++ b/src/views/ExAppView.vue
@@ -12,6 +12,22 @@