feat: add is_visible callable for dynamic menu item visibility#502
feat: add is_visible callable for dynamic menu item visibility#502ShlomoCode wants to merge 1 commit intofarridav:mainfrom
Conversation
e2ac445 to
433c1b0
Compare
|
@farridav Can you check this? Thanks |
|
If Checking group membership as a means of permissions seems to be a bit of an anti-pattern with djangos builtin authentication. as an example:
The implementation of permission checking need not ever reference groups, as To provide a better example, ive added a pull request to demonstrate this in a test: #630 if you feel like something has been lost here, please let me know |
What do you think about this? https://docs.djangoproject.com/en/4.2/topics/auth/default/#groups:~:text=Beyond%20permissions%2C%20groups,only%20email%20messages |
I think its an interesting idea that is something ive never used in that way within Django apps ive built in the past, but i can see the value in it, especially within Jazzmin ;) That said, i will need you to add tests for this, feel free to borrow from my implementation linked above. |
|
@farridav Instead of adding explicit This approach is more flexible, users can implement any visibility logic they need (groups with AND/OR, path-based, etc.) without requiring new parameters for each use case. Also added tests. |
Allows menu items to define a callable that receives the request object and returns True/False to control visibility. This enables complex visibility logic based on user groups, request path, permissions, etc.
|
I rsolved the conflicts |
from django docs:
This PR adds support for the groups option as a display condition for a menu item (user_menu/top_menu).
It is very useful in my opinion to be able to control the display option not only based on model permissions but also based on the groups.
It works in the form of AND, if both groups and permissions are defined, and the user has only the groups or only permissions, the item will not be shown to him (open to comments maybe it should work differently).
usage example: