Skip to content

Let the UI's delete and password-reset buttons act through the API, and check the API's permissions on audit log pages - #2791

Merged
Flix6x merged 14 commits into
mainfrom
fix/ui-permission-gaps
Nov 1, 2026
Merged

Flix6x merged 14 commits into
mainfrom
fix/ui-permission-gaps

Conversation

@Flix6x

@Flix6x Flix6x commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Description

Brings a few UI views in line with their API counterparts.

  • The asset page's "Delete this asset" button and the "Reset password" buttons (user page and own-user page) now call the API, DELETE /api/v3_0/assets/<id> and PATCH /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.
  • The account audit log page follows the audit log's access rule (account admins, consultants and admins), as the API does, instead of the rule for reading the account.
  • The user audit log page and the page listing an organisation's assets check access as well.
  • Added changelog item in documentation/changelog.rst

Builds 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/tests
  • In the UI: delete a child asset and a top-level asset; reset another user's password as an admin; reset your own password from your user page (you get logged out).

Related Items

Follows up on #2788.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DWv6v3qq916tT9BKtL4ji7

bferanmi806-sketch and others added 8 commits October 31, 2026 16:38
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>
@Flix6x Flix6x added this to the 1.1.0 milestone Nov 1, 2026
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, new initResetPasswordButtons), 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_data to 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

@read-the-docs-community

read-the-docs-community Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No open code issues remain after the earlier fresh_db/db mixing concern was resolved, leaving nothing outstanding to block approval.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Flix6x
Flix6x merged commit 3a946f3 into main Nov 1, 2026
12 of 13 checks passed
@Flix6x
Flix6x deleted the fix/ui-permission-gaps branch November 1, 2026 16:31
Flix6x added a commit that referenced this pull request Nov 5, 2026
… 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>
Flix6x added a commit that referenced this pull request Nov 5, 2026
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>
@Flix6x Flix6x removed this from the 1.1.0 milestone Nov 6, 2026
@Flix6x Flix6x added this to the 1.0.2 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants