Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend customvalidators with user request information #14279

Closed
ITJamie opened this issue Nov 16, 2023 · 4 comments
Closed

Extend customvalidators with user request information #14279

ITJamie opened this issue Nov 16, 2023 · 4 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@ITJamie
Copy link
Contributor

ITJamie commented Nov 16, 2023

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

@ITJamie ITJamie added the type: feature Introduction of new functionality to the application label Nov 16, 2023
@ITJamie
Copy link
Contributor Author

ITJamie commented 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)

@peteeckel
Copy link
Contributor

peteeckel commented 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).

Copy link

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 github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Feb 22, 2024
@jeremystretch
Copy link
Member

jeremystretch commented 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 jeremystretch added status: needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed pending closure Requires immediate attention to avoid being closed for inactivity labels Mar 12, 2024
@jeremystretch jeremystretch added this to the v4.0 milestone Mar 19, 2024
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Mar 19, 2024
@jeremystretch jeremystretch self-assigned this Mar 20, 2024
jeremystretch added a commit that referenced this issue Mar 22, 2024
* Closes #14279: Pass current request to custom validators

* Update custom validation docs

* Check that validator is a subclass of CustomValidator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

3 participants