Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add sensitive preferences with encryption check
  • Loading branch information
andrey18106 committed May 29, 2025
commit b203613a75e25dff5fb1a42d8b5a5bf5c81a7bde
15 changes: 15 additions & 0 deletions lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ class Button1Format(BaseModel):
class Button2Format(BaseModel):
sensitive_value: str

class Button3Format(BaseModel):
preference_value: str


@APP.post("/api/verify_initial_value")
async def verify_initial_value(
Expand All @@ -293,6 +296,18 @@ async def verify_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(
file: UiActionFileInfo,
Expand Down
16 changes: 16 additions & 0 deletions src/store/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ const actions = {
})
},

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,
Expand Down
12 changes: 12 additions & 0 deletions src/views/ExAppView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
{{ t('ui_example', 'Verify sensitive value') }}
</NcButton>
</div>

<div style="margin: 10px 0; display: flex; align-items: center; width: 100%; justify-content: center; flex-direction: column;">
<NcInputField :value.sync="preference_value"
:label="t('ui_example', 'Test preference sensitive value')" />
<NcButton style="margin: 10px 0;" @click="verifyPreferenceValue">
{{ t('ui_example', 'Verify preference value') }}
</NcButton>
</div>
</div>
</NcAppContent>
</NcContent>
Expand All @@ -45,6 +53,7 @@ export default {
data() {
return {
initialState: JSON.parse(loadState('app_api', 'ui_example_state')),
preference_value: 'test_preference_value',
}
},
computed: {
Expand All @@ -59,6 +68,9 @@ export default {
verifySensitiveValue() {
this.$store.dispatch('verifySensitiveValue', this.initialState?.initial_sensitive_value)
},
verifyPreferenceValue() {
this.$store.dispatch('verifyPreferenceValue', this.preference_value)
},
},
}
</script>
Expand Down