nautobot / pylint-nautobot

Custom Pylint Rules for Nautobot
https://docs.nautobot.com/projects/pylint-nautobot/en/latest/
Other
4 stars 0 forks source link

Add linter to check for correct navigation permissions #97

Open gsnider2195 opened 1 month ago

gsnider2195 commented 1 month ago

Environment

Proposed Functionality

Ensure that if permissions are used in NavMenu items that they match the model being used in the linked view. For example, if you are adding a navigation menu item to the plugins:example_app:examplemodel_list view, the permission should be for example_app.view_examplemodel. See the Navigation Menu docs for more information.

Use Case

glennmatthews commented 1 month ago

Good thought, though also I'd really like to enhance the nav menu API in core at some point so that the common case can implicitly derive the correct permissions without needing so much duplication of information.

bryanculver commented 1 month ago

Let's not go down the depth of trying to introspect the router. Instead, let's just duck-type the link and permissions to ensure they follow the conventions (modelname_action and permission_modelname) and the model names are the same in both. Providing a helpful pylint documentation for this rule would suggest that Model-less views can be safely ignored with the pylint ignore comment.