Repository navigation
Make Resource.delete() check user_can_delete_resource - #13036
Closed
illtellyouwhat wants to merge 2 commits into
Closed
illtellyouwhat wants to merge 2 commits into
illtellyouwhat wants to merge 2 commits into
Conversation
archesproject#13035 AI assistance: Claude Code (Claude Opus 5.5) wrote the tests. I read them, approved them and ran them. Claude drafted the docstrings, and I reworded them.
archesproject#13035 AI assistance: Claude Code (Claude Opus 5.5) helped trace the permission call paths and proposed several fixes. I chose the final fix. Claude drafted the code comment, and I reworded it. I read each function myself and wrote or approved every line.
illtellyouwhat
force-pushed
the
13035_scope_resource_delete_to_resource
branch
from
October 20, 2026 04:09
39ddd2c to
47b7e55
Compare
chiatt
self-requested a review
October 22, 2026 18:00
chiatt
reviewed
Oct 22, 2026
chiatt
left a comment
Member
There was a problem hiding this comment.
Thanks @illtellyouwhat, this is a nice catch. Could you rebase on dev/8.1.x? Once you do you'll have the 8.1.6.md file in the releases directory. You can add a changelog entry in there; just follow the pattern in 8.1.5.md
Comment on lines
+698
to
+721
| # Ask the permission framework about this resource, so | ||
| # per-resource permissions and lifecycle rules apply to | ||
| # reviewers too. user_can_delete_resource refuses deletion | ||
| # when the resource's lifecycle state forbids it, unless the | ||
| # user holds can_delete_all_resource_instance_lifecycle_states. | ||
| # | ||
| # When a site sets neither per-resource nor per-card | ||
| # permissions, the framework answers "unknown" and falls back | ||
| # to a nodegroup check, which the reviewer passes. "unknown" is | ||
| # not itself a grant. In that case, a reviewer is refused only | ||
| # when the lifecycle state's can_delete_resource_instances flag | ||
| # forbids deletion. | ||
| # | ||
| # Alternative considered but not chosen: checking whether | ||
| # "delete_resourceinstance" is in get_perms(user, resource). On | ||
| # a site that sets no per-resource permissions, get_perms | ||
| # always returns an empty list, so the check always returns | ||
| # False. Every reviewer is refused, even though the | ||
| # default-allow framework treats "no permissions set" as | ||
| # allowed. user_can_delete_resource keeps that rule. | ||
| # | ||
| # Alternative considered but not chosen: adding a resource | ||
| # argument to user_is_resource_reviewer. It has 19 call sites | ||
| # in core, and 8 of them have no resource to pass. |
Member
There was a problem hiding this comment.
Could you remove this comment? The explanation of the reasoning is good in the PR and the code is otherwise clear.
1 of 11 tasks
Member
|
I wanted to make sure this got into the 8.1.6 release, so we cherrypicked this commit into this PR: #13079 |
Contributor
Author
|
@chiatt , Sorry I missed this earlier, I've been traveling overseas and was unable to check here. Thank-you for moving it along to 8.1.6. |
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.
Types of changes
Description of Change
A Resource Reviewer can delete any resource, in any lifecycle state, through
Resource.delete(). The reviewer branch grants deletion without asking the permission framework about the resource. It now callsuser_can_delete_resource, so per-resource permissions and the lifecycle state'scan_delete_resource_instancesflag apply.The single-resource view already makes this check. Bulk Data Deletion does not, and has no permission check of its own, so
Resource.delete()is its only gate.The reasoning, and two alternatives considered but not chosen, are in the comment at the changed line.
Compatibility. If a site sets neither per-resource nor per-card permissions, the framework has no per-resource answer and falls back to card permissions. With none set, every card is open, so the reviewer passes. The per-resource part changes nothing on those sites.
The lifecycle part is the intended change. A reviewer without
can_delete_all_resource_instance_lifecycle_statescan no longer delete a resource whose lifecycle state forbids deletion. The default lifecycle marks Active and Retired that way.Issues Solved
Closes #13035
Checklist
Accessibility Checklist
No user-facing change, so no accessibility impact.
Ticket Background
Further comments
Found while building an instance-scoped permission framework, where delete was the one grant that could not be expressed. The framework already inherited
user_can_delete_resource, but nothing called it on this path.Targeting
dev/8.1.xbecause this is a permission fix rather than a feature, anddev/8.1.xis contained indev/8.2.x, so it reaches development on your next merge-up. Happy to rebase ontodev/8.2.xif you would rather.Changelog. 8.1.5 is released, and releases/8.1.6.md does not exist yet. Should I create it with an entry for
#13036, or add the entry once you start that file?
Separate defect, not fixed here. If the user and their groups hold no per-resource permissions in Django Guardian,
user_can_delete_resourcelooks for protected tiles withTileModel.objects.filter(resourceinstance_id=resourceid)(arches_permission_base.py:433). If the caller passes the resource object instead of its ID,resourceidisNone. The query then finds no tiles, and the check passes even if protected tiles exist.Resource.delete()passes the object, so this PR adds the lifecycle and per-resource checks for reviewers, but not the per-card check. Two callers inviews/api/resource.pyalso pass the object, so the defect predates this PR. The fix is probablyresult["resource"].pk, but it changes behavior for those API callers, so it needs its own issue.Test evidence
Commit 1 adds two tests. Commit 2 applies the fix.
test_reviewer_cannot_delete_when_lifecycle_state_forbids_deletionfails ondev/8.1.xand passes with the fix.test_reviewer_can_still_delete_when_lifecycle_state_allows_deletionpasses on both, which shows that reviewers still delete where the lifecycle state allows it.At commit 1,
a0eeeddd25:At commit 2,
47b7e55b7f: