Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI URL pattern for scripts to allow a specific script to be accessed by module and class in addition to ID #18024

Closed
atownson opened this issue Nov 15, 2024 · 3 comments · Fixed by #18723
Assignees
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@atownson
Copy link
Contributor

NetBox version

v4.1.6

Feature type

New functionality

Triage priority

I volunteer to perform this work (if approved)

Proposed functionality

Related to #16145, proposing to allow a URL pattern for scripts to reference them by <module>.<class>. The scope of this request is simply to allow this new URL pattern in addition to the existing scripts/<int:pk>/, scripts/<int:pk>/source/, and scripts/<int:pk>/jobs/ patterns. The templates and Script.get_absolute_url() would still reference the pk. The suggested URL pattern should match the allowed pattern for the API resolved in #16145.

Use case

When using Custom Links to link to a specific script, using the pk is problematic because it's subject to change as the scripts are updated over time. By allowing the <module>.<class> pattern, the custom links could be configured to use that pattern and return the correct script.

Database changes

None

External dependencies

None

@atownson atownson added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels Nov 15, 2024
@atownson atownson changed the title Add URL pattern for scripts to allow a specific script to be accessed by module and class in addition to ID Add UI URL pattern for scripts to allow a specific script to be accessed by module and class in addition to ID Nov 15, 2024
@rboucher-me rboucher-me added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation complexity: low Requires minimal effort to implement needs milestone Awaiting prioritization for inclusion with a future NetBox release status: backlog Awaiting selection for work and removed status: needs triage This issue is awaiting triage by a maintainer status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Feb 13, 2025
@ross-cello
Copy link

Ah excellent, have just come across the same issue when evaluating an upgrade from v3.7.8.

Seems it might be a capability regression introduced in v4.0.0.

For us, it breaks navigation on dependent Custom Links, Export Templates and Custom Scripts where URLs are constructed.

I have only just started digging, but comparing the /netbox/extras/urls.py seems to start there.

v4.2.3 (current) /netbox/extras/urls.py [ From Line 74 ]
...
    # Scripts
    path('scripts/', views.ScriptListView.as_view(), name='script_list'),
    path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'),
    path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'),
    path('scripts/<int:pk>/', views.ScriptView.as_view(), name='script'),
    path('scripts/<int:pk>/source/', views.ScriptSourceView.as_view(), name='script_source'),
    path('scripts/<int:pk>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'),
    path('script-modules/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))),
...
v3.7.8 /netbox/extras/urls.py [ From Line 128 ]
...
    # Scripts
    path('scripts/', views.ScriptListView.as_view(), name='script_list'),
    path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'),
    path('scripts/results/<int:job_pk>/', views.ScriptResultView.as_view(), name='script_result'),
    path('scripts/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))),
    path('scripts/<str:module>/<str:name>/', views.ScriptView.as_view(), name='script'), <----- missing
    path('scripts/<str:module>/<str:name>/source/', views.ScriptSourceView.as_view(), name='script_source'), <----- missing
    path('scripts/<str:module>/<str:name>/jobs/', views.ScriptJobsView.as_view(), name='script_jobs'), <----- missing
...

IIRC, the URL path also changed between v2 and v3, from scripts/module.name/ to scripts/module/name/.
We had similar breakages at that point as well, but the URL path was still human readable.

@rrizun
Copy link

rrizun commented Feb 24, 2025

I encountered this exact issue when evaluating an upgrade from 3.7.8 to 4 .. would be great to get the /scripts/module/name url back again!

@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed needs milestone Awaiting prioritization for inclusion with a future NetBox release status: backlog Awaiting selection for work labels Feb 24, 2025
@atownson
Copy link
Contributor Author

I can work on this.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Feb 24, 2025
jeremystretch pushed a commit that referenced this issue Feb 25, 2025
…e.name (#18723)

* Add URL pattern for scripts to reference them by module.name

* Change _get_script function name and syntax

* Fix formatting issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants