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

Add custom validation functionality for the models' delete method #10244

Closed
atownson opened this issue Sep 1, 2022 · 12 comments
Closed

Add custom validation functionality for the models' delete method #10244

atownson opened this issue Sep 1, 2022 · 12 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@atownson
Copy link
Contributor

atownson commented Sep 1, 2022

NetBox version

v3.3.1

Feature type

New functionality

Proposed functionality

NetBox's extensible custom validation is a very nice feature which allows users to inject their own business-specific logic into the models' create and update methods. I'm proposing to add the same functionality to the delete method.

Use case

Users would be able to add their own logic to ensure instantiated models are not unintentionally deleted or to better control cascading effects of a delete. One example use case would be to ensure no IP addresses are assigned to a device's or virtual machine's interfaces before deleting either the device/VM or one of its interfaces. In our deployment of NetBox we track a good bit of metadata associated with IP addresses (such as NATs, ICMP polling status, and monitoring flags) and typically assign already created IPs to interfaces rather than creating them when assigning them.

Database changes

None

External dependencies

None

@atownson atownson added the type: feature Introduction of new functionality to the application label Sep 1, 2022
@jeremystretch
Copy link
Member

Interesting idea. We could probably implement this by hooking into the pre_delete signal to run validation. But how should we differentiate save and deletion validation rules? (Presumably they're likely to be different.)

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Sep 1, 2022
@atownson
Copy link
Contributor Author

atownson commented Sep 1, 2022

I would differentiate the two by their configuration parameter names based on their respective roles.
If you were to prioritize ease of migration, you might just add the configuration parameter DELETE_CUSTOM_VALIDATORS.
If you were to prioritize the intuitiveness of the parameter names, you might migrate CUSTOM_VALIDATORS to CREATE_CUSTOM_VALIDATORS and add DELETE_CUSTOM_VALIDATORS. And perhaps even assume CUSTOM_VALIDATORS means CREATE_CUSTOM_VALIDATORS for legacy configuration settings.
Just my thoughts.

@jeremystretch
Copy link
Member

Maybe we call them something like "protection rules" instead, and just use the same configuration format that we do for validators.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2022

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 Nov 1, 2022
@kkthxbye-code kkthxbye-code added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation pending closure Requires immediate attention to avoid being closed for inactivity labels Nov 1, 2022
@kkthxbye-code
Copy link
Contributor

I think this would be a good addition. Open to any contributors, otherwise I'll pick it up when I get time.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2023

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 Jan 1, 2023
@jeremystretch
Copy link
Member

I'm going to tag this as needs milestone; hopefully we can get to it in a future release.

@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation pending closure Requires immediate attention to avoid being closed for inactivity labels Jan 24, 2023
@BarbarossaTM
Copy link
Contributor

Love this! This would be very handy for us so only devices in a certain status could be deleted (we've introduced Disposed in our life cycle).

@pv2b
Copy link
Contributor

pv2b commented Sep 8, 2023

Hi!

I'd be interested to volunteer on implementing this, it seems like a small, self-contained feature and straight-forward enough. But it's set as "needs milestone", I'm not sure what that means in the context of this project?

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Oct 13, 2023
@jeremystretch jeremystretch added this to the v3.7 milestone Oct 13, 2023
@jeremystretch
Copy link
Member

@pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the feature branch.)

@pv2b
Copy link
Contributor

pv2b commented Oct 25, 2023

@pv2b I've just tagged this for the upcoming v3.7 release if you'd like to work on it. (Please base your work on the feature branch.)

I'll be happy to work on this, but I'd like to see some progress on my other PR's on this project for work on accepted bug fixes before I do. I don't want to add too much to the projects backlog of pull requests.

@jeremystretch
Copy link
Member

@pv2b I've already completed work on this, thanks though.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

5 participants