Repository navigation
Let the UI's delete and password-reset buttons act through the API, and check the API's permissions on audit log pages - #2791
Conversation
Signed-off-by: Enoch <bferanmi806@gmail.com>
asset_contains_data probed timed_belief with a subquery for the subtree's sensors. Postgres planned that as a merge join over the whole timed_belief index, so on a table of 20 million beliefs the probe took over two seconds whenever the subtree held no beliefs, however small it was. It now fetches the subtree's asset and sensor IDs first and names them in the probes, which Postgres looks up in the index: 31 ms at most on the same database, for a tree of 1000 sensors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
With the probe looking up sensors by ID, the asset and sensor pages can again tell whether a user may delete what they show, rather than offer the button to every member and let deletion fail on data. So members keep a delete button for assets and sensors without data, as the API lets them delete those, and users who may delete data skip the query altogether. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
The scan came in with #2607, which is not released yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
The copy buttons noted "you can copy but not delete" to whoever may not delete the asset shown. But that asset may hold data, while a copy holds none, and whoever may copy an asset may edit the assets where the copy lands, so they may delete the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
The asset page's delete button and the reset-password buttons now call the API's DELETE and PATCH endpoints, which a link on another site cannot trigger, and the UI routes that did the same on a GET are gone. Resetting a password now asks for confirmation first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
…n's asset page The account audit log page now follows the audit log's own access rule, as the API does, rather than letting anyone who may read the account see it. The user audit log page and the page listing an organisation's assets now check access too, so they no longer name users or organisations the visitor may not read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
There was a problem hiding this comment.
🟡 Changes recommended
A moderate unresolved issue remains where two new tests mix the module-scoped db fixture with the module's fresh_db style, violating the repo's single-fixture convention and risking order-dependent, fragile test behavior.
1 open issue
What changed in this PR
This PR aligns several UI views with their API counterparts. The asset page's "Delete this asset" button and the "Reset password" buttons now act through the API (DELETE /api/v3_0/assets/<id> and PATCH /api/v3_0/users/<id>/password-reset) instead of GET-based UI routes (/assets/delete_with_data/<id> and /users/reset_password_for/<id>), which are removed. It also brings three pages' authorization in line with the API: the account and user audit-log pages now enforce the audit-log ACL (AuditLog.account_table_acl / user_table_acl), and the account-asset listing now requires read access to the account. A supporting change makes user_can_delete skip the data-existence probe for users who already hold delete-data, and asset_contains_data materializes the subtree's IDs to keep Postgres from planning a slow index scan.
Changes:
- Replace UI delete/reset-password routes with buttons that call the API via JS (
initDeleteAssetButton, newinitResetPasswordButtons), adding a confirmation dialog for password resets. - Enforce API-equivalent permissions on the account/user audit-log pages and the account-asset listing.
- Optimize
user_can_delete/asset_contains_datato avoid unnecessary data queries, with accompanying tests.
| File | Description |
|---|---|
flexmeasures/ui/views/users/views.py |
Remove reset_password_for route; add audit-log ACL check on the user audit-log page |
flexmeasures/ui/views/assets/views.py |
Remove delete_with_data route and toast_msg; add read-access check to owned_by |
flexmeasures/ui/views/accounts.py |
Use AuditLog.account_table_acl on the account audit-log page |
flexmeasures/ui/utils/auth_utils.py |
Skip data probe in user_can_delete when user has delete-data; add docstring |
flexmeasures/ui/templates/users/user.html, admin/logged_in_user.html |
Convert reset-password links to API-calling buttons |
flexmeasures/ui/templates/assets/asset_properties.html |
Add data-parent-asset-id; drop stale "cannot delete copies" note |
flexmeasures/ui/static/js/ui-utils.js |
Point delete button at the API; add initResetPasswordButtons |
flexmeasures/data/services/generic_assets.py |
Materialize subtree IDs in asset_contains_data to avoid a slow query plan |
flexmeasures/ui/tests/*, flexmeasures/data/tests/test_generic_assets.py |
New/updated tests for permissions, delete flow, and the data probe |
documentation/changelog.rst |
Changelog entry for the above |
One issue is flagged inline: the two new tests in test_generic_assets.py introduce the module-scoped db fixture into a module that otherwise uses function-scoped fresh_db, which violates the repo's "one database fixture per module" convention and makes the module order-dependent. The rest of the changes look consistent and well-covered.
Review effort: Balanced
…dule does A module uses either the db or the fresh_db fixture, never both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7 Signed-off-by: F.N. Claessen <claessen@seita.nl>
Documentation build overview
7 files changed ·
|
… passwords on a GET, and check access on UI pages On 1.0.x, GET /assets/delete_with_data/<id> deleted any asset, with its data, for any logged-in user, as it called the asset service without the permission check the API does (since #1683, in v0.28.0). The asset page's delete button and the reset-password buttons now call the API instead, and the UI routes that acted on a GET are gone, so a link on another site cannot trigger them either. The sensor page, the user audit log page and the page listing an organisation's assets now check access, and the account audit log page follows the audit log's own access rule, as on main. See GHSA-vmgf-59hm-j9m7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v5ELzmj2eBM1L4GTBz Signed-off-by: F.N. Claessen <claessen@seita.nl>
The v1.0.2 patch release backports the fixes for GHSA-xcvm-r33m-77v5 (KPI sensors readable across organisations) and GHSA-vmgf-59hm-j9m7 (the security part of #2791) to the 1.0.x branch. Move their changelog bullets out of the v1.1.0 section into a new v1.0.2 section, so the same fix is not listed as unreleased once 1.0.2 ships. The API and CLI change logs are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DWv6v5ELzmj2eBM1L4GTBz Signed-off-by: F.N. Claessen <claessen@seita.nl>

Description
Brings a few UI views in line with their API counterparts.
DELETE /api/v3_0/assets/<id>andPATCH /api/v3_0/users/<id>/password-reset, the way the sensor page's delete button already does.The UI routes that did the same on a GET,
/assets/delete_with_data/<id>and/users/reset_password_for/<id>, are removed.Resetting a password now asks for confirmation first.
documentation/changelog.rstBuilds on #2788, now merged.
Look & Feel
No visual changes, except a confirmation dialog before resetting a password.
After deleting an asset, the page moves on to its parent asset, or to the asset list for a top-level asset, as before.
How to test
pytest flexmeasures/ui/testsRelated Items
Follows up on #2788.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7