Repository navigation
Add missing write-permission checks to network, scenario and resource group updates - #317
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_scenariowas called with the defaultcheck_write=False.groups.update_resourcegroup,delete_resourcegroup,add_resourcegroup: no check.groups.add_resourcegroupitem/delete_resourcegroupitem, and scenariodelete_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
check_write_permission/check_write=True) on all of the above. Admin, creator, network-level and project-level write behave as before.update_networkalso requires write on the new project ifproject_idchanges;move_networkrequires write on the target project.update_value_from_mappingalso refuse locked scenarios (check_can_edit), matchingadd_resourcegroupitem.delete_resourcegroupitemsnow 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_scenarionow runs after the network write check with the same user;merge_scenariosalready required write on the target. No internal caller relies on a missinguser_id.Deliberately left
clone_networkinto an existingproject_iddoes 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, andclone_projectclones 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 plustests/projectandtests/test_network.pypass (85), andtests/test_groups.pyandtests/test_scenario.pypassed (75) before a final change that only removed the clone check.