Extend customvalidators with user request information #8846

Closed
opened 2025-12-29 20:42:00 +01:00 by adam · 4 comments
Owner

Originally created by @ITJamie on GitHub (Nov 16, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v.3.6.5

Feature type

Change to existing functionality

Proposed functionality

Extend customvalidators with an additional variable - request user details

Use case

It would be great it customvalidators had a way to check what users are making the request. in some situations, it can make sense to allow one user/usergroup/API integration the ability to skip a specific validation.

for example we wish to use an ipaddress validator to make sure rfc 1918 ip's don't end up in the global vrf, however there is one particular api integration that is going to take quite awhile to update to support vrf lookup's, in the meantime we want to stop any other rfc 1918 ip's getting added to the global vrf. being able to write the validator with an exclusion for a particular user would be great.

I understand that sometimes the supplied user would also need to be None/False as changes from nbshell wouldn't have an attached user.

Database changes

No response

External dependencies

No response

Originally created by @ITJamie on GitHub (Nov 16, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v.3.6.5 ### Feature type Change to existing functionality ### Proposed functionality Extend customvalidators with an additional variable - request user details ### Use case It would be great it customvalidators had a way to check what users are making the request. in some situations, it can make sense to allow one user/usergroup/API integration the ability to skip a specific validation. for example we wish to use an ipaddress validator to make sure rfc 1918 ip's don't end up in the global vrf, however there is one particular api integration that is going to take quite awhile to update to support vrf lookup's, in the meantime we want to stop any other rfc 1918 ip's getting added to the global vrf. being able to write the validator with an exclusion for a particular user would be great. I understand that sometimes the supplied user would also need to be None/False as changes from nbshell wouldn't have an attached user. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:42:00 +01:00
adam closed this issue 2025-12-29 20:42:00 +01:00
Author
Owner

@ITJamie commented on GitHub (Nov 16, 2023):

some examples of integrations that right now don't have vrf support so it would be great to be able to exclude the related user from an rfc1918 validator
plugin: netbox-proxmox
external integration: xoa (it uses the API & has no concept of a vrf)

@ITJamie commented on GitHub (Nov 16, 2023): some examples of integrations that right now don't have vrf support so it would be great to be able to exclude the related user from an rfc1918 validator plugin: netbox-proxmox external integration: xoa (it uses the API & has no concept of a vrf)
Author
Owner

@peteeckel commented on GitHub (Nov 23, 2023):

Thanks! I support that and suggest extending the concept to the new PROTECTION_RULES feature to be introduced with version 3.7 (#14097).

@peteeckel commented on GitHub (Nov 23, 2023): Thanks! I support that and suggest extending the concept to the new `PROTECTION_RULES` feature to be introduced with version 3.7 (#14097).
Author
Owner

@github-actions[bot] commented on GitHub (Feb 22, 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 (Feb 22, 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

@jeremystretch commented on GitHub (Mar 12, 2024):

Historically this has not been possible as custom validators are processed via the post_clean signal, and signal handlers have no direct access to the request being processed. However, I believe this is now feasible with the somewhat recent introduce of the current_request context variable, which can be referenced fro inside the signal receiver.

Also, the CustomValidator class will need to be extended to support the inclusion of request context in addition to the object itself.

@jeremystretch commented on GitHub (Mar 12, 2024): Historically this has not been possible as custom validators are processed via the `post_clean` signal, and signal handlers have no direct access to the request being processed. However, I believe this is now feasible with the somewhat recent introduce of the [`current_request`](https://github.com/netbox-community/netbox/blob/51b2bcf264723f1752438b0448049ba50f9feb87/netbox/netbox/context.py#L9) context variable, which can be referenced fro inside the signal receiver. Also, the `CustomValidator` class will need to be extended to support the inclusion of request context in addition to the object itself.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8846