Kani999 / netbox-attachments

Plugin to manage attachments for any model
Apache License 2.0
54 stars 4 forks source link

[Feature] Limit attachments to specific models #64

Open llamafilm opened 1 month ago

llamafilm commented 1 month ago

Hello! I'd like to allow attachments only on Device Types. I don't want users to be able to add attachments to Devices. My primary use case is datasheets, and I'm afraid that if users are able to add in both places, they will make mistakes.

Kani999 commented 1 month ago

I'll take a look on how to extend the PLUGIN_CONFIG to support specifying certain models.

PLUGINS_CONFIG = {
    'netbox_attachments': {
        'apps': ['dcim', 'ipam', 'circuits', 'tenancy', 'virtualization', 'wireless', 'inventory_monitor'],
        'display_default': "right_page",
        'display_setting': {'ipam.vlan': "left_page", 'dcim.device': "full_width_page", 'dcim.devicerole': "full_width_page", 'inventory_monitor.probe': "additional_tab"}
    }
}
matejv commented 1 month ago

That would be a useful feature for us as well.

I have figured out a workaround: if you set display_setting to some unsupported value for models you want hidden, it won't show on GUI. This won't prevent adding attachments via some other methods (like from scripts or via API), but is good enough for us.

Example config:

PLUGINS_CONFIG = {
    'netbox_attachments': {
        'apps': ['dcim',],
        'display_setting': {
            'dcim.devicetype': "full_width_page",
            'dcim.device': "hidden",
        },
    },

You'll have to list all models under dcim you want to hide attachments from unfortunately.