Refactor actions declarations for ObjectListView #6608

Closed
opened 2025-12-29 19:43:03 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (Jun 29, 2022).

Proposed Changes

ObjectListView currently has two attributes related to permitted actions: actions (a tuple of action names) and action_perms (a dictionary mapping these names to required permissions. By default, these are:

actions = ('add', 'import', 'export', 'bulk_edit', 'bulk_delete')
action_perms = defaultdict(set, **{
    'add': {'add'},
    'import': {'add'},
    'bulk_edit': {'change'},
    'bulk_delete': {'delete'},
})

The proposal here is to merge these into a single dictionary named actions, i.e.:

actions = defaultdict(set, **{
    'add': {'add'},
    'import': {'add'},
    'export': {},
    'bulk_edit': {'change'},
    'bulk_delete': {'delete'},
})

Actions which do not require any permissions map to an empty set.

Justification

This approach simplifies the declaration of actions and their required permissions.

Originally created by @jeremystretch on GitHub (Jun 29, 2022). ### Proposed Changes ObjectListView currently has two attributes related to permitted actions: `actions` (a tuple of action names) and `action_perms` (a dictionary mapping these names to required permissions. By default, these are: ```python actions = ('add', 'import', 'export', 'bulk_edit', 'bulk_delete') action_perms = defaultdict(set, **{ 'add': {'add'}, 'import': {'add'}, 'bulk_edit': {'change'}, 'bulk_delete': {'delete'}, }) ``` The proposal here is to merge these into a single dictionary named `actions`, i.e.: ```python actions = defaultdict(set, **{ 'add': {'add'}, 'import': {'add'}, 'export': {}, 'bulk_edit': {'change'}, 'bulk_delete': {'delete'}, }) ``` Actions which do not require any permissions map to an empty set. ### Justification This approach simplifies the declaration of actions and their required permissions.
adam added the type: housekeepingtopic: plugins labels 2025-12-29 19:43:03 +01:00
adam closed this issue 2025-12-29 19:43:03 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 29, 2022):

Disregard; we did it this way specifically to allow a view to declare a subset of actions without having to redefine the permission mappings.

@jeremystretch commented on GitHub (Jun 29, 2022): Disregard; we did it this way specifically to allow a view to declare a subset of actions without having to redefine the permission mappings.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6608