Enable permission constraints to evaluate attributes across generic relationships #8345

Closed
opened 2025-12-29 20:35:36 +01:00 by adam · 8 comments
Owner

Originally created by @cpmills1975 on GitHub (Jul 19, 2023).

NetBox version

v3.5.6

Feature type

New functionality

Proposed functionality

I'd like the ability to constrain permissions on ContactAssignments, specifically to allow users to edit contact assignments on devices, but only when a device is owned by a specified tenant.

It seems I cannot currently do this as the object to which the contact assignment applies is a GenericForeignKey.

I've been able to craft a suitable filter on contact assignments for devices with a given tenant through the Django shell, but I cannot, I believe, express this as JSON for use in the permissions system

Use case

I'm using ContactAssignments to assign devices to individuals. My NetBox instance contains devices owned by multiple tenants and I've been quite successful in constraining access to these devices using the permissions model and constraining on the tenant field.

I'd now like to roll out the use of contact assignments to my users, but it is important that they can only edit contact assignments on devices where the tenant field matches a specific value.

Database changes

None?

External dependencies

None?

Originally created by @cpmills1975 on GitHub (Jul 19, 2023). ### NetBox version v3.5.6 ### Feature type New functionality ### Proposed functionality I'd like the ability to constrain permissions on ContactAssignments, specifically to allow users to edit contact assignments on devices, but only when a device is owned by a specified tenant. It seems I cannot currently do this as the object to which the contact assignment applies is a GenericForeignKey. I've been able to craft a suitable filter on contact assignments for devices with a given tenant through the Django shell, but I cannot, I believe, express this as JSON for use in the permissions system ### Use case I'm using ContactAssignments to assign devices to individuals. My NetBox instance contains devices owned by multiple tenants and I've been quite successful in constraining access to these devices using the permissions model and constraining on the tenant field. I'd now like to roll out the use of contact assignments to my users, but it is important that they can only edit contact assignments on devices where the tenant field matches a specific value. ### Database changes None? ### External dependencies None?
adam added the type: featurestatus: needs ownerpending closurecomplexity: high labels 2025-12-29 20:35:36 +01:00
adam closed this issue 2025-12-29 20:35:37 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 13, 2023):

Stepping back from the specific use case here, I think the intent is to enable permission constraints to evaluate attributes across generic relationships. As an example, if I try to create a permission for contact assignments using the constraint

{"object__tenant__slug": "dunder-mifflin"}

I receive a validation error:

Invalid filter for <class 'tenancy.models.contacts.ContactAssignment'>: Field 'object' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation.

@jeremystretch commented on GitHub (Oct 13, 2023): Stepping back from the specific use case here, I think the intent is to enable permission constraints to evaluate attributes across generic relationships. As an example, if I try to create a permission for contact assignments using the constraint ```json {"object__tenant__slug": "dunder-mifflin"} ``` I receive a validation error: > Invalid filter for <class 'tenancy.models.contacts.ContactAssignment'>: Field 'object' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation.
Author
Owner

@github-actions[bot] commented on GitHub (Jan 12, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jan 12, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@cpmills1975 commented on GitHub (Jan 12, 2024):

Jeremy’s comment in October is exactly the issue and it would be great if this could be looked at. I’m not sufficiently knowledgeable to be able to suggest a solution here but I’d be shocked if I were the only one who has come across this, especially when working with a large database, many users and a complex permission set.If this issue could remain open, it would be really helpful.On 12 Jan 2024, at 04:01, github-actions[bot] @.***> wrote:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

@cpmills1975 commented on GitHub (Jan 12, 2024): Jeremy’s comment in October is exactly the issue and it would be great if this could be looked at. I’m not sufficiently knowledgeable to be able to suggest a solution here but I’d be shocked if I were the only one who has come across this, especially when working with a large database, many users and a complex permission set.If this issue could remain open, it would be really helpful.On 12 Jan 2024, at 04:01, github-actions[bot] ***@***.***> wrote: This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide. —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
Author
Owner

@jirutka commented on GitHub (Feb 9, 2024):

I’d be shocked if I were the only one who has come across this

You’re not; I just encountered this limitation as well. :(

@jirutka commented on GitHub (Feb 9, 2024): > I’d be shocked if I were the only one who has come across this You’re not; I just encountered this limitation as well. :(
Author
Owner

@nc-td commented on GitHub (May 28, 2024):

I’d be shocked if I were the only one who has come across this

You’re not; I just encountered this limitation as well. :(

Me too, this is certainly desirable

@nc-td commented on GitHub (May 28, 2024): > > I’d be shocked if I were the only one who has come across this > > You’re not; I just encountered this limitation as well. :( Me too, this is certainly desirable
Author
Owner

@jeremystretch commented on GitHub (May 28, 2024):

@jirutka @nc-td could I assign this to one of you for a PR?

@jeremystretch commented on GitHub (May 28, 2024): @jirutka @nc-td could I assign this to one of you for a PR?
Author
Owner

@github-actions[bot] commented on GitHub (Sep 14, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Sep 14, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Oct 14, 2024):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Oct 14, 2024): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8345