Compare commits

..

58 Commits

Author SHA1 Message Date
Jeremy Stretch
cca1b0a897 Merge pull request #16132 from netbox-community/develop
Release v4.0.2
2024-05-14 11:20:56 -04:00
Jeremy Stretch
70c0aec53a Release v4.0.2 2024-05-14 11:02:17 -04:00
Jeremy Stretch
beb9b96395 Changelog for #16096, #16107, #16123, #16124, #16127 2024-05-14 10:35:00 -04:00
Jeremy Stretch
e5ab48e3c5 Fixes #16123: Fix custom script execution via REST API 2024-05-14 10:31:55 -04:00
Jeremy Stretch
c95dd0b4d1 Update translations 2024-05-14 09:30:28 -04:00
Jeremy Stretch
34f8bf7caf Update source strings for translations 2024-05-14 09:22:27 -04:00
Anton
1feb3742e2 add ENABLE_TRANSLATION setting to optionally turn translation off (#16096)
* add USE_I18N setting

* change setting name to ENABLE_TRANSLATION

* raise a warning in the UI when translation is disabled

* Misc cleanup

* Rename to TRANSLATION_ENABLED for consistency with other settings

---------

Co-authored-by: Anton Myasnikov <anton.myasnikov@nordigy.ru>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-14 09:21:00 -04:00
Jeremy Stretch
829bae6b29 Fixes #16124: Fix GraphQL API support for querying virtual machine interfaces 2024-05-14 09:15:57 -04:00
Jeremy Stretch
fcc8eccb6c Closes #16127: Enable loading local settings 2024-05-14 09:14:40 -04:00
Jeremy Stretch
c117218332 Fix permissions for stalebot (see actions/stale #1131) 2024-05-14 08:20:31 -04:00
Jeremy Stretch
b8a8db09ed Closes #16107: Set LOGIN_REQUIRED to True by default (#16122)
* Closes #16107: Set LOGIN_REQUIRED to True by default

* Update tests
2024-05-14 07:53:19 -04:00
Jeremy Stretch
b67eda403a Changelog for #15119, #16077, #16078, #16090, #16101 2024-05-13 19:15:40 -04:00
Arthur Hanson
b291aa4312 16078 make GraphQL NumberFilter optional (#16115)
* 16078 make GraphQL NumberFilter optional

* 16078 add tests for graphql filtering

* 16078 add tests for graphql filtering

* 16078 add tests for graphql filtering
2024-05-13 19:01:30 -04:00
Jeremy Stretch
e6ccea0168 Refactor & expand search view tests 2024-05-13 18:56:44 -04:00
Jeremy Stretch
a20ccfee7e Update queryset resolution methods for compatibility with Django 5.0 2024-05-13 18:56:44 -04:00
Jeremy Stretch
c7850b586b Fixes #16101: Fix initial loading of pagination widget for dynamic object tables 2024-05-13 18:55:13 -04:00
Jeremy Stretch
e0f138dea2 Closes #16070: Set default template for ObjectChildrenView 2024-05-13 15:21:52 -04:00
Arthur
5be14b0ee2 16110 fix typo 2024-05-13 15:20:33 -04:00
Julio-Oliveira-Encora
dffd52d6b0 Added Cluster category and cluster, cluster_group for VLAN Group filters. 2024-05-13 15:16:01 -04:00
Markku Leiniö
4b91e79d1e Closes #16090: Show NetBox version if plugin validation fails (#16094)
* Closes #16090: Show NetBox version if plugin validation fails

* Shorten error message

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-13 09:37:40 -04:00
Arthur
111cbe5b7c 16077 fix display of config revision 2024-05-13 09:33:30 -04:00
Jeremy Stretch
4a64a3f6e0 PRVB 2024-05-09 16:03:13 -04:00
Jeremy Stretch
a3f7dc0423 Merge pull request #16072 from netbox-community/develop
Release v4.0.1
2024-05-09 16:02:03 -04:00
Jeremy Stretch
ab62f416de Merge branch 'master' into develop 2024-05-09 15:48:45 -04:00
Jeremy Stretch
9cd0a0d872 Release v4.0.1 2024-05-09 15:41:20 -04:00
Jeremy Stretch
d847f02434 Correct link 2024-05-09 15:39:48 -04:00
Arthur Hanson
8d11f8aa7c 14121 update plugin development docs for pyproject.toml (#15952)
* 14121 update plugin development docs for pyproject.toml

* 14121 review feedback

* Update docs/plugins/development/index.md

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>

* 14121 remove setup.py references

* 14121 add cookiecutter reference

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-09 15:06:19 -04:00
Jeremy Stretch
9d4932b221 Fixes #16061: Omit hidden fields from event rule form 2024-05-09 15:01:53 -04:00
Abhimanyu Saharan
e438ddb405 Adds 2.5 and 10g (#16068)
* adds 2.5 and 10g #15451

* Tweak constant names for consistency w/peers

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-09 14:58:24 -04:00
Arthur Hanson
a953ff20f9 15973 fix switch type on cable edit (#16049)
* 15973 fix switch type on cable edit

* 15973 fix cable add from device
2024-05-09 14:54:38 -04:00
Abhimanyu Saharan
08923d77d1 adds vms tab on device object view #15328 2024-05-09 14:33:31 -04:00
Markku Leiniö
2a06e1990a Closes #16056: Add binary-path configuration in uwsgi.ini 2024-05-09 13:11:11 -04:00
Jeremy Stretch
9f940150fc Closes #16010: Enable Prometheus middleware only if metrics are enabled 2024-05-09 10:47:33 -04:00
Jeremy Stretch
e055e0a222 Fixes #15968: Avoid resizing quick search field to display clear button 2024-05-09 10:46:41 -04:00
teapot
f40fb6a707 Fixes #16051: Wrap empty_text with gettext_lazy() 2024-05-09 08:09:53 -04:00
Arthur Hanson
1a56e8e23b 15148 add copy button to config context (#15954)
* 15148 add copy button to config context

* Merge configcontext_format.html into configcontext_data.html

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-09 08:06:53 -04:00
Markku Leiniö
0cc2963e6f Closes #16043: Add 'die-on-term = true' to fix stopping uWSGI (#16045)
* Closes #16043: Add 'die-on-term = true' to fix stopping uWSGI

* Fix spelling
2024-05-08 14:51:54 -04:00
Arthur Hanson
56ea7b8714 16014 Update incorrect django-graphene reference and add link to filtering docs. (#16015)
* 16014 change ref from django-graphene to django-strawberry

* 16014 add references to filtering syntax

* 16014 remove graphene reference

* 16014 remove graphene reference

* Remove obsolete reference to Graphene

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-05-08 14:29:54 -04:00
Jeremy Stretch
6e658d43dc #15999: Additional cleanup 2024-05-08 14:06:48 -04:00
Arnold
6ff349dbac Putting field labels above fields 2024-05-08 14:06:04 -04:00
Daniel Sheppard
d7d97b1b52 Return an empty dict if the module cannot be loaded 2024-05-08 13:29:39 -04:00
Markku Leiniö
d7f652bcc7 Closes #16034: Disable uWSGI logging 2024-05-08 12:02:23 -04:00
Jeremy Stretch
313b6e624c Remove duplicate column definition from ReportResultsTable 2024-05-08 11:59:36 -04:00
Arthur
0df3787796 16031 make script result message display markdown 2024-05-08 11:43:20 -04:00
Jeremy Stretch
5c68fc9202 Fixes #16020: Include Python version on system UI view 2024-05-08 10:35:38 -04:00
Jeremy Stretch
ff8dabe8d9 Fixes #16025: Fix execution of scripts via the runscript management command 2024-05-08 10:30:47 -04:00
Markku Leiniö
5c5c0e1e43 Fixes #16032: Specify the WSGI module to load in uwsgi.ini 2024-05-08 10:28:35 -04:00
Jeremy Stretch
b87d1eca98 Fixes #16016: Correct typo 2024-05-08 10:15:43 -04:00
teapot
db823634cf Fixes #16027: Correct typo in error message 2024-05-08 09:42:20 -04:00
Jeremy Stretch
195dbaed00 Fixes #16017: Bump Django to 5.0.6 2024-05-07 21:33:13 -04:00
Jeremy Stretch
a9a012daf0 Fixes #16011: Fix site tenant assignment by PK via REST API 2024-05-07 16:35:11 -04:00
Jeremy Stretch
4d40699f2c Fixes #15995: Permit nullable fields referenced by unique constraints to be omitted from REST API requests 2024-05-07 15:33:14 -04:00
Jeremy Stretch
ccf32244d3 Fixes #16003: Enable cache busting on upgrade for setmode.js 2024-05-07 11:10:19 -04:00
Jeremy Stretch
9316f48a20 Fixes #15982: Restore the "assign IP" tab 2024-05-07 10:43:49 -04:00
Jeremy Stretch
acc2add845 Fixes #15977: Hide all admin menu items for non-authenticated users (#15978)
* Fixes #15977: Hide all admin menu items for non-authenticated users

* Account for absence of auth_required on PluginMenuItem
2024-05-07 10:37:42 -04:00
Tobias Genannt
b4486b4d30 Fix #15992: Removed integrations for sentry-sdk
According to the Sentry Python SDK documentation setting the
integrations manually is only needed when the integration configuration
needs to be changed.

See: https://docs.sentry.io/platforms/python/integrations/django/#options
2024-05-07 09:11:36 -04:00
Jeremy Stretch
d7592744d4 Update supported Python versions for v4.0 2024-05-06 16:41:16 -04:00
Jeremy Stretch
fbcec97328 PRVB 2024-05-06 15:28:43 -04:00
92 changed files with 2545 additions and 2277 deletions

View File

@@ -26,7 +26,7 @@ body:
attributes:
label: NetBox Version
description: What version of NetBox are you currently running?
placeholder: v4.0.0
placeholder: v4.0.2
validations:
required: true
- type: dropdown
@@ -34,10 +34,9 @@ body:
label: Python Version
description: What version of Python are you currently running?
options:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
validations:
required: true
- type: textarea

View File

@@ -14,7 +14,7 @@ body:
attributes:
label: NetBox version
description: What version of NetBox are you currently running?
placeholder: v4.0.0
placeholder: v4.0.2
validations:
required: true
- type: dropdown

View File

@@ -7,6 +7,7 @@ on:
workflow_dispatch:
permissions:
actions: write
issues: write
pull-requests: write

View File

@@ -131,7 +131,7 @@ social-auth-app-django
strawberry-graphql
# Strawberry GraphQL Django extension
# https://github.com/strawberry-graphql/strawberry-django/blob/main/CHANGELOG.md
# https://github.com/strawberry-graphql/strawberry-django/releases
strawberry-graphql-django
# SVG image rendering (used for rack elevations)

View File

@@ -353,6 +353,8 @@
"800gbase-x-qsfpdd",
"800gbase-x-osfp",
"1000base-kx",
"2.5gbase-kx",
"5gbase-kr",
"10gbase-kr",
"10gbase-kx4",
"25gbase-kr",

View File

@@ -11,8 +11,24 @@ master = true
; clear environment on exit
vacuum = true
; make SIGTERM stop the app (instead of reload)
die-on-term = true
; exit if no app can be loaded
need-app = true
; do not use multiple interpreters
single-interpreter = true
; change to the project directory
chdir = netbox
; specify the WSGI module to load
module = netbox.wsgi
; workaround to make uWSGI reloads work with pyuwsgi (not to be used if using uwsgi package instead)
binary-path = venv/bin/python
; only log internal messages and errors (reverse proxy already logs the requests)
disable-logging = true
log-5xx = true

View File

@@ -159,9 +159,12 @@ Note that enabling this setting causes NetBox to update a user's session in the
## LOGIN_REQUIRED
Default: False
Default: True
Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users are permitted to access most data in NetBox but not make any changes.
When enabled, only authenticated users are permitted to access any part of NetBox. Disabling this will allow unauthenticated users to access most areas of NetBox (but not make any changes).
!!! info "Changed in NetBox v4.0.2"
Prior to NetBox v4.0.2, this setting was disabled by default.
---

View File

@@ -198,3 +198,11 @@ If `STORAGE_BACKEND` is not defined, this setting will be ignored.
Default: UTC
The time zone NetBox will use when dealing with dates and times. It is recommended to use UTC time unless you have a specific need to use a local time zone. Please see the [list of available time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
---
## TRANSLATION_ENABLED
Default: True
Enables language translation for the user interface. (This parameter maps to Django's [USE_I18N](https://docs.djangoproject.com/en/stable/ref/settings/#std-setting-USE_I18N) setting.)

View File

@@ -77,7 +77,7 @@ Create the following for each model:
## 13. GraphQL API components
Create a Graphene object type for the model in `graphql/types.py` by subclassing the appropriate class from `netbox.graphql.types`.
Create a GraphQL object type for the model in `graphql/types.py` by subclassing the appropriate class from `netbox.graphql.types`.
Also extend the schema class defined in `graphql/schema.py` with the individual object and object list fields per the established convention.

View File

@@ -72,7 +72,7 @@ In cases where upgrading a dependency to its most recent release is breaking, it
### Update UI Dependencies
Check whether any UI dependencies (JavaScript packages, fonts, etc.) need to be updated by running `yarn outdated` from within the `project-static/` directory. [Upgrade these dependencies](http://0.0.0.0:9000/development/web-ui/#updating-dependencies) as necessary, then run `yarn bundle` to generate the necessary files for distribution.
Check whether any UI dependencies (JavaScript packages, fonts, etc.) need to be updated by running `yarn outdated` from within the `project-static/` directory. [Upgrade these dependencies](./web-ui.md#updating-dependencies) as necessary, then run `yarn bundle` to generate the necessary files for distribution.
### Rebuild the Device Type Definition Schema

View File

@@ -17,7 +17,7 @@ pip3 install pyuwsgi
Once installed, add the package to `local_requirements.txt` to ensure it is re-installed during future rebuilds of the virtual environment:
```no-highlight
sudo sh -c "echo 'pyuwgsi' >> /opt/netbox/local_requirements.txt"
sudo sh -c "echo 'pyuwsgi' >> /opt/netbox/local_requirements.txt"
```
## Configuration

View File

@@ -1,6 +1,6 @@
# GraphQL API Overview
NetBox provides a read-only [GraphQL](https://graphql.org/) API to complement its REST API. This API is powered by the [Graphene](https://graphene-python.org/) library and [Graphene-Django](https://docs.graphene-python.org/projects/django/en/latest/).
NetBox provides a read-only [GraphQL](https://graphql.org/) API to complement its REST API. This API is powered by [Strawberry Django](https://strawberry-graphql.github.io/strawberry-django/).
## Queries
@@ -47,7 +47,7 @@ NetBox provides both a singular and plural query field for each object type:
For example, query `device(id:123)` to fetch a specific device (identified by its unique ID), and query `device_list` (with an optional set of filters) to fetch all devices.
For more detail on constructing GraphQL queries, see the [Graphene documentation](https://docs.graphene-python.org/en/latest/) as well as the [GraphQL queries documentation](https://graphql.org/learn/queries/).
For more detail on constructing GraphQL queries, see the [GraphQL queries documentation](https://graphql.org/learn/queries/). For filtering and lookup syntax, please refer to the [Strawberry Django documentation](https://strawberry-graphql.github.io/strawberry-django/guide/filters/).
## Filtering

View File

@@ -2,7 +2,7 @@
## Defining the Schema Class
A plugin can extend NetBox's GraphQL API by registering its own schema class. By default, NetBox will attempt to import `graphql.schema` from the plugin, if it exists. This path can be overridden by defining `graphql_schema` on the PluginConfig instance as the dotted path to the desired Python class. This class must be a subclass of `graphene.ObjectType`.
A plugin can extend NetBox's GraphQL API by registering its own schema class. By default, NetBox will attempt to import `graphql.schema` from the plugin, if it exists. This path can be overridden by defining `graphql_schema` on the PluginConfig instance as the dotted path to the desired Python class.
### Example

View File

@@ -55,18 +55,20 @@ project-name/
- template_content.py
- urls.py
- views.py
- pyproject.toml
- README.md
- setup.py
```
The top level is the project root, which can have any name that you like. Immediately within the root should exist several items:
* `setup.py` - This is a standard installation script used to install the plugin package within the Python environment.
* `pyproject.toml` - is a standard configuration file used to install the plugin package within the Python environment.
* `README.md` - A brief introduction to your plugin, how to install and configure it, where to find help, and any other pertinent information. It is recommended to write `README` files using a markup language such as Markdown to enable human-friendly display.
* The plugin source directory. This must be a valid Python package name, typically comprising only lowercase letters, numbers, and underscores.
The plugin source directory contains all the actual Python code and other resources used by your plugin. Its structure is left to the author's discretion, however it is recommended to follow best practices as outlined in the [Django documentation](https://docs.djangoproject.com/en/stable/intro/reusable-apps/). At a minimum, this directory **must** contain an `__init__.py` file containing an instance of NetBox's `PluginConfig` class, discussed below.
**Note:** The [Cookiecutter NetBox Plugin](https://github.com/netbox-community/cookiecutter-netbox-plugin) can be used to auto-generate all the needed directories and files for a new plugin.
## PluginConfig
The `PluginConfig` class is a NetBox-specific wrapper around Django's built-in [`AppConfig`](https://docs.djangoproject.com/en/stable/ref/applications/) class. It is used to declare NetBox plugin functionality within a Python package. Each plugin should provide its own subclass, defining its name, metadata, and default and required configuration parameters. An example is below:
@@ -136,31 +138,48 @@ Apps from this list are inserted *before* the plugin's `PluginConfig` in the ord
Any additional apps must be installed within the same Python environment as NetBox or `ImproperlyConfigured` exceptions will be raised when loading the plugin.
## Create setup.py
## Create pyproject.toml
`setup.py` is the [setup script](https://docs.python.org/3.10/distutils/setupscript.html) used to package and install our plugin once it's finished. The primary function of this script is to call the setuptools library's `setup()` function to create a Python distribution package. We can pass a number of keyword arguments to control the package creation as well as to provide metadata about the plugin. An example `setup.py` is below:
`pyproject.toml` is the [configuration file](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) used to package and install our plugin once it's finished. It is used by packaging tools, as well as other tools. The primary function of this file is to call the build system to create a Python distribution package. We can pass a number of keyword arguments to control the package creation as well as to provide metadata about the plugin. There are three possible TOML tables in this file:
```python
from setuptools import find_packages, setup
* `[build-system]` allows you to declare which build backend you use and which other dependencies (if any) are needed to build your project.
* `[project]` is the format that most build backends use to specify your projects basic metadata, such as the author's name, project URL, etc.
* `[tool]` has tool-specific subtables, e.g., `[tool.black]`, `[tool.mypy]`. Consult the particular tools documentation for reference.
An example `pyproject.toml` is below:
```
# See PEP 518 for the spec of this file
# https://www.python.org/dev/peps/pep-0518/
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "my-example-plugin"
version = "0.1.0"
authors = [
{name = "John Doe", email = "test@netboxlabs.com"},
]
description = "An example NetBox plugin."
readme = "README.md"
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Natural Language :: English',
"Programming Language :: Python :: 3 :: Only",
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
]
requires-python = ">=3.10.0"
setup(
name='my-example-plugin',
version='0.1',
description='An example NetBox plugin',
url='https://github.com/jeremystretch/my-example-plugin',
author='Jeremy Stretch',
license='Apache 2.0',
install_requires=[],
packages=find_packages(),
include_package_data=True,
zip_safe=False,
)
```
Many of these are self-explanatory, but for more information, see the [setuptools documentation](https://setuptools.readthedocs.io/en/latest/setuptools.html).
!!! info
`zip_safe=False` is **required** as the current plugin iteration is not zip safe due to upstream python issue [issue19699](https://bugs.python.org/issue19699)
Many of these are self-explanatory, but for more information, see the [pyproject.toml documentation](https://packaging.python.org/en/latest/specifications/pyproject-toml/).
## Create a Virtual Environment
@@ -178,11 +197,12 @@ echo /opt/netbox/netbox > $VENV/lib/python3.10/site-packages/netbox.pth
## Development Installation
To ease development, it is recommended to go ahead and install the plugin at this point using setuptools' `develop` mode. This will create symbolic links within your Python environment to the plugin development directory. Call `setup.py` from the plugin's root directory with the `develop` argument (instead of `install`):
To ease development, it is recommended to go ahead and install the plugin at this point using setuptools' `develop` mode. This will create symbolic links within your Python environment to the plugin development directory. Call `pip` from the plugin's root directory with the `-e` flag:
```no-highlight
$ python setup.py develop
$ pip install -e .
```
More information on editable builds can be found at [Editable installs for pyproject.toml ](https://peps.python.org/pep-0660/).
## Configure NetBox

View File

@@ -1,5 +1,57 @@
# NetBox v4.0
## v4.0.2 (2024-05-14)
!!! warning "Important"
This release includes an important security fix, and is a strongly recommended update for all users. More details will follow.
### Enhancements
* [#15119](https://github.com/netbox-community/netbox/issues/15119) - Add cluster & cluster group UI filter fields for VLAN groups
* [#16090](https://github.com/netbox-community/netbox/issues/16090) - Include current NetBox version when an unsupported plugin is detected
* [#16096](https://github.com/netbox-community/netbox/issues/16096) - Introduce the `ENABLE_TRANSLATION` configuration parameter
* [#16107](https://github.com/netbox-community/netbox/issues/16107) - Change the default value for `LOGIN_REQUIRED` to True
* [#16127](https://github.com/netbox-community/netbox/issues/16127) - Add integration point for unsupported settings
### Bug Fixes
* [#16077](https://github.com/netbox-community/netbox/issues/16077) - Fix display of parameter values when viewing configuration revisions
* [#16078](https://github.com/netbox-community/netbox/issues/16078) - Fix integer filters mistakenly marked as required for GraphQL API
* [#16101](https://github.com/netbox-community/netbox/issues/16101) - Fix initial loading of pagination widget for dynamic object tables
* [#16123](https://github.com/netbox-community/netbox/issues/16123) - Fix custom script execution via REST API
* [#16124](https://github.com/netbox-community/netbox/issues/16124) - Fix GraphQL API support for querying virtual machine interfaces
---
## v4.0.1 (2024-05-09)
### Enhancements
* [#15148](https://github.com/netbox-community/netbox/issues/15148) - Add copy-to-clipboard button for config context data
* [#15328](https://github.com/netbox-community/netbox/issues/15328) - Add a virtual machines UI tab for host devices
* [#15451](https://github.com/netbox-community/netbox/issues/15451) - Add 2.5 and 5 Gbps backplane Ethernet interface types
* [#16010](https://github.com/netbox-community/netbox/issues/16010) - Enable Prometheus middleware only if metrics are enabled
### Bug Fixes
* [#15968](https://github.com/netbox-community/netbox/issues/15968) - Avoid resizing quick search field to display clear button
* [#15973](https://github.com/netbox-community/netbox/issues/15973) - Fix AttributeError exception when modifying cable termination type
* [#15977](https://github.com/netbox-community/netbox/issues/15977) - Hide all admin menu items for non-authenticated users
* [#15982](https://github.com/netbox-community/netbox/issues/15982) - Restore the "assign IP" tab for assigning existing IP addresses to interfaces
* [#15992](https://github.com/netbox-community/netbox/issues/15992) - Fix AttributeError exception when Sentry integration is enabled
* [#15995](https://github.com/netbox-community/netbox/issues/15995) - Permit nullable fields referenced by unique constraints to be omitted from REST API requests
* [#15999](https://github.com/netbox-community/netbox/issues/15999) - Fix layout of login form labels for certain languages
* [#16003](https://github.com/netbox-community/netbox/issues/16003) - Enable cache busting for `setmode.js` asset to avoid breaking dark mode support on upgrade
* [#16011](https://github.com/netbox-community/netbox/issues/16011) - Fix site tenant assignment by PK via REST API
* [#16020](https://github.com/netbox-community/netbox/issues/16020) - Include Python version in system UI view
* [#16022](https://github.com/netbox-community/netbox/issues/16022) - Fix database migration failure when encountering a script module which no longer exists on disk
* [#16025](https://github.com/netbox-community/netbox/issues/16025) - Fix execution of scripts via the `runscript` management command
* [#16031](https://github.com/netbox-community/netbox/issues/16031) - Render Markdown content in script log messages
* [#16051](https://github.com/netbox-community/netbox/issues/16051) - Translate "empty" text for object tables
* [#16061](https://github.com/netbox-community/netbox/issues/16061) - Omit hidden fields from display within event rule edit form
---
## v4.0.0 (2024-05-06)
!!! tip "Plugin Maintainers"

View File

@@ -48,7 +48,7 @@ class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
class CircuitSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='circuits-api:circuit-detail')
provider = ProviderSerializer(nested=True)
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True)
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True, default=None)
status = ChoiceField(choices=CircuitStatusChoices, required=False)
type = CircuitTypeSerializer(nested=True)
tenant = TenantSerializer(nested=True, required=False, allow_null=True)

View File

@@ -45,6 +45,7 @@ class ProviderSerializer(NetBoxModelSerializer):
class ProviderAccountSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='circuits-api:provideraccount-detail')
provider = ProviderSerializer(nested=True)
name = serializers.CharField(allow_blank=True, max_length=100, required=False, default='')
class Meta:
model = ProviderAccount

View File

@@ -141,7 +141,7 @@ class CircuitTest(APIViewTestCases.APIViewTestCase):
{
'cid': 'Circuit 6',
'provider': providers[1].pk,
'provider_account': provider_accounts[1].pk,
# Omit provider account to test uniqueness constraint
'type': circuit_types[1].pk,
},
]
@@ -237,7 +237,7 @@ class ProviderAccountTest(APIViewTestCases.APIViewTestCase):
'account': '5678',
},
{
'name': 'Provider Account 6',
# Omit name to test uniqueness constraint
'provider': providers[0].pk,
'account': '6789',
},

View File

@@ -122,6 +122,7 @@ class DeviceWithConfigContextSerializer(DeviceSerializer):
class VirtualDeviceContextSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:virtualdevicecontext-detail')
device = DeviceSerializer(nested=True)
identifier = serializers.IntegerField(allow_null=True, max_value=32767, min_value=0, required=False, default=None)
tenant = TenantSerializer(nested=True, required=False, allow_null=True, default=None)
primary_ip = IPAddressSerializer(nested=True, read_only=True, allow_null=True)
primary_ip4 = IPAddressSerializer(nested=True, required=False, allow_null=True)

View File

@@ -51,7 +51,7 @@ class SiteSerializer(NetBoxModelSerializer):
status = ChoiceField(choices=SiteStatusChoices, required=False)
region = RegionSerializer(nested=True, required=False, allow_null=True)
group = SiteGroupSerializer(nested=True, required=False, allow_null=True)
tenant = TenantSerializer(required=False, allow_null=True)
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
time_zone = TimeZoneSerializerField(required=False, allow_null=True)
asns = SerializedPKRelatedField(
queryset=ASN.objects.all(),
@@ -83,7 +83,7 @@ class SiteSerializer(NetBoxModelSerializer):
class LocationSerializer(NestedGroupModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:location-detail')
site = SiteSerializer(nested=True)
parent = NestedLocationSerializer(required=False, allow_null=True)
parent = NestedLocationSerializer(required=False, allow_null=True, default=None)
status = ChoiceField(choices=LocationStatusChoices, required=False)
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
rack_count = serializers.IntegerField(read_only=True)

View File

@@ -848,6 +848,8 @@ class InterfaceTypeChoices(ChoiceSet):
# Ethernet Backplane
TYPE_1GE_KX = '1000base-kx'
TYPE_2GE_KX = '2.5gbase-kx'
TYPE_5GE_KR = '5gbase-kr'
TYPE_10GE_KR = '10gbase-kr'
TYPE_10GE_KX4 = '10gbase-kx4'
TYPE_25GE_KR = '25gbase-kr'
@@ -1008,6 +1010,8 @@ class InterfaceTypeChoices(ChoiceSet):
_('Ethernet (backplane)'),
(
(TYPE_1GE_KX, '1000BASE-KX (1GE)'),
(TYPE_2GE_KX, '2.5GBASE-KX (2.5GE)'),
(TYPE_5GE_KR, '5GBASE-KR (5GE)'),
(TYPE_10GE_KR, '10GBASE-KR (10GE)'),
(TYPE_10GE_KX4, '10GBASE-KX4 (10GE)'),
(TYPE_25GE_KR, '25GBASE-KR (25GE)'),

View File

@@ -90,14 +90,14 @@ def get_cable_form(a_type, b_type):
class _CableForm(CableForm, metaclass=FormMetaclass):
def __init__(self, *args, initial=None, **kwargs):
initial = initial or {}
if a_type:
ct = ContentType.objects.get_for_model(a_type)
initial['a_terminations_type'] = f'{ct.app_label}.{ct.model}'
a_ct = ContentType.objects.get_for_model(a_type)
initial['a_terminations_type'] = f'{a_ct.app_label}.{a_ct.model}'
if b_type:
ct = ContentType.objects.get_for_model(b_type)
initial['b_terminations_type'] = f'{ct.app_label}.{ct.model}'
b_ct = ContentType.objects.get_for_model(b_type)
initial['b_terminations_type'] = f'{b_ct.app_label}.{b_ct.model}'
# TODO: Temporary hack to work around list handling limitations with utils.normalize_querydict()
for field_name in ('a_terminations', 'b_terminations'):
@@ -108,8 +108,17 @@ def get_cable_form(a_type, b_type):
if self.instance and self.instance.pk:
# Initialize A/B terminations when modifying an existing Cable instance
self.initial['a_terminations'] = self.instance.a_terminations
self.initial['b_terminations'] = self.instance.b_terminations
if a_type and self.instance.a_terminations and a_ct == ContentType.objects.get_for_model(self.instance.a_terminations[0]):
self.initial['a_terminations'] = self.instance.a_terminations
if b_type and self.instance.b_terminations and b_ct == ContentType.objects.get_for_model(self.instance.b_terminations[0]):
self.initial['b_terminations'] = self.instance.b_terminations
else:
# Need to clear terminations if swapped type - but need to do it only
# if not from instance
if a_type:
initial.pop('a_terminations', None)
if b_type:
initial.pop('b_terminations', None)
def clean(self):
super().clean()

View File

@@ -10,6 +10,7 @@ from dcim.models import *
from extras.models import ConfigTemplate
from ipam.models import ASN, RIR, VLAN, VRF
from netbox.api.serializers import GenericObjectSerializer
from tenancy.models import Tenant
from utilities.testing import APITestCase, APIViewTestCases, create_test_device
from virtualization.models import Cluster, ClusterType
from wireless.choices import WirelessChannelChoices
@@ -152,6 +153,7 @@ class SiteTest(APIViewTestCases.APIViewTestCase):
Site.objects.bulk_create(sites)
rir = RIR.objects.create(name='RFC 6996', is_private=True)
tenant = Tenant.objects.create(name='Tenant 1', slug='tenant-1')
asns = [
ASN(asn=65000 + i, rir=rir) for i in range(8)
@@ -166,6 +168,7 @@ class SiteTest(APIViewTestCases.APIViewTestCase):
'group': groups[1].pk,
'status': SiteStatusChoices.STATUS_ACTIVE,
'asns': [asns[0].pk, asns[1].pk],
'tenant': tenant.pk,
},
{
'name': 'Site 5',
@@ -230,7 +233,7 @@ class LocationTest(APIViewTestCases.APIViewTestCase):
'name': 'Test Location 6',
'slug': 'test-location-6',
'site': sites[1].pk,
'parent': parent_locations[1].pk,
# Omit parent to test uniqueness constraint
'status': LocationStatusChoices.STATUS_PLANNED,
},
]
@@ -2307,6 +2310,6 @@ class VirtualDeviceContextTest(APIViewTestCases.APIViewTestCase):
'device': devices[1].pk,
'status': 'active',
'name': 'VDC 3',
'identifier': 3,
# Omit identifier to test uniqueness constraint
},
]

View File

@@ -28,7 +28,9 @@ from utilities.permissions import get_permission_for_model
from utilities.query import count_related
from utilities.query_functions import CollateAsChar
from utilities.views import GetReturnURLMixin, ObjectPermissionRequiredMixin, ViewTab, register_model_view
from virtualization.filtersets import VirtualMachineFilterSet
from virtualization.models import VirtualMachine
from virtualization.tables import VirtualMachineTable
from . import filtersets, forms, tables
from .choices import DeviceFaceChoices
from .models import *
@@ -2085,6 +2087,24 @@ class DeviceRenderConfigView(generic.ObjectView):
}
@register_model_view(Device, 'virtual-machines')
class DeviceVirtualMachinesView(generic.ObjectChildrenView):
queryset = Device.objects.all()
child_model = VirtualMachine
table = VirtualMachineTable
filterset = VirtualMachineFilterSet
tab = ViewTab(
label=_('Virtual Machines'),
badge=lambda obj: VirtualMachine.objects.filter(cluster=obj.cluster, device=obj).count(),
weight=2200,
hide_if_empty=True,
permission='virtualization.view_virtualmachine'
)
def get_children(self, request, parent):
return self.child_model.objects.restrict(request.user, 'view').filter(cluster=parent.cluster, device=parent)
class DeviceBulkImportView(generic.BulkImportView):
queryset = Device.objects.all()
model_form = forms.DeviceImportForm
@@ -2965,7 +2985,6 @@ class InventoryItemChildrenView(generic.ObjectChildrenView):
child_model = InventoryItem
table = tables.InventoryItemTable
filterset = filtersets.InventoryItemFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('Children'),
badge=lambda obj: obj.child_items.count(),

View File

@@ -240,9 +240,9 @@ class ScriptViewSet(ModelViewSet):
raise RQWorkerNotRunningException()
if input_serializer.is_valid():
script.result = Job.enqueue(
Job.enqueue(
run_script,
instance=script.module,
instance=script,
name=script.python_class.class_name,
user=request.user,
data=input_serializer.data['data'],

View File

@@ -279,10 +279,7 @@ class EventRuleForm(NetBoxModelForm):
FieldSet('name', 'description', 'object_types', 'enabled', 'tags', name=_('Event Rule')),
FieldSet('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end', name=_('Events')),
FieldSet('conditions', name=_('Conditions')),
FieldSet(
'action_type', 'action_choice', 'action_object_type', 'action_object_id', 'action_data',
name=_('Action')
),
FieldSet('action_type', 'action_choice', 'action_data', name=_('Action')),
)
class Meta:

View File

@@ -85,6 +85,7 @@ class Command(BaseCommand):
module_name, script_name = script.split('.', 1)
module, script = get_module_and_script(module_name, script_name)
script = script.python_class
# Take user from command line if provided and exists, other
if options['user']:

View File

@@ -60,7 +60,10 @@ def get_module_scripts(scriptmodule):
return cls.full_name.split(".", maxsplit=1)[1]
loader = SourceFileLoader(get_python_name(scriptmodule), get_full_path(scriptmodule))
module = loader.load_module()
try:
module = loader.load_module()
except FileNotFoundError:
return {}
scripts = {}
ordered = getattr(module, 'script_order', [])

View File

@@ -1,10 +1,10 @@
import json
import django_tables2 as tables
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from extras.models import *
from netbox.constants import EMPTY_TABLE_TEXT
from netbox.tables import BaseTable, NetBoxTable, columns
from .template_code import *
@@ -545,12 +545,12 @@ class ScriptResultsTable(BaseTable):
template_code="""{% load log_levels %}{% log_level record.status %}""",
verbose_name=_('Level')
)
message = tables.Column(
message = columns.MarkdownColumn(
verbose_name=_('Message')
)
class Meta(BaseTable.Meta):
empty_text = _('No results found')
empty_text = _(EMPTY_TABLE_TEXT)
fields = (
'index', 'time', 'status', 'message',
)
@@ -566,27 +566,22 @@ class ReportResultsTable(BaseTable):
time = tables.Column(
verbose_name=_('Time')
)
status = tables.Column(
empty_values=(),
verbose_name=_('Level')
)
status = tables.TemplateColumn(
template_code="""{% load log_levels %}{% log_level record.status %}""",
verbose_name=_('Level')
)
object = tables.Column(
verbose_name=_('Object')
)
url = tables.Column(
verbose_name=_('URL')
)
message = tables.Column(
message = columns.MarkdownColumn(
verbose_name=_('Message')
)
class Meta(BaseTable.Meta):
empty_text = _('No results found')
empty_text = _(EMPTY_TABLE_TEXT)
fields = (
'index', 'method', 'time', 'status', 'object', 'url', 'message',
)

View File

@@ -10,7 +10,7 @@ from tenancy.forms import TenancyFilterForm
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, add_blank_choice
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField, TagFilterField
from utilities.forms.rendering import FieldSet
from virtualization.models import VirtualMachine
from virtualization.models import VirtualMachine, ClusterGroup, Cluster
from vpn.models import L2VPN
__all__ = (
@@ -405,6 +405,7 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
FieldSet('min_vid', 'max_vid', name=_('VLAN ID')),
)
model = VLANGroup
@@ -445,6 +446,17 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
max_value=VLAN_VID_MAX,
label=_('Maximum VID')
)
cluster = DynamicModelMultipleChoiceField(
queryset=Cluster.objects.all(),
required=False,
label=_('Cluster')
)
cluster_group = DynamicModelMultipleChoiceField(
queryset=ClusterGroup.objects.all(),
required=False,
label=_('Cluster group')
)
tag = TagFilterField(model)

View File

@@ -574,7 +574,7 @@ class IPRange(PrimaryModel):
if not self.end_address > self.start_address:
raise ValidationError({
'end_address': _(
"Ending address must be lower than the starting address ({start_address})"
"Ending address must be greater than the starting address ({start_address})"
).format(start_address=self.start_address)
})

View File

@@ -648,6 +648,9 @@ class IPAddressTest(APIViewTestCases.APIViewTestCase):
bulk_update_data = {
'description': 'New description',
}
graphql_filter = {
'address': '192.168.0.1/24',
}
@classmethod
def setUpTestData(cls):

View File

@@ -214,7 +214,6 @@ class ASNRangeASNsView(generic.ObjectChildrenView):
child_model = ASN
table = tables.ASNTable
filterset = filtersets.ASNFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('ASNs'),
badge=lambda x: x.get_child_asns().count(),
@@ -781,6 +780,7 @@ class IPAddressView(generic.ObjectView):
class IPAddressEditView(generic.ObjectEditView):
queryset = IPAddress.objects.all()
form = forms.IPAddressForm
template_name = 'ipam/ipaddress_edit.html'
def alter_object(self, obj, request, url_args, url_kwargs):
@@ -882,7 +882,6 @@ class IPAddressRelatedIPsView(generic.ObjectChildrenView):
child_model = IPAddress
table = tables.IPAddressTable
filterset = filtersets.IPAddressFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('Related IPs'),
badge=lambda x: x.get_related_ips().count(),
@@ -954,7 +953,6 @@ class VLANGroupVLANsView(generic.ObjectChildrenView):
child_model = VLAN
table = tables.VLANTable
filterset = filtersets.VLANFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('VLANs'),
badge=lambda x: x.get_child_vlans().count(),
@@ -1110,7 +1108,6 @@ class VLANInterfacesView(generic.ObjectChildrenView):
child_model = Interface
table = tables.VLANDevicesTable
filterset = InterfaceFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('Device Interfaces'),
badge=lambda x: x.get_interfaces().count(),
@@ -1128,7 +1125,6 @@ class VLANVMInterfacesView(generic.ObjectChildrenView):
child_model = VMInterface
table = tables.VLANVirtualMachinesTable
filterset = VMInterfaceFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('VM Interfaces'),
badge=lambda x: x.get_vminterfaces().count(),

View File

@@ -157,9 +157,8 @@ LOGGING = {}
# authenticated to NetBox indefinitely.
LOGIN_PERSISTENCE = False
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
# are permitted to access most data in NetBox but not make any changes.
LOGIN_REQUIRED = False
# Setting this to False will permit unauthenticated users to access most areas of NetBox (but not make any changes).
LOGIN_REQUIRED = True
# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
# re-authenticate. (Default: 1209600 [14 days])

View File

@@ -41,3 +41,6 @@ DEFAULT_ACTION_PERMISSIONS = {
# General-purpose tokens
CENSOR_TOKEN = '********'
CENSOR_TOKEN_CHANGED = '***CHANGED***'
# Placeholder text for empty tables
EMPTY_TABLE_TEXT = 'No results found'

View File

@@ -87,7 +87,7 @@ def map_strawberry_type(field):
pass
elif issubclass(type(field), django_filters.NumberFilter):
should_create_function = True
attr_type = int
attr_type = int | None
elif issubclass(type(field), django_filters.ModelMultipleChoiceFilter):
should_create_function = True
attr_type = List[str] | None

View File

@@ -32,6 +32,7 @@ class MenuItem:
link: str
link_text: str
permissions: Optional[Sequence[str]] = ()
auth_required: Optional[bool] = False
staff_only: Optional[bool] = False
buttons: Optional[Sequence[MenuItemButton]] = ()

View File

@@ -371,6 +371,7 @@ ADMIN_MENU = Menu(
MenuItem(
link=f'users:user_list',
link_text=_('Users'),
auth_required=True,
permissions=[f'auth.view_user'],
buttons=(
MenuItemButton(
@@ -390,6 +391,7 @@ ADMIN_MENU = Menu(
MenuItem(
link=f'users:group_list',
link_text=_('Groups'),
auth_required=True,
permissions=[f'auth.view_group'],
buttons=(
MenuItemButton(
@@ -409,12 +411,14 @@ ADMIN_MENU = Menu(
MenuItem(
link=f'users:token_list',
link_text=_('API Tokens'),
auth_required=True,
permissions=[f'users.view_token'],
buttons=get_model_buttons('users', 'token')
),
MenuItem(
link=f'users:objectpermission_list',
link_text=_('Permissions'),
auth_required=True,
permissions=[f'users.view_objectpermission'],
buttons=get_model_buttons('users', 'objectpermission', actions=['add'])
),
@@ -425,16 +429,19 @@ ADMIN_MENU = Menu(
items=(
MenuItem(
link='core:system',
link_text=_('System')
link_text=_('System'),
auth_required=True
),
MenuItem(
link='core:configrevision_list',
link_text=_('Configuration History'),
auth_required=True,
permissions=['core.view_configrevision']
),
MenuItem(
link='core:background_queue_list',
link_text=_('Background Tasks')
link_text=_('Background Tasks'),
auth_required=True
),
),
),

View File

@@ -138,13 +138,15 @@ class PluginConfig(AppConfig):
min_version = version.parse(cls.min_version)
if current_version < min_version:
raise ImproperlyConfigured(
f"Plugin {cls.__module__} requires NetBox minimum version {cls.min_version}."
f"Plugin {cls.__module__} requires NetBox minimum version {cls.min_version} (current: "
f"{netbox_version})."
)
if cls.max_version is not None:
max_version = version.parse(cls.max_version)
if current_version > max_version:
raise ImproperlyConfigured(
f"Plugin {cls.__module__} requires NetBox maximum version {cls.max_version}."
f"Plugin {cls.__module__} requires NetBox maximum version {cls.max_version} (current: "
f"{netbox_version})."
)
# Verify required configuration settings

View File

@@ -23,7 +23,7 @@ PREFERENCES = {
),
description=_('Enable dynamic UI navigation'),
default=False,
experimental=True
warning=_('Experimental feature')
),
'locale.language': UserPreference(
label=_('Language'),
@@ -31,7 +31,12 @@ PREFERENCES = {
('', _('Auto')),
*settings.LANGUAGES,
),
description=_('Forces UI translation to the specified language.')
description=_('Forces UI translation to the specified language'),
warning=(
_("Support for translation has been disabled locally")
if not settings.TRANSLATION_ENABLED
else ''
)
),
'pagination.per_page': UserPreference(
label=_('Page length'),

View File

@@ -25,7 +25,7 @@ from utilities.string import trailing_slash
# Environment setup
#
VERSION = '4.0.0'
VERSION = '4.0.2'
HOSTNAME = platform.node()
# Set the base directory two levels up
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -105,7 +105,7 @@ LANGUAGE_CODE = getattr(configuration, 'DEFAULT_LANGUAGE', 'en-us')
LANGUAGE_COOKIE_PATH = CSRF_COOKIE_PATH
LOGGING = getattr(configuration, 'LOGGING', {})
LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False)
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', True)
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)
LOGOUT_REDIRECT_URL = getattr(configuration, 'LOGOUT_REDIRECT_URL', 'home')
MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media')).rstrip('/')
@@ -156,6 +156,7 @@ SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None)
STORAGE_BACKEND = getattr(configuration, 'STORAGE_BACKEND', None)
STORAGE_CONFIG = getattr(configuration, 'STORAGE_CONFIG', {})
TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC')
TRANSLATION_ENABLED = getattr(configuration, 'TRANSLATION_ENABLED', True)
# Load any dynamic configuration parameters which have been hard-coded in the configuration file
for param in CONFIG_PARAMS:
@@ -372,7 +373,6 @@ if not DJANGO_ADMIN_ENABLED:
# Middleware
MIDDLEWARE = [
"strawberry_django.middlewares.debug_toolbar.DebugToolbarMiddleware",
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
@@ -386,8 +386,14 @@ MIDDLEWARE = [
'netbox.middleware.RemoteUserMiddleware',
'netbox.middleware.CoreMiddleware',
'netbox.middleware.MaintenanceModeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware',
]
if METRICS_ENABLED:
# If metrics are enabled, add the before & after Prometheus middleware
MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
*MIDDLEWARE,
'django_prometheus.middleware.PrometheusAfterMiddleware',
]
# URLs
ROOT_URLCONF = 'netbox.urls'
@@ -440,6 +446,9 @@ LOGIN_REDIRECT_URL = f'/{BASE_PATH}'
# Use timezone-aware datetime objects
USE_TZ = True
# Toggle language translation support
USE_I18N = TRANSLATION_ENABLED
# WSGI
WSGI_APPLICATION = 'netbox.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
@@ -522,7 +531,6 @@ if SENTRY_ENABLED:
sentry_sdk.init(
dsn=SENTRY_DSN,
release=VERSION,
integrations=[sentry_sdk.integrations.django.DjangoIntegration()],
sample_rate=SENTRY_SAMPLE_RATE,
traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
send_default_pii=True,
@@ -797,3 +805,10 @@ for plugin_name in PLUGINS:
RQ_QUEUES.update({
f"{plugin_name}.{queue}": RQ_PARAMS for queue in plugin_config.queues
})
# UNSUPPORTED FUNCTIONALITY: Import any local overrides.
try:
from .local_settings import *
_UNSUPPORTED_SETTINGS = True
except ImportError:
pass

View File

@@ -14,6 +14,7 @@ from django_tables2.data import TableQuerysetData
from core.models import ObjectType
from extras.choices import *
from extras.models import CustomField, CustomLink
from netbox.constants import EMPTY_TABLE_TEXT
from netbox.registry import registry
from netbox.tables import columns
from utilities.paginator import EnhancedPaginator, get_paginate_count
@@ -52,7 +53,7 @@ class BaseTable(tables.Table):
# Set default empty_text if none was provided
if self.empty_text is None:
self.empty_text = f"No {self._meta.model._meta.verbose_name_plural} found"
self.empty_text = _("No {model_name} found").format(model_name=self._meta.model._meta.verbose_name_plural)
# Determine the table columns to display by checking the following:
# 1. User's configuration for the table
@@ -258,7 +259,7 @@ class SearchTable(tables.Table):
attrs = {
'class': 'table table-hover object-list',
}
empty_text = _('No results found')
empty_text = _(EMPTY_TABLE_TEXT)
def __init__(self, data, highlight=None, **kwargs):
self.highlight = highlight

View File

@@ -42,6 +42,7 @@ class PluginTest(TestCase):
url = reverse('admin:dummy_plugin_dummymodel_add')
self.assertEqual(url, '/admin/dummy_plugin/dummymodel/add/')
@override_settings(LOGIN_REQUIRED=False)
def test_views(self):
# Test URL resolution
@@ -53,7 +54,7 @@ class PluginTest(TestCase):
response = client.get(url)
self.assertEqual(response.status_code, 200)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
def test_api_views(self):
# Test URL resolution
@@ -65,6 +66,7 @@ class PluginTest(TestCase):
response = client.get(url)
self.assertEqual(response.status_code, 200)
@override_settings(LOGIN_REQUIRED=False)
def test_registered_views(self):
# Test URL resolution

View File

@@ -1,24 +1,76 @@
import urllib.parse
from utilities.testing import TestCase
from django.urls import reverse
from django.test import override_settings
from dcim.models import Site
from netbox.constants import EMPTY_TABLE_TEXT
from netbox.search.backends import search_backend
from utilities.testing import TestCase
class HomeViewTestCase(TestCase):
def test_home(self):
url = reverse('home')
response = self.client.get(url)
self.assertHttpStatus(response, 200)
def test_search(self):
class SearchViewTestCase(TestCase):
@classmethod
def setUpTestData(cls):
sites = (
Site(name='Site Alpha', slug='alpha', description='Red'),
Site(name='Site Bravo', slug='bravo', description='Red'),
Site(name='Site Charlie', slug='charlie', description='Green'),
Site(name='Site Delta', slug='delta', description='Green'),
Site(name='Site Echo', slug='echo', description='Blue'),
Site(name='Site Foxtrot', slug='foxtrot', description='Blue'),
)
Site.objects.bulk_create(sites)
search_backend.cache(sites)
def test_search(self):
url = reverse('search')
response = self.client.get(url)
self.assertHttpStatus(response, 200)
def test_search_query(self):
url = reverse('search')
params = {
'q': 'foo',
'q': 'red',
}
query = urllib.parse.urlencode(params)
response = self.client.get('{}?{}'.format(url, urllib.parse.urlencode(params)))
# Test without view permission
response = self.client.get(f'{url}?{query}')
self.assertHttpStatus(response, 200)
content = str(response.content)
self.assertIn(EMPTY_TABLE_TEXT, content)
# Add view permissions & query again. Only matching objects should be listed
self.add_permissions('dcim.view_site')
response = self.client.get(f'{url}?{query}')
self.assertHttpStatus(response, 200)
content = str(response.content)
self.assertIn('Site Alpha', content)
self.assertIn('Site Bravo', content)
self.assertNotIn('Site Charlie', content)
self.assertNotIn('Site Delta', content)
self.assertNotIn('Site Echo', content)
self.assertNotIn('Site Foxtrot', content)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_search_no_results(self):
url = reverse('search')
params = {
'q': 'xxxxxxxxx', # Matches nothing
}
query = urllib.parse.urlencode(params)
response = self.client.get(f'{url}?{query}')
self.assertHttpStatus(response, 200)
content = str(response.content)
self.assertIn(EMPTY_TABLE_TEXT, content)

View File

@@ -93,6 +93,7 @@ class ObjectChildrenView(ObjectView, ActionsMixin, TableMixin):
child_model = None
table = None
filterset = None
template_name = 'generic/object_children.html'
def get_children(self, request, parent):
"""

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -30,7 +30,7 @@
"gridstack": "10.1.2",
"htmx.org": "1.9.12",
"query-string": "9.0.0",
"sass": "1.76.0",
"sass": "1.77.1",
"tom-select": "2.3.1",
"typeface-inter": "3.18.1",
"typeface-roboto-mono": "1.1.13"

View File

@@ -10,9 +10,9 @@ function quickSearchEventHandler(event: Event): void {
const clearbtn = document.getElementById("quicksearch_clear") as HTMLAnchorElement;
if (isTruthy(clearbtn)) {
if (quicksearch.value === "") {
clearbtn.classList.add("d-none");
clearbtn.classList.add("invisible");
} else {
clearbtn.classList.remove("d-none");
clearbtn.classList.remove("invisible");
}
}
}

View File

@@ -1816,9 +1816,9 @@ ignore@^5.2.0:
integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==
immutable@^4.0.0:
version "4.3.5"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.5.tgz#f8b436e66d59f99760dc577f5c99a4fd2a5cc5a0"
integrity sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw==
version "4.3.6"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.6.tgz#6a05f7858213238e587fb83586ffa3b4b27f0447"
integrity sha512-Ju0+lEMyzMVZarkTn/gqRpdqd5dOPaz1mCZ0SH3JV6iFw81PldE/PEB1hWVEA288HPt4WXW8O7AWxB10M+03QQ==
import-fresh@^3.2.1:
version "3.3.0"
@@ -2482,7 +2482,16 @@ safe-regex-test@^1.0.3:
es-errors "^1.3.0"
is-regex "^1.1.4"
sass@1.76.0, sass@^1.7.3:
sass@1.77.1:
version "1.77.1"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.77.1.tgz#018cdfb206afd14724030c02e9fefd8f30a76cd0"
integrity sha512-OMEyfirt9XEfyvocduUIOlUSkWOXS/LAt6oblR/ISXCTukyavjex+zQNm51pPCOiFKY1QpWvEH1EeCkgyV3I6w==
dependencies:
chokidar ">=3.0.0 <4.0.0"
immutable "^4.0.0"
source-map-js ">=0.6.2 <2.0.0"
sass@^1.7.3:
version "1.76.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.76.0.tgz#fe15909500735ac154f0dc7386d656b62b03987d"
integrity sha512-nc3LeqvF2FNW5xGF1zxZifdW3ffIz5aBb7I7tSvOoNu7z1RQ6pFt9MBuiPtjgaI62YWrM/txjWlOCFiGtf2xpw==

View File

@@ -20,7 +20,7 @@
{# Initialize color mode #}
<script
type="text/javascript"
src="{% static 'setmode.js' %}"
src="{% static 'setmode.js' %}?v={{ settings.VERSION }}"
onerror="window.location='{% url 'media_failure' %}?filename=setmode.js'">
</script>
<script type="text/javascript">

View File

@@ -33,7 +33,7 @@
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">{% trans "Configuration Data" %}</h5>
{% include 'core/inc/config_data.html' with config=config.data %}
{% include 'core/inc/config_data.html' with config=object.data %}
</div>
<div class="card">

View File

@@ -31,12 +31,16 @@
<th scope="row">{% trans "NetBox version" %}</th>
<td>{{ stats.netbox_version }}</td>
</tr>
<tr>
<th scope="row">{% trans "Python version" %}</th>
<td>{{ stats.python_version }}</td>
</tr>
<tr>
<th scope="row">{% trans "Django version" %}</th>
<td>{{ stats.django_version }}</td>
</tr>
<tr>
<th scope="row">{% trans "PotsgreSQL version" %}</th>
<th scope="row">{% trans "PostgreSQL version" %}</th>
<td>{{ stats.postgresql_version }}</td>
</tr>
<tr>

View File

@@ -77,15 +77,9 @@
</div>
</div>
<div class="col col-md-7">
{% include 'inc/sync_warning.html' %}
<div class="card">
<h5 class="card-header d-flex justify-content-between">
{% trans "Data" %}
{% include 'extras/inc/configcontext_format.html' %}
</h5>
<div class="card-body">
{% include 'inc/sync_warning.html' %}
{% include 'extras/inc/configcontext_data.html' with data=object.data format=format %}
</div>
{% include 'extras/inc/configcontext_data.html' with title="Data" data=object.data format=format copyid="data" %}
</div>
</div>
</div>

View File

@@ -1,5 +1,17 @@
{% load helpers %}
{% load i18n %}
<div class="rendered-context-data mt-1">
<pre class="block">{% if format == 'json' %}{{ data|json }}{% elif format == 'yaml' %}{{ data|yaml }}{% else %}{{ data }}{% endif %}</pre>
{% if title %}
<h5 class="card-header d-flex justify-content-between">
{% trans title %}
<div>
{% if copyid %}{% copy_content copyid %}{% endif %}
{% include 'extras/inc/format_toggle.html' %}
</div>
</h5>
{% endif %}
<div class="card-body">
<div class="rendered-context-data mt-1">
<pre class="block" {% if copyid %}id="{{ copyid }}{% endif %}">{% if format == 'json' %}{{ data|json }}{% elif format == 'yaml' %}{{ data|yaml }}{% else %}{{ data }}{% endif %}</pre>
</div>
</div>

View File

@@ -1,6 +0,0 @@
<div>
<div class="btn-group btn-group-sm" role="group">
<a href="?format=json" type="button" class="btn btn-outline-dark{% if format == 'json' %} active{% endif %}">JSON</a>
<a href="?format=yaml" type="button" class="btn btn-outline-dark{% if format == 'yaml' %} active{% endif %}">YAML</a>
</div>
</div>

View File

@@ -0,0 +1,4 @@
<div class="btn-group btn-group-sm" role="group">
<a href="?format=json" type="button" class="btn btn-outline-dark{% if format == 'json' %} active{% endif %}">JSON</a>
<a href="?format=yaml" type="button" class="btn btn-outline-dark{% if format == 'yaml' %} active{% endif %}">YAML</a>
</div>

View File

@@ -6,28 +6,13 @@
{% block content %}
<div class="row">
<div class="col col-md-6">
<div class="card">
<h5 class="card-header d-flex justify-content-between">
{% trans "Rendered Context" %}
{% include 'extras/inc/configcontext_format.html' %}
</h5>
<div class="card-body">
{% include 'extras/inc/configcontext_data.html' with data=rendered_context format=format %}
</div>
</div>
<div class="card">
{% include 'extras/inc/configcontext_data.html' with title="Rendered Context" data=rendered_context format=format copyid="rendered_context" %}
</div>
</div>
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
{% trans "Local Context" %}
</h5>
<div class="card-body">
{% if object.local_context_data %}
{% include 'extras/inc/configcontext_data.html' with data=object.local_context_data format=format %}
{% else %}
<span class="text-muted">{% trans "None" %}</span>
{% endif %}
</div>
{% include 'extras/inc/configcontext_data.html' with title="Local Context" data=object.local_context_data format=format copyid="local_context" %}
<div class="card-footer">
<span class="help-block">
<i class="mdi mdi-information-outline"></i>
@@ -36,8 +21,11 @@
</div>
</div>
<div class="card">
<h5 class="card-header">
{% trans "Source Contexts" %}
<h5 class="card-header d-flex justify-content-between">
{% trans "Source Contexts" %}
<div>
{% include 'extras/inc/format_toggle.html' %}
</div>
</h5>
{% for context in source_contexts %}
<div class="card-body">

View File

@@ -2,15 +2,17 @@
{% load helpers %}
{% load render_table from django_tables2 %}
{% with preferences|get_key:"pagination.placement" as paginator_placement %}
{% if paginator_placement == 'top' or paginator_placement == 'both' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %}
{% endif %}
{% render_table table 'inc/table_htmx.html' %}
{% if paginator_placement != 'top' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %}
{% endif %}
{% endwith %}
<div class="htmx-container table-responsive">
{% with preferences|get_key:"pagination.placement" as paginator_placement %}
{% if paginator_placement == 'top' or paginator_placement == 'both' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %}
{% endif %}
{% render_table table 'inc/table_htmx.html' %}
{% if paginator_placement != 'top' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %}
{% endif %}
{% endwith %}
</div>
{# Include the updated object count for display elsewhere on the page #}
<div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>

View File

@@ -5,7 +5,8 @@
<div
class="d-flex justify-content-between align-items-center border-{% if placement == 'top' %}bottom{% else %}top{% endif %} p-2"
hx-target="closest .htmx-container"
hx-disinherit="hx-select hx-swap"
hx-disinherit="hx-select"
hx-swap="outerHTML"
{% if not table.embedded %}hx-push-url="true"{% endif %}
>

View File

@@ -7,7 +7,7 @@
<input type="search" results="5" name="q" id="quicksearch" class="form-control px-2 py-1" placeholder="Quick search"
hx-get="{{ request.full_path }}" hx-target="#object_list" hx-trigger="keyup changed delay:500ms, search" />
<span class="input-group-text py-1">
<a href="#" id="quicksearch_clear" class="d-none text-secondary"><i class="mdi mdi-close-circle"></i></a>
<a href="#" id="quicksearch_clear" class="invisible text-secondary"><i class="mdi mdi-close-circle"></i></a>
</span>
{% block extra_table_controls %}{% endblock %}
</div>

View File

@@ -1,5 +1,5 @@
{% load django_tables2 %}
<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %} hx-disinherit="hx-target hx-select hx-swap">
<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %} hx-disinherit="hx-target hx-select" hx-swap="outerHTML">
{% if table.show_header %}
<thead
hx-target="closest .htmx-container"

View File

@@ -3,30 +3,21 @@
<ul class="nav nav-tabs">
<li class="nav-item">
<a
class="nav-link {% if active_tab == 'add' %}active{% endif %}"
href="{% url 'ipam:ipaddress_add' %}{% querystring request %}"
>
{% if obj.pk %}{% trans "Edit" %}{% else %}{% trans "Create" %}{% endif %}
</a>
<a href="{% url 'ipam:ipaddress_add' %}{% querystring request %}" class="nav-link {% if active_tab == 'add' %}active{% endif %}">
{% if object.pk %}{% trans "Edit" %}{% else %}{% trans "Create" %}{% endif %}
</a>
</li>
{% if 'interface' in request.GET or 'vminterface' in request.GET %}
<li class="nav-item">
<a
class="nav-link {% if active_tab == 'assign' %}active{% endif %}"
href="{% url 'ipam:ipaddress_assign' %}{% querystring request %}"
>
{% trans "Assign IP" %}
<li class="nav-item">
<a href="{% url 'ipam:ipaddress_assign' %}{% querystring request %}" class="nav-link {% if active_tab == 'assign' %}active{% endif %}">
{% trans "Assign IP" %}
</a>
</li>
{% else %}
<li class="nav-item">
<a
class="nav-link {% if active_tab == 'bulk_add' %}active{% endif %}"
href="{% url 'ipam:ipaddress_bulk_add' %}{% querystring request %}"
>
{% trans "Bulk Create" %}
</li>
{% elif not object.pk %}
<li class="nav-item">
<a href="{% url 'ipam:ipaddress_bulk_add' %}{% querystring request %}" class="nav-link {% if active_tab == 'bulk_add' %}active{% endif %}">
{% trans "Bulk Create" %}
</a>
</li>
</li>
{% endif %}
</ul>

View File

@@ -12,37 +12,33 @@
{% endblock %}
{% block form %}
<form action="{% querystring request %}" method="post" class="form form-horizontal">
{% csrf_token %}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
<div class="row mb-3">
<div class="col col-md-8 offset-md-2">
<div class="field-group">
<h6>{% trans "Select IP Address" %}</h6>
{% render_field form.vrf_id %}
{% render_field form.q %}
</div>
</div>
<form action="{% querystring request %}" method="post" class="form form-horizontal">
{% csrf_token %}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
<div class="field-group my-5">
<div class="row">
<h5 class="col-9 offset-3">{% trans "Select IP Address" %}</h5>
</div>
{% render_field form.vrf_id %}
{% render_field form.q %}
</div>
<div class="text-end my-3">
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
</div>
</form>
{% if table %}
<div class="row mb-3">
<div class="col col-md-12">
<h3>{% trans "Search Results" %}</h3>
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
<div class="row mb-3">
<div class="col col-md-8 offset-md-2 text-end">
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
<button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
</div>
</div>
</form>
{% if table %}
<div class="row mb-3">
<div class="col col-md-12">
<h3>{% trans "Search Results" %}</h3>
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endif %}
{% endblock form %}
{% block buttons %}

View File

@@ -0,0 +1,5 @@
{% extends 'generic/object_edit.html' %}
{% block tabs %}
{% include 'ipam/inc/ipaddress_edit_header.html' with active_tab='add' %}
{% endblock %}

View File

@@ -46,7 +46,21 @@
<input type="hidden" name="next" value="{{ request.POST.next }}" />
{% endif %}
{% render_form form %}
<div class="form-group mb-3">
<label for="id_username" class="form-label">{{ form.username.label }}</label>
{{ form.username }}
{% for error in form.username.errors %}
<div class="alert alert-danger">{{ error }}</div>
{% endfor %}
</div>
<div class="form-group">
<label for="id_password" class="form-label">{{ form.password.label }}</label>
{{ form.password }}
{% for error in form.password.errors %}
<div class="alert alert-danger">{{ error }}</div>
{% endfor %}
</div>
<div class="form-footer">
<button type="submit" class="btn btn-primary w-100">

View File

@@ -27,7 +27,7 @@ class TenantGroupSerializer(NestedGroupModelSerializer):
class TenantSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='tenancy-api:tenant-detail')
group = TenantGroupSerializer(nested=True, required=False, allow_null=True)
group = TenantGroupSerializer(nested=True, required=False, allow_null=True, default=None)
# Related object counts
circuit_count = RelatedObjectCountField('circuits')

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -40,11 +40,8 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
help_text = f'<code>{field_name}</code>'
if preference.description:
help_text = f'{preference.description}<br />{help_text}'
if preference.experimental:
help_text = (
f'<span class="text-danger"><i class="mdi mdi-alert"></i> Experimental feature</span><br />'
f'{help_text}'
)
if warning := preference.warning:
help_text = f'<span class="text-danger"><i class="mdi mdi-alert"></i> {warning}</span><br />{help_text}'
field_kwargs = {
'label': preference.label,
'choices': preference.choices,

View File

@@ -2,10 +2,10 @@ class UserPreference:
"""
Represents a configurable user preference.
"""
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, experimental=False):
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, warning=''):
self.label = label
self.choices = choices
self.default = default if default is not None else choices[0]
self.description = description
self.coerce = coerce
self.experimental = experimental
self.warning = warning

View File

@@ -70,14 +70,24 @@ class RestrictedGenericForeignKey(GenericForeignKey):
# 1. Capture restrict_params from RestrictedPrefetch (hack)
# 2. If restrict_params is set, call restrict() on the queryset for
# the related model
def get_prefetch_queryset(self, instances, queryset=None):
def get_prefetch_querysets(self, instances, querysets=None):
restrict_params = {}
custom_queryset_dict = {}
# Compensate for the hack in RestrictedPrefetch
if type(queryset) is dict:
restrict_params = queryset
elif queryset is not None:
raise ValueError(_("Custom queryset can't be used for this lookup."))
if type(querysets) is dict:
restrict_params = querysets
elif querysets is not None:
for queryset in querysets:
ct_id = self.get_content_type(
model=queryset.query.model, using=queryset.db
).pk
if ct_id in custom_queryset_dict:
raise ValueError(
"Only one queryset is allowed for each content type."
)
custom_queryset_dict[ct_id] = queryset
# For efficiency, group the instances by content type and then do one
# query per model
@@ -100,15 +110,16 @@ class RestrictedGenericForeignKey(GenericForeignKey):
ret_val = []
for ct_id, fkeys in fk_dict.items():
instance = instance_dict[ct_id]
ct = self.get_content_type(id=ct_id, using=instance._state.db)
if restrict_params:
# Override the default behavior to call restrict() on each model's queryset
qs = ct.model_class().objects.filter(pk__in=fkeys).restrict(**restrict_params)
ret_val.extend(qs)
if ct_id in custom_queryset_dict:
# Return values from the custom queryset, if provided.
ret_val.extend(custom_queryset_dict[ct_id].filter(pk__in=fkeys))
else:
# Default behavior
ret_val.extend(ct.get_all_objects_for_this_type(pk__in=fkeys))
instance = instance_dict[ct_id]
ct = self.get_content_type(id=ct_id, using=instance._state.db)
qs = ct.model_class().objects.filter(pk__in=fkeys)
if restrict_params:
qs = qs.restrict(**restrict_params)
ret_val.extend(qs)
# For doing the join in Python, we have to match both the FK val and the
# content type, so we use a callable that returns a (fk, class) pair.

View File

@@ -20,14 +20,14 @@ class RestrictedPrefetch(Prefetch):
super().__init__(lookup, queryset=queryset, to_attr=to_attr)
def get_current_queryset(self, level):
def get_current_querysets(self, level):
params = {
'user': self.restrict_user,
'action': self.restrict_action,
}
if qs := super().get_current_queryset(level):
return qs.restrict(**params)
if querysets := super().get_current_querysets(level):
return [qs.restrict(**params) for qs in querysets]
# Bit of a hack. If no queryset is defined, pass through the dict of restrict()
# kwargs to be handled by the field. This is necessary e.g. for GenericForeignKey
@@ -49,11 +49,11 @@ class RestrictedQuerySet(QuerySet):
permission_required = get_permission_for_model(self.model, action)
# Bypass restriction for superusers and exempt views
if user.is_superuser or permission_is_exempt(permission_required):
if user and user.is_superuser or permission_is_exempt(permission_required):
qs = self
# User is anonymous or has not been granted the requisite permission
elif not user.is_authenticated or permission_required not in user.get_all_permissions():
elif user is None or not user.is_authenticated or permission_required not in user.get_all_permissions():
qs = self.none()
# Filter the queryset to include only objects with allowed attributes

View File

@@ -1,5 +1,5 @@
<div class="htmx-container table-responsive"
hx-get="{% url viewname %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}"
hx-target="this"
hx-trigger="load" hx-select="table" hx-swap="innerHTML"
hx-trigger="load" hx-select=".htmx-container" hx-swap="outerHTML"
></div>

View File

@@ -26,6 +26,8 @@ def nav(context):
for group in menu.groups:
items = []
for item in group.items:
if getattr(item, 'auth_required', False) and not user.is_authenticated:
continue
if not user.has_perms(item.permissions):
continue
if item.staff_only and not user.is_staff:

View File

@@ -73,7 +73,7 @@ class APIViewTestCases:
class GetObjectViewTestCase(APITestCase):
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
def test_get_object_anonymous(self):
"""
GET a single object as an unauthenticated user.
@@ -135,7 +135,7 @@ class APIViewTestCases:
class ListObjectsViewTestCase(APITestCase):
brief_fields = []
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
def test_list_objects_anonymous(self):
"""
GET a list of objects as an unauthenticated user.
@@ -440,13 +440,12 @@ class APIViewTestCases:
base_name = self.model._meta.verbose_name.lower().replace(' ', '_')
return getattr(self, 'graphql_base_name', base_name)
def _build_query(self, name, **filters):
def _build_query_with_filter(self, name, filter_string):
"""
Called by either _build_query or _build_filtered_query - construct the actual
query given a name and filter string
"""
type_class = get_graphql_type_for_model(self.model)
if filters:
filter_string = ', '.join(f'{k}:{v}' for k, v in filters.items())
filter_string = f'({filter_string})'
else:
filter_string = ''
# Compile list of fields to include
fields_string = ''
@@ -492,6 +491,30 @@ class APIViewTestCases:
return query
def _build_filtered_query(self, name, **filters):
"""
Create a filtered query: i.e. ip_address_list(filters: {address: "1.1.1.1/24"}){.
"""
if filters:
filter_string = ', '.join(f'{k}: "{v}"' for k, v in filters.items())
filter_string = f'(filters: {{{filter_string}}})'
else:
filter_string = ''
return self._build_query_with_filter(name, filter_string)
def _build_query(self, name, **filters):
"""
Create a normal query - unfiltered or with a string query: i.e. site(name: "aaa"){.
"""
if filters:
filter_string = ', '.join(f'{k}:{v}' for k, v in filters.items())
filter_string = f'({filter_string})'
else:
filter_string = ''
return self._build_query_with_filter(name, filter_string)
@override_settings(LOGIN_REQUIRED=True)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*', 'auth.user'])
def test_graphql_get_object(self):
@@ -550,6 +573,31 @@ class APIViewTestCases:
self.assertNotIn('errors', data)
self.assertGreater(len(data['data'][field_name]), 0)
@override_settings(LOGIN_REQUIRED=True)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*', 'auth.user'])
def test_graphql_filter_objects(self):
if not hasattr(self, 'graphql_filter'):
return
url = reverse('graphql')
field_name = f'{self._get_graphql_base_name()}_list'
query = self._build_filtered_query(field_name, **self.graphql_filter)
# Add object-level permission
obj_perm = ObjectPermission(
name='Test permission',
actions=['view']
)
obj_perm.save()
obj_perm.users.add(self.user)
obj_perm.object_types.add(ObjectType.objects.get_for_model(self.model))
response = self.client.post(url, data={'query': query}, format="json", **self.header)
self.assertHttpStatus(response, status.HTTP_200_OK)
data = json.loads(response.content)
self.assertNotIn('errors', data)
self.assertGreater(len(data['data'][field_name]), 0)
class APIViewTestCase(
GetObjectViewTestCase,
ListObjectsViewTestCase,

View File

@@ -62,7 +62,7 @@ class ViewTestCases:
"""
Retrieve a single instance.
"""
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
def test_get_object_anonymous(self):
# Make the request as an unauthenticated user
self.client.logout()
@@ -421,7 +421,7 @@ class ViewTestCases:
"""
Retrieve multiple instances.
"""
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], LOGIN_REQUIRED=False)
def test_list_objects_anonymous(self):
# Make the request as an unauthenticated user
self.client.logout()

View File

@@ -31,11 +31,11 @@ __all__ = (
class VirtualMachineSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='virtualization-api:virtualmachine-detail')
status = ChoiceField(choices=VirtualMachineStatusChoices, required=False)
site = SiteSerializer(nested=True, required=False, allow_null=True)
cluster = ClusterSerializer(nested=True, required=False, allow_null=True)
device = DeviceSerializer(nested=True, required=False, allow_null=True)
site = SiteSerializer(nested=True, required=False, allow_null=True, default=None)
cluster = ClusterSerializer(nested=True, required=False, allow_null=True, default=None)
device = DeviceSerializer(nested=True, required=False, allow_null=True, default=None)
role = DeviceRoleSerializer(nested=True, required=False, allow_null=True)
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
tenant = TenantSerializer(nested=True, required=False, allow_null=True, default=None)
platform = PlatformSerializer(nested=True, required=False, allow_null=True)
primary_ip = IPAddressSerializer(nested=True, read_only=True, allow_null=True)
primary_ip4 = IPAddressSerializer(nested=True, required=False, allow_null=True)
@@ -55,7 +55,6 @@ class VirtualMachineSerializer(NetBoxModelSerializer):
'interface_count', 'virtual_disk_count',
]
brief_fields = ('id', 'url', 'display', 'name', 'description')
validators = []
class VirtualMachineWithConfigContextSerializer(VirtualMachineSerializer):

View File

@@ -84,7 +84,7 @@ class VirtualMachineType(ConfigContextMixin, ContactsMixin, NetBoxObjectType):
primary_ip4: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
primary_ip6: Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')] | None
interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
interfaces: List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]
services: List[Annotated["ServiceType", strawberry.lazy('ipam.graphql.types')]]
virtualdisks: List[Annotated["VirtualDiskType", strawberry.lazy('virtualization.graphql.types')]]
@@ -102,8 +102,8 @@ class VMInterfaceType(IPAddressesMixin, ComponentType):
vrf: Annotated["VRFType", strawberry.lazy('ipam.graphql.types')] | None
tagged_vlans: List[Annotated["VLANType", strawberry.lazy('ipam.graphql.types')]]
bridge_interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
child_interfaces: List[Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')]]
bridge_interfaces: List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]
child_interfaces: List[Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')]]
@strawberry_django.type(

View File

@@ -181,7 +181,6 @@ class ClusterVirtualMachinesView(generic.ObjectChildrenView):
child_model = VirtualMachine
table = tables.VirtualMachineTable
filterset = filtersets.VirtualMachineFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('Virtual Machines'),
badge=lambda obj: obj.virtual_machines.count(),

View File

@@ -1,4 +1,4 @@
Django==5.0.5
Django==5.0.6
django-cors-headers==4.3.1
django-debug-toolbar==4.3.0
django-filter==24.2
@@ -20,18 +20,18 @@ feedparser==6.0.11
gunicorn==22.0.0
Jinja2==3.1.4
Markdown==3.6
mkdocs-material==9.5.21
mkdocs-material==9.5.22
mkdocstrings[python-legacy]==0.25.1
netaddr==1.2.1
nh3==0.2.17
Pillow==10.3.0
psycopg[c,pool]==3.1.18
psycopg[c,pool]==3.1.19
PyYAML==6.0.1
requests==2.31.0
social-auth-app-django==5.4.1
social-auth-core==4.5.4
strawberry-graphql==0.227.3
strawberry-graphql-django==0.39.2
strawberry-graphql==0.229.0
strawberry-graphql-django==0.40.0
svgwrite==1.4.3
tablib==3.6.1
tzdata==2024.1