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

Allow Custom Validators to prevent object deletion #13718

Closed
pv2b opened this issue Sep 8, 2023 · 2 comments
Closed

Allow Custom Validators to prevent object deletion #13718

pv2b opened this issue Sep 8, 2023 · 2 comments
Labels
type: feature Introduction of new functionality to the application

Comments

@pv2b
Copy link
Contributor

pv2b commented Sep 8, 2023

NetBox version

v3.6.1

Feature type

New functionality

Proposed functionality

I propose an extension of the Custom Validators functionality to allow a NetBox administrator to prevent object deletion under certain criteria.

An example of how this would look would be the below pseudocode. (The example probably won't work exactly as listed, I'm just making up the way to count connected cables, and if it's right it's just an accident, but this is to show the idea.)

class PreventDeletingCabledDevicesValidator(CustomValidator):
    def validate_delete(self, instance):
        cable_count = len(instance.cables)
        if cable_count > 0:
            self.fail(f"Device still has {cable_count} cables connected to it!")

The example would prevent deleting devices that are cabled.

Implementation wise, this would happen though an overridable validate_delete() method added to the CustomValidator class which would be called prior to object deletion. Any spots in the code that perform deletion of objects would have to be identified and this hook added, hopefully there's some good chokepoint to add it to.

Use case

Deleting an object can have wide-ranging consequences in NetBox and can easilly happen accidentally. That accidental deletion is a concern is evidenced by previous Feature Request #13690. I have personally accidentally deleted an important object and caused myself an hour and a half of pain in re-creating that deleted object along with all its cable connections.

Additionally, business rules might be in place to prevent the deletion of objects under certain criteria. For example, a business rule might be that circuits or devices may not be deleted from a system if they're still active. The Permissions system might be able to do something similar (I haven't really checked) but that doesn't allow superuser actions to be validated, and that doesn't allow for custom code anyway. Or some organizations might not want to allow device deletion at all in order to keep a permanent record of scrapped devices. Anyway, you see, there's a lot of things you could do that would be for the administrator to decide.

In my opinion the inclusion of a hook like this into NetBox is a fairly small and unopinionated change that lets administrators set their own policy regarding object deletions in NetBox. It's also a natural extension of the Custom Validators functionality, covering a gap in its current functionality.

Database changes

No database changes are required. Custom validators live in configuration and code only.

External dependencies

No external dependencies are required.

@pv2b pv2b added the type: feature Introduction of new functionality to the application label Sep 8, 2023
@jeremystretch
Copy link
Member

This seems like a duplicate of #10244.

@pv2b
Copy link
Contributor Author

pv2b commented Sep 8, 2023

This seems like a duplicate of #10244.

Yeah, I agree, it's looks like a dupe. I didn't find it when doing a quick search. Since the other FR is close enough to what I wanted to do, I'll close this one for now.

@pv2b pv2b closed this as completed Sep 8, 2023
@pv2b pv2b closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants