From df71b02e887655125aec0af4826d15b7915043cb Mon Sep 17 00:00:00 2001 From: Ryan Rawdon Date: Mon, 18 Sep 2023 03:47:53 -0400 Subject: [PATCH] Proposed option for #13795, adding module option to hide scripts from user display --- docs/customization/custom-scripts.md | 3 ++- netbox/extras/models/scripts.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/customization/custom-scripts.md b/docs/customization/custom-scripts.md index 3811474d2..b2112fee7 100644 --- a/docs/customization/custom-scripts.md +++ b/docs/customization/custom-scripts.md @@ -42,7 +42,7 @@ Defining script variables is optional: You may create a script with only a `run( Any output generated by the script during its execution will be displayed under the "output" tab in the UI. -By default, scripts within a module are ordered alphabetically in the scripts list page. To return scripts in a specific order, you can define the `script_order` variable at the end of your module. The `script_order` variable is a tuple which contains each Script class in the desired order. Any scripts that are omitted from this list will be listed last. +By default, scripts within a module are ordered alphabetically in the scripts list page. To return scripts in a specific order, you can define the `script_order` variable at the end of your module. The `script_order` variable is a tuple which contains each Script class in the desired order. Any scripts that are omitted from this list will be listed last. To omit scripts from display entirely, define the `script_hide` variable at the end of your module. Scripts listed in this tuple will be ommitted from the unordered script listing. ```python from extras.scripts import Script @@ -54,6 +54,7 @@ class AnotherCustomScript(Script): ... script_order = (MyCustomScript, AnotherCustomScript) +script_hide = (MyHiddenScript,) ``` ## Module Attributes diff --git a/netbox/extras/models/scripts.py b/netbox/extras/models/scripts.py index 122f56f20..f94b895d9 100644 --- a/netbox/extras/models/scripts.py +++ b/netbox/extras/models/scripts.py @@ -67,11 +67,12 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile): scripts = {} ordered = getattr(module, 'script_order', []) + hide = getattr(module, 'script_hide', []) for cls in ordered: scripts[_get_name(cls)] = cls for name, cls in inspect.getmembers(module, is_script): - if cls not in ordered: + if cls not in ordered and cls not in hide: scripts[_get_name(cls)] = cls return scripts