cleanup user management templates' and views' auth checks with extra permissions context#3763
cleanup user management templates' and views' auth checks with extra permissions context#3763teovin wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3763 +/- ##
===========================================
+ Coverage 69.41% 69.50% +0.08%
===========================================
Files 58 60 +2
Lines 7870 7942 +72
===========================================
+ Hits 5463 5520 +57
- Misses 2407 2422 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rebeccacremona
left a comment
There was a problem hiding this comment.
Thanks for giving this a whack; these templates are just wild lol.
The templates are much easier to read with those named booleans, and the reduction of the dozens of inline lambdas in the permission checks is delightfully DRY.
I don't, however, think a context processor is the way to go: context processors run on every HTML request (homepage, settings, playback, etc.), just to build the ~20 flags needed by the user-management pages. I think we can go with a narrower helper, explicitly called by the views that need it. I think that will also be less confusing than having the default context build automatically, and then overriding it in places with calls like context['user_management_perms'] = build_user_management_perms(request, screen=group_name).
I'm going to take a swing at tweaking the architecture of your code, for your consideration: we can looks at the advantages and disadvantages of both together and pick whichever aspects seem cleanest and most intuitive 🤝
|
Alrighty! I made a PR to your PR: teovin#2 When you're back, let's chat about whether you like these ideas, or whether I messed up something about your original structure! Cheers, |
This PR cleans up some of the user management templates and their repeated
request.userchecks by creating a context processor that's populated with ui flags. The flags include actions and which users can carry them out, which are then received by the templates, and used to decide what content to render.I created an access module to define the access conditions. Along with the above, I also used this to power the
@user_passes_test_or_403checks in theuser_managementview in an attempt to reduce the repetition of theuserchecks there as well. (I see the@user_passes_test_or_403(lambda user:...is used outside of user management view, and can address those in a separate PR)