diff --git a/docs/customization/custom-scripts.md b/docs/customization/custom-scripts.md index 3fe44ed88..c2e0620ce 100644 --- a/docs/customization/custom-scripts.md +++ b/docs/customization/custom-scripts.md @@ -18,7 +18,8 @@ They can also be used as a mechanism for validating the integrity of data within Custom scripts are Python code which exists outside the NetBox code base, so they can be updated and changed without interfering with the core NetBox installation. And because they're completely custom, there is no inherent limitation on what a script can accomplish. !!! danger "Only install trusted scripts" - Custom scripts have unrestricted access to change anything in the databse and are inherently unsafe and should only be installed and run from trusted sources. You should also review and set permissions for who can run scripts if the script can modify any data. + Custom scripts have unrestricted access to change anything in the database and are inherently unsafe and should only be installed and run from trusted sources. You should also review and set permissions for who can run scripts if the script can modify any data. + ## Writing Custom Scripts diff --git a/netbox/extras/views.py b/netbox/extras/views.py index fe4513310..5cfacca51 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -1443,12 +1443,16 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View): return 'extras.view_script' def get(self, request): - script_modules = ScriptModule.objects.restrict(request.user).prefetch_related( - 'data_source', 'data_file', 'jobs' + available_scripts = Script.objects.restrict(request.user) + module_ids = {s.module_id for s in available_scripts} + script_modules = ScriptModule.objects.restrict(request.user).filter(pk__in=module_ids).prefetch_related( + 'data_source', 'data_file', ) + context = { 'model': ScriptModule, 'script_modules': script_modules, + 'available_scripts': available_scripts, } # Use partial template for dashboard widgets diff --git a/netbox/templates/extras/inc/script_list_content.html b/netbox/templates/extras/inc/script_list_content.html index 70b77a27b..783d6eac1 100644 --- a/netbox/templates/extras/inc/script_list_content.html +++ b/netbox/templates/extras/inc/script_list_content.html @@ -38,81 +38,83 @@ {% for script in scripts %} - {% with last_job=script.get_latest_jobs|first %} - - - {% if script.is_executable %} - {{ script.python_class.name }} + {% if script in available_scripts %} + {% with last_job=script.get_latest_jobs|first %} + + + {% if script.is_executable %} + {{ script.python_class.name }} + {% else %} + {{ script.python_class.name }} + + + + {% endif %} + + {{ script.python_class.description|markdown|placeholder }} + {% if last_job %} + + {{ last_job.created|isodatetime }} + + + {% badge last_job.get_status_display last_job.get_status_color %} + {% else %} - {{ script.python_class.name }} - - - + {% trans "Never" %} + {{ ''|placeholder }} {% endif %} - - {{ script.python_class.description|markdown|placeholder }} - {% if last_job %} - {{ last_job.created|isodatetime }} - - - {% badge last_job.get_status_display last_job.get_status_color %} - - {% else %} - {% trans "Never" %} - {{ ''|placeholder }} - {% endif %} - - {% if request.user|can_run:script and script.is_executable %} -
-
- {% if script.python_class.commit_default %} - - {% endif %} - {% csrf_token %} - -
-
- {% endif %} - - - {% if last_job and not embedded %} - {% for test_name, data in last_job.data.tests.items %} - - - {{ test_name }} - - - {{ data.success }} - {{ data.info }} - {{ data.warning }} - {{ data.failure }} - - - {% endfor %} - {% elif last_job and not last_job.data.log and not embedded %} - {# legacy #} - {% for method, stats in last_job.data.items %} - - - {{ method }} - - - {{ stats.success }} - {{ stats.info }} - {{ stats.warning }} - {{ stats.failure }} - - - {% endfor %} - {% endif %} - {% endwith %} + {% csrf_token %} + + + + {% endif %} + + + {% if last_job and not embedded %} + {% for test_name, data in last_job.data.tests.items %} + + + {{ test_name }} + + + {{ data.success }} + {{ data.info }} + {{ data.warning }} + {{ data.failure }} + + + {% endfor %} + {% elif last_job and not last_job.data.log and not embedded %} + {# legacy #} + {% for method, stats in last_job.data.items %} + + + {{ method }} + + + {{ stats.success }} + {{ stats.info }} + {{ stats.warning }} + {{ stats.failure }} + + + {% endfor %} + {% endif %} + {% endwith %} + {% endif %} {% endfor %} diff --git a/netbox/users/forms/model_forms.py b/netbox/users/forms/model_forms.py index c1576e6a3..997142aa2 100644 --- a/netbox/users/forms/model_forms.py +++ b/netbox/users/forms/model_forms.py @@ -328,7 +328,7 @@ class ObjectPermissionForm(forms.ModelForm): widget=SplitMultiSelectWidget( choices=get_object_types_choices ), - help_text=_('Select the types of objects to which the permission will appy.') + help_text=_('Select the types of objects to which the permission will apply.') ) can_view = forms.BooleanField( required=False