mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-05 00:47:17 +02:00
Add documentation for custom model actions
- Add plugin development guide for registering custom actions - Update admin permissions docs to mention custom actions UI - Add docstrings to ModelAction and register_model_actions
This commit is contained in:
36
docs/plugins/development/permissions.md
Normal file
36
docs/plugins/development/permissions.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Custom Model Actions
|
||||
|
||||
Plugins can register custom permission actions for their models. These actions appear as checkboxes in the ObjectPermission form, making it easy for administrators to grant or restrict access to plugin-specific functionality without manually entering action names.
|
||||
|
||||
For example, a plugin might define a "sync" action for a model that syncs data from an external source, or a "bypass" action that allows users to bypass certain restrictions.
|
||||
|
||||
## Registering Model Actions
|
||||
|
||||
To register custom actions for a model, call `register_model_actions()` in your plugin's `ready()` method:
|
||||
|
||||
```python
|
||||
# __init__.py
|
||||
from netbox.plugins import PluginConfig
|
||||
|
||||
class MyPluginConfig(PluginConfig):
|
||||
name = 'my_plugin'
|
||||
# ...
|
||||
|
||||
def ready(self):
|
||||
super().ready()
|
||||
from utilities.permissions import ModelAction, register_model_actions
|
||||
from .models import MyModel
|
||||
|
||||
register_model_actions(MyModel, [
|
||||
ModelAction('sync', help_text='Synchronize data from external source'),
|
||||
ModelAction('export', help_text='Export data to external system'),
|
||||
])
|
||||
|
||||
config = MyPluginConfig
|
||||
```
|
||||
|
||||
Once registered, these actions will appear grouped under your model's name when creating or editing an ObjectPermission that includes your model as an object type.
|
||||
|
||||
::: utilities.permissions.ModelAction
|
||||
|
||||
::: utilities.permissions.register_model_actions
|
||||
Reference in New Issue
Block a user