Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2023] Implemented Category/Product admin access based on auth.Group #967

Merged
merged 4 commits into from
Feb 2, 2024

Conversation

Bartvaderkin
Copy link
Contributor

@Bartvaderkin Bartvaderkin commented Jan 18, 2024

task: https://taiga.maykinmedia.nl/project/open-inwoner/task/2023

To make this work create a Group in the admin and assign some Categories. Then assign this Group to a non-superuser, and login as this User.

Then in the Category list view you'll only see this category, and in the Product list view you only see Product from this Category. Additionally in the Product edit view you can only assign Categories from your Groups (there is some logic to keep assigned Categories you're not allowed to manage)..

@codecov-commenter
Copy link

codecov-commenter commented Jan 18, 2024

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (c63452b) 94.77% compared to head (fbc6500) 94.74%.
Report is 8 commits behind head on develop.

Files Patch % Lines
src/open_inwoner/pdc/admin/category.py 59.25% 11 Missing ⚠️
src/open_inwoner/accounts/forms.py 64.28% 5 Missing ⚠️
src/open_inwoner/accounts/admin.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #967      +/-   ##
===========================================
- Coverage    94.77%   94.74%   -0.04%     
===========================================
  Files          861      863       +2     
  Lines        30192    30388     +196     
===========================================
+ Hits         28614    28790     +176     
- Misses        1578     1598      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bartvaderkin Bartvaderkin force-pushed the feature/2023-category-admin-group branch from 22645c8 to 4b49cd4 Compare January 23, 2024 10:51
@Bartvaderkin Bartvaderkin changed the title WIP [#2023] Implemented Category/Product admin access based on auth.Group [#2023] Implemented Category/Product admin access based on auth.Group Jan 23, 2024
@Bartvaderkin Bartvaderkin marked this pull request as ready for review January 23, 2024 11:11
@pi-sigma
Copy link
Contributor

When I try to edit a category via the CMS without permission, I am redirected to the admin and get the following message:

Onderwerp met ID ‘10’ bestaat niet. Misschien is deze verwijderd?

That's misleading. Perhaps change the message to indicate that the user has no permission.

Copy link
Contributor

@pi-sigma pi-sigma left a comment

Choose a reason for hiding this comment

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

A group user who is not part of a group with access to category X can still view and change X (or any other category) by assigning the permission pdc | Product | Can change product to themselves.

It would be best to just hide the permission section from the admin for group users (only show it to superusers).

src/open_inwoner/pdc/admin/product.py Outdated Show resolved Hide resolved
src/open_inwoner/pdc/models/category.py Outdated Show resolved Hide resolved
@Bartvaderkin
Copy link
Contributor Author

Bartvaderkin commented Jan 25, 2024

@pi-sigma

  • Unless I'm missing something you shouldn't be able to navigate (by clicking stuff) to a category or product edit-page you don't have access to, as it won't show up in the list because it is filtered at the get_queryset() level. Which is also why the error message reports not-found instead of bad-permission. It is out of scope to cover this with a custom message.

  • I don't think this is an issue? Users with these category restrictions are of lower responsibility and won't have group management because that would create this escalation route.

src/open_inwoner/pdc/admin/category.py Outdated Show resolved Hide resolved
src/open_inwoner/pdc/admin/product.py Show resolved Hide resolved
@@ -95,6 +96,52 @@ def test_user_cannot_publish_child_category_without_root_published_on_list_page(
updated_category = Category.objects.get(slug="bar4")
self.assertFalse(updated_category.published)

def test_access_limited_to_linked_auth_groups(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're missing a testcase to verify that a user with managed categories cannot see/edit the access_groups field on the Category change page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this test (even though it is now readonly)

@Bartvaderkin Bartvaderkin force-pushed the feature/2023-category-admin-group branch from 693d142 to bc29efa Compare February 1, 2024 11:18
@Bartvaderkin Bartvaderkin force-pushed the feature/2023-category-admin-group branch from bc29efa to c96e2f0 Compare February 1, 2024 11:47
@stevenbal stevenbal merged commit e8471d8 into develop Feb 2, 2024
14 checks passed
@stevenbal stevenbal deleted the feature/2023-category-admin-group branch February 2, 2024 13:57
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.

4 participants