Permission checks in views should always evaluate the concrete model for an instance #8388

Closed
opened 2025-12-29 20:36:06 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (Jul 30, 2023).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

Currently, we always evaluate the model class of an instance when determining applicable permissions. Instead, we should we query for permissions assigned to its concrete model (i.e. instance._meta.concrete_model). There are a few places where this adjustment needs to be made.

Justification

Referencing the model directly inhibits the use of proxy models in established conventions. For instance, we want to be table to evaluate permissions using a UserToken instance to get permissions for its concrete Token model.

Originally created by @jeremystretch on GitHub (Jul 30, 2023). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Currently, we always evaluate the model class of an instance when determining applicable permissions. Instead, we should we query for permissions assigned to its concrete model (i.e. `instance._meta.concrete_model`). There are a few places where this adjustment needs to be made. ### Justification Referencing the model directly inhibits the use of [proxy models](https://docs.djangoproject.com/en/4.2/topics/db/models/#proxy-models) in established conventions. For instance, we want to be table to evaluate permissions using a `UserToken` instance to get permissions for its concrete `Token` model.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:36:06 +01:00
adam closed this issue 2025-12-29 20:36:06 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 30, 2023):

Really we should be using get_permission_for_model() everywhere, which has already been updated to do this.

@jeremystretch commented on GitHub (Jul 30, 2023): Really we should be using `get_permission_for_model()` everywhere, which has already been updated to do this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8388