[Fixes #13581] Forbid API changing permissions for anonymous and registered members users if user is not allowed to#13592
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #13592 +/- ##
==========================================
+ Coverage 74.00% 74.03% +0.02%
==========================================
Files 932 932
Lines 55471 55573 +102
Branches 7476 7487 +11
==========================================
+ Hits 41054 41144 +90
- Misses 12786 12794 +8
- Partials 1631 1635 +4 🚀 New features to boost your workflow:
|
giohappy
left a comment
There was a problem hiding this comment.
@sijandh35 Instead of doing all this logic (including retrieving the Group objects from the DB), shouldn't we just discard the anonymous and registered_members permissions from the perms payload in case the user doesn't have permissions to change it?
I mean:
- We check if the user doesn't have
can_manage_anonymous_permissionsorcan_manage_registered_member_permissions - In that case, we remove the two groups from
request.data.get("groups")without throwing any exception - The other changes will go through, but the permissions for the two groups remain unchanged
Maybe we can also avoid the check with the grups id, and just rely on the group name? This would save a DB query.
Hi @giohappy Updated it.
Yes, using the group name would reduce the need for the query to fetch the group object. However, from what I see on the client side, when a permission is changed, a PUT request is made, and in the groups key it only sends the ID and permissions — for example: [{'id': 3, 'permissions': 'view'}, {'id': 2, 'permissions': 'edit'}]. That’s why I used the ID. But if we can pass the group name also from client, that would be better. |
…permission to update
54f1846 to
4c5cd0d
Compare
This PR Fixes #13581
This PR should only be merged after the issue(#13578 ) is merged.
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.