Skip to content

Add missing write-permission checks to network, scenario and resource group updates - #317

Merged
knoxsp merged 3 commits into
masterfrom
fix/write-permission-checks
Oct 22, 2026
Merged

knoxsp merged 3 commits into
masterfrom
fix/write-permission-checks

Conversation

@knoxsp

@knoxsp knoxsp commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Pairs with hwi MR !69 (read-only network access, hydra/hwi on gitlab.waterstrategy.org), whose review found that read-only users were only blocked client-side.

What was unprotected

These only checked read access (or nothing), so a view-only share could modify data:

  • update_network: no check at all (the check was a commented-out #check_perm). It could rename the network, move or add nodes, links and groups, and change attributes and scenarios.
  • update_scenario, create_child_scenario, clone_scenario: _get_scenario was called with the default check_write=False.
  • groups.update_resourcegroup, delete_resourcegroup, add_resourcegroup: no check.
  • groups.add_resourcegroupitem / delete_resourcegroupitem, and scenario delete_resourcegroupitems, empty_group, add_resourcegroupitems: read only (the last one also checked write via _check_network_ownership; now direct).
  • update_value_from_mapping: the target scenario was only read-checked.
  • move_network: checked write on the network but not on the destination project.

What now checks

  • Network write permission (check_write_permission / check_write=True) on all of the above. Admin, creator, network-level and project-level write behave as before.
  • update_network also requires write on the new project if project_id changes; move_network requires write on the target project.
  • The scenario-level group item functions and update_value_from_mapping also refuse locked scenarios (check_can_edit), matching add_resourcegroupitem.
  • delete_resourcegroupitems now only deletes items belonging to the given scenario (previously any item id was accepted once the scenario check passed).

Already checked and unchanged: add/update/delete node and link, delete_network, lock/unlock scenario, update_resourcedata, delete_scenario (purge) and network.add/update/delete_group.

Behaviour changes for callers

Read-only users now get PermissionError. Internal callers were checked: update_network -> update_scenario now runs after the network write check with the same user; merge_scenarios already required write on the target. No internal caller relies on a missing user_id.

Deliberately left

clone_network into an existing project_id does not require project write. An existing test (test_clone_network_in_shared_project) intentionally lets a user with only a network-level share clone into the parent project, and clone_project clones into projects the caller may not own. Worth a separate decision.

Testing

New tests/test_write_permissions.py: a view-only user is refused for each changed function, and the owner and a write-share user still succeed. Run on the default sqlite temp-file backend (no MySQL/remote DB used): new tests plus tests/project and tests/test_network.py pass (85), and tests/test_groups.py and tests/test_scenario.py passed (75) before a final change that only removed the clone check.

check_write is about the user's permission and check_can_edit only tests
whether the scenario is locked, so the name read like a second permission
check. check_unlocked says what it does. _get_scenario is private and has
no callers outside hydra-base, so no alias is kept.
With check_unlocked for the lock test, check_can_edit is the matching name
for the user-permission test and says that it is about the user, not the
scenario's state. Only _get_scenario's flag changes; the model's
check_write_permission and the check_write flags on other helpers are
untouched.
@knoxsp
knoxsp merged commit d73e580 into master Oct 22, 2026
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants