Add permission-based navbar items#2416
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2416 +/- ##
==========================================
+ Coverage 46.76% 47.75% +0.99%
==========================================
Files 251 261 +10
Lines 13317 13763 +446
==========================================
+ Hits 6228 6573 +345
- Misses 7089 7190 +101 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This pull request implements permission-based control for navbar items by filtering navigation bar entries based on the user's permissions.
- Updates the navbar context to filter items using a permission-based method.
- Adds a new "permission" field to the NavigationBar model along with an associated migration.
- Updates the admin interface to include the new permission field with an appropriate widget.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| judge/template_context.py | Filters navbar items based on user permissions using for_user method |
| judge/models/interface.py | Adds a permission field to the NavigationBar model and a static filtering method |
| judge/migrations/0150_navigationbar_permissions.py | Adds the new permission field to the NavigationBar model via migration |
| judge/admin/interface.py | Updates the admin form and field list to support the new permission field |
4607cd8 to
0724281
Compare
| return { | ||
| 'nav_tab': FixedSimpleLazyObject(partial(__nav_tab, request.path)), | ||
| 'nav_bar': NavigationBar.objects.all(), | ||
| 'nav_bar': NavigationBar.for_user(request.user), |
There was a problem hiding this comment.
What about nav_tab? This is going to break it.
There was a problem hiding this comment.
Right, this would break if multiple navbar items match the current path, but the first result is the one that gets hidden, then nothing would be highlighted.
I can see a few ways to fix this:
- passing the path to
for_userand moving the regex query there, but if anything else would use the navbar in the future it would run into the same issue again - making
for_usertake a queryset and the function would only apply the permission filter, but this would then result inNavigationBar.for_user(NavigationBar.objects.all())andNavigationBar.for_user(NavigationBar.objects.extra(where=['%s REGEXP BINARY regex'], params=[path])) - adding a custom queryset class for NavigationBar that applies the filter in the query (the one from Add permission-based navbar items #2416 (comment))
There was a problem hiding this comment.
Given that we are already fetching the entire navbar, computing nav_tab on the db layer is unnecessary. You can probably just change nav_tab to be computed in Python based on NavigationBar.for_user(request.user).
2fd4d48 to
814df3a
Compare
814df3a to
1f72dc0
Compare
Uh oh!
There was an error while loading. Please reload this page.