Compare commits

...

9 Commits

Author SHA1 Message Date
Arthur Hanson 3ad769f5a6
Merge fcce7b7bf4 into 5af3c659a5 2024-04-26 13:26:15 +02:00
Tobias Genannt 5af3c659a5 Fix #15826: Added new group and user models 2024-04-25 09:23:27 -04:00
Arthur Hanson 4923025fec
15541 Add component selector to InventoryItemTemplate (#15691)
* 15541 update InventoryItemTemplateForm

* 15541 update InventoryItemTemplateForm

* Remove custom template

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-04-25 09:22:32 -04:00
Arthur Hanson ded2fe9471
15809 Mark unions as nullable in GraphQL where appropriate (#15824)
* 15809 mark unions as nullable where appropriate

* 15809 fix tests

* 15809 fix tests
2024-04-25 09:19:19 -04:00
Jeremy Stretch e05ca710ae Flag HTMX navigation as an experimental feature 2024-04-23 10:38:49 -04:00
Arthur fcce7b7bf4 15153 styling changes 2024-04-01 09:34:29 -07:00
Arthur 510aa2156d 15153 move css to scss file 2024-04-01 09:09:53 -07:00
Arthur 4b436c9d4f Merge branch 'feature' into 15153-rest-styling 2024-04-01 07:53:06 -07:00
Arthur 5429bf651d 15153 update styling browseable rest api 2024-03-19 07:02:56 -07:00
15 changed files with 117 additions and 157 deletions

View File

@ -1002,6 +1002,7 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
queryset=Manufacturer.objects.all(),
required=False
)
# Assigned component selectors
consoleporttemplate = DynamicModelChoiceField(
queryset=ConsolePortTemplate.objects.all(),
@ -1063,8 +1064,19 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
fieldsets = (
FieldSet(
'device_type', 'parent', 'name', 'label', 'role', 'manufacturer', 'part_id', 'description',
'component_type', 'component_id',
),
FieldSet(
TabbedGroups(
FieldSet('interfacetemplate', name=_('Interface')),
FieldSet('consoleporttemplate', name=_('Console Port')),
FieldSet('consoleserverporttemplate', name=_('Console Server Port')),
FieldSet('frontporttemplate', name=_('Front Port')),
FieldSet('rearporttemplate', name=_('Rear Port')),
FieldSet('powerporttemplate', name=_('Power Port')),
FieldSet('poweroutlettemplate', name=_('Power Outlet')),
),
name=_('Component Assignment')
)
)
class Meta:
@ -1079,22 +1091,17 @@ class InventoryItemTemplateForm(ComponentTemplateForm):
component_type = initial.get('component_type')
component_id = initial.get('component_id')
# Used for picking the default active tab for component selection
self.no_component = True
if instance:
# When editing set the initial value for component selection
for component_model in ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS):
if type(instance.component) is component_model.model_class():
initial[component_model.model] = instance.component
self.no_component = False
break
elif component_type and component_id:
# When adding the InventoryItem from a component page
if content_type := ContentType.objects.filter(MODULAR_COMPONENT_TEMPLATE_MODELS).filter(pk=component_type).first():
if component := content_type.model_class().objects.filter(pk=component_id).first():
initial[content_type.model] = component
self.no_component = False
kwargs['initial'] = initial

View File

@ -130,7 +130,7 @@ class CableTerminationType(NetBoxObjectType):
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("CableTerminationTerminationType")]
], strawberry.union("CableTerminationTerminationType")] | None
@strawberry_django.type(
@ -302,7 +302,7 @@ class InventoryItemTemplateType(ComponentTemplateType):
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("InventoryItemTemplateComponentType")]
], strawberry.union("InventoryItemTemplateComponentType")] | None
@strawberry_django.type(
@ -431,7 +431,7 @@ class InventoryItemType(ComponentType):
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("InventoryItemComponentType")]
], strawberry.union("InventoryItemComponentType")] | None
@strawberry_django.type(

View File

@ -1655,7 +1655,6 @@ class InventoryItemTemplateCreateView(generic.ComponentCreateView):
queryset = InventoryItemTemplate.objects.all()
form = forms.InventoryItemTemplateCreateForm
model_form = forms.InventoryItemTemplateForm
template_name = 'dcim/inventoryitemtemplate_edit.html'
def alter_object(self, instance, request):
# Set component (if any)
@ -1673,7 +1672,6 @@ class InventoryItemTemplateCreateView(generic.ComponentCreateView):
class InventoryItemTemplateEditView(generic.ObjectEditView):
queryset = InventoryItemTemplate.objects.all()
form = forms.InventoryItemTemplateForm
template_name = 'dcim/inventoryitemtemplate_edit.html'
@register_model_view(InventoryItemTemplate, 'delete')

View File

@ -133,7 +133,7 @@ class IPAddressType(NetBoxObjectType, BaseIPAddressFamilyType):
Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')],
Annotated["FHRPGroupType", strawberry.lazy('ipam.graphql.types')],
Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')],
], strawberry.union("IPAddressAssignmentType")]:
], strawberry.union("IPAddressAssignmentType")] | None:
return self.assigned_object
@ -261,7 +261,7 @@ class VLANGroupType(OrganizationalObjectType):
Annotated["RegionType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("VLANGroupScopeType")]:
], strawberry.union("VLANGroupScopeType")] | None:
return self.scope

View File

@ -22,6 +22,7 @@ PREFERENCES = {
('dark', _('Dark')),
),
default='light',
description=_('Preferred default UI theme')
),
'ui.htmx_navigation': UserPreference(
label=_('HTMX Navigation'),
@ -29,14 +30,17 @@ PREFERENCES = {
('', _('Disabled')),
('true', _('Enabled')),
),
default=False
description=_('Enable dynamic UI navigation'),
default=False,
experimental=True
),
'locale.language': UserPreference(
label=_('Language'),
choices=(
('', _('Auto')),
*settings.LANGUAGES,
)
),
description=_('Forces UI translation to the specified language.')
),
'pagination.per_page': UserPreference(
label=_('Page length'),
@ -51,8 +55,8 @@ PREFERENCES = {
('top', _('Top')),
('both', _('Both')),
),
description=_('Where the paginator controls will be displayed relative to a table'),
default='bottom'
default='bottom',
description=_('Where the paginator controls will be displayed relative to a table')
),
# Miscellaneous
@ -62,6 +66,7 @@ PREFERENCES = {
('json', 'JSON'),
('yaml', 'YAML'),
),
description=_('The preferred syntax for displaying generic data within the UI')
),
}

View File

@ -477,11 +477,11 @@ SERIALIZATION_MODULES = {
# Exclude potentially sensitive models from wildcard view exemption. These may still be exempted
# by specifying the model individually in the EXEMPT_VIEW_PERMISSIONS configuration parameter.
EXEMPT_EXCLUDE_MODELS = (
('auth', 'group'),
('auth', 'user'),
('extras', 'configrevision'),
('users', 'group'),
('users', 'objectpermission'),
('users', 'token'),
('users', 'user'),
)
# All URLs starting with a string listed here are exempt from login enforcement

View File

@ -113,6 +113,7 @@ async function bundleStyles() {
'netbox': 'styles/netbox.scss',
rack_elevation: 'styles/svg/rack_elevation.scss',
cable_trace: 'styles/svg/cable_trace.scss',
'rest-api': 'styles/rest_api.scss',
};
const pluginOptions = { outputStyle: 'compressed' };
// Allow cache disabling.

View File

@ -0,0 +1,31 @@
.breadcrumb {
background-color: #fff;
}
.btn-primary {
background-color: #17a2b8;
border: none;
}
.navbar-default {
background-color: #1f2e41;
margin-bottom: 10px;
}
.navbar-default .navbar-text {
color: #fff;
}
.navbar>.container .navbar-brand, .navbar>.container-fluid .navbar-brand {
padding: 12px 0 12px 0;
margin-bottom: 5px;
margin-left: 1px;
}
.prettyprint {
background-color: #f6f8fb;
}
.breadcrumb {
margin-bottom: 10px;
padding-left: 0;
}
.page-header {
margin-top: 10px;
}

View File

@ -39,30 +39,32 @@
{% trans "Clear table preferences" %}
</label>
<div class="col-sm-9">
<table class="table table-hover object-list">
<thead>
<tr>
<th>
<input type="checkbox" class="toggle form-check-input" title="{% trans "Toggle All" %}">
</th>
<th>{% trans "Table" %}</th>
<th>{% trans "Ordering" %}</th>
<th>{% trans "Columns" %}</th>
</tr>
</thead>
<tbody>
{% for table, prefs in request.user.config.data.tables.items %}
<div class="card">
<table class="table table-hover object-list">
<thead>
<tr>
<td>
<input type="checkbox" name="pk" value="tables.{{ table }}" class="form-check-input" />
</td>
<td>{{ table }}</td>
<td>{{ prefs.ordering|join:", "|placeholder }}</td>
<td>{{ prefs.columns|join:", "|placeholder }}</td>
<th>
<input type="checkbox" class="toggle form-check-input" title="{% trans "Toggle All" %}">
</th>
<th>{% trans "Table" %}</th>
<th>{% trans "Ordering" %}</th>
<th>{% trans "Columns" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for table, prefs in request.user.config.data.tables.items %}
<tr>
<td>
<input type="checkbox" name="pk" value="tables.{{ table }}" class="form-check-input" />
</td>
<td>{{ table }}</td>
<td>{{ prefs.ordering|join:", "|placeholder }}</td>
<td>{{ prefs.columns|join:", "|placeholder }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<div class="col-9 offset-3">

View File

@ -1,104 +0,0 @@
{% extends 'generic/object_edit.html' %}
{% load static %}
{% load form_helpers %}
{% load helpers %}
{% load i18n %}
{% block form %}
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{% trans "Inventory Item" %}</h5>
</div>
{% render_field form.device_type %}
{% render_field form.parent %}
{% render_field form.name %}
{% render_field form.label %}
{% render_field form.role %}
{% render_field form.description %}
</div>
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{% trans "Hardware" %}</h5>
</div>
{% render_field form.manufacturer %}
{% render_field form.part_id %}
</div>
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{% trans "Component Assignment" %}</h5>
</div>
<div class="row mb-2 offset-sm-3">
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="consoleport_tab" data-bs-toggle="tab" aria-controls="consoleport" data-bs-target="#consoleport" class="nav-link {% if form.initial.consoleporttemplate or form.no_component %}active{% endif %}">
{% trans "Console Port" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="consoleserverport_tab" data-bs-toggle="tab" aria-controls="consoleserverport" data-bs-target="#consoleserverport" class="nav-link {% if form.initial.consoleserverporttemplate %}active{% endif %}">
{% trans "Console Server Port" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="frontport_tab" data-bs-toggle="tab" aria-controls="frontport" data-bs-target="#frontport" class="nav-link {% if form.initial.frontporttemplate %}active{% endif %}">
{% trans "Front Port" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="interface_tab" data-bs-toggle="tab" aria-controls="interface" data-bs-target="#interface" class="nav-link {% if form.initial.interfacetemplate %}active{% endif %}">
{% trans "Interface" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="poweroutlet_tab" data-bs-toggle="tab" aria-controls="poweroutlet" data-bs-target="#poweroutlet" class="nav-link {% if form.initial.poweroutlettemplate %}active{% endif %}">
{% trans "Power Outlet" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="powerport_tab" data-bs-toggle="tab" aria-controls="powerport" data-bs-target="#powerport" class="nav-link {% if form.initial.powerporttemplate %}active{% endif %}">
{% trans "Power Port" %}
</button>
</li>
<li role="presentation" class="nav-item">
<button role="tab" type="button" id="rearport_tab" data-bs-toggle="tab" aria-controls="rearport" data-bs-target="#rearport" class="nav-link {% if form.initial.rearporttemplate %}active{% endif %}">
{% trans "Rear Port" %}
</button>
</li>
</ul>
</div>
<div class="tab-content p-0 border-0">
<div class="tab-pane {% if form.initial.consoleporttemplate or form.no_component %}active{% endif %}" id="consoleport" role="tabpanel" aria-labeled-by="consoleport_tab">
{% render_field form.consoleporttemplate %}
</div>
<div class="tab-pane {% if form.initial.consoleserverporttemplate %}active{% endif %}" id="consoleserverport" role="tabpanel" aria-labeled-by="consoleserverport_tab">
{% render_field form.consoleserverporttemplate %}
</div>
<div class="tab-pane {% if form.initial.frontporttemplate %}active{% endif %}" id="frontport" role="tabpanel" aria-labeled-by="frontport_tab">
{% render_field form.frontporttemplate %}
</div>
<div class="tab-pane {% if form.initial.interfacetemplate %}active{% endif %}" id="interface" role="tabpanel" aria-labeled-by="interface_tab">
{% render_field form.interfacetemplate %}
</div>
<div class="tab-pane {% if form.initial.poweroutlettemplate %}active{% endif %}" id="poweroutlet" role="tabpanel" aria-labeled-by="poweroutlet_tab">
{% render_field form.poweroutlettemplate %}
</div>
<div class="tab-pane {% if form.initial.powerporttemplate %}active{% endif %}" id="powerport" role="tabpanel" aria-labeled-by="powerport_tab">
{% render_field form.powerporttemplate %}
</div>
<div class="tab-pane {% if form.initial.rearporttemplate %}active{% endif %}" id="rearport" role="tabpanel" aria-labeled-by="rearport_tab">
{% render_field form.rearporttemplate %}
</div>
</div>
</div>
{% if form.custom_fields %}
<div class="field-group my-5">
<div class="row mb-2">
<h5 class="offset-sm-3">{% trans "Custom Fields" %}</h5>
</div>
{% render_custom_fields form %}
</div>
{% endif %}
{% endblock %}

View File

@ -2,6 +2,13 @@
{% load static %}
{% load i18n %}
{% block bootstrap_theme %}
<link rel="stylesheet" type="text/css" href="{% static "rest_framework/css/bootstrap.min.css" %}"/>
<link rel="stylesheet" type="text/css" href="{% static "rest-api.css" %}"/>
{% endblock %}
{% block bootstrap_navbar_variant %}navbar-default{% endblock %}
{% block head %}
{{ block.super }}
<link rel="icon" type="image/png" href="{% static 'rest-api.ico' %}" />
@ -10,5 +17,7 @@
{% block title %}{% if name %}{{ name }} | {% endif %}NetBox {% trans "REST API" %}{% endblock %}
{% block branding %}
<a class="navbar-brand" href="{% url 'home' %}">NetBox</a>
<a class="navbar-brand" href="{% url 'home' %}">
<img src="{% static 'netbox_logo.svg' %}" height="32" alt="{% trans "NetBox Logo" %}" class="navbar-brand-image">
</a>
{% endblock branding %}

View File

@ -3,7 +3,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.postgres.forms import SimpleArrayField
from django.core.exceptions import FieldError
from django.utils.html import mark_safe
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from core.models import ObjectType
@ -37,7 +37,14 @@ class UserConfigFormMetaclass(forms.models.ModelFormMetaclass):
preference_fields = {}
for field_name, preference in PREFERENCES.items():
description = f'{preference.description}<br />' if preference.description else ''
help_text = f'{description}<code>{field_name}</code>'
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}'
)
field_kwargs = {
'label': preference.label,
'choices': preference.choices,

View File

@ -2,9 +2,10 @@ class UserPreference:
"""
Represents a configurable user preference.
"""
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x):
def __init__(self, label, choices, default=None, description='', coerce=lambda x: x, experimental=False):
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

View File

@ -469,6 +469,9 @@ class APIViewTestCases:
elif type(field.type) is StrawberryUnion:
# this would require a fragment query
continue
elif type(field.type) is StrawberryOptional and type(field.type.of_type) is StrawberryUnion:
# this would require a fragment query
continue
elif type(field.type) is StrawberryOptional and type(field.type.of_type) is LazyType:
fields_string += f'{field.name} {{ id }}\n'
elif hasattr(field, 'is_relation') and field.is_relation:

View File

@ -151,7 +151,7 @@ class ViewTestCases:
with disable_warnings('django.request'):
self.assertHttpStatus(response, 403)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_create_object_with_permission(self):
# Assign unconstrained permission
@ -190,7 +190,7 @@ class ViewTestCases:
self.assertEqual(len(objectchanges), 1)
self.assertEqual(objectchanges[0].action, ObjectChangeActionChoices.ACTION_CREATE)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_create_object_with_constrained_permission(self):
# Assign constrained permission
@ -253,7 +253,7 @@ class ViewTestCases:
with disable_warnings('django.request'):
self.assertHttpStatus(self.client.post(**request), 403)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_edit_object_with_permission(self):
instance = self._get_queryset().first()
@ -291,7 +291,7 @@ class ViewTestCases:
self.assertEqual(len(objectchanges), 1)
self.assertEqual(objectchanges[0].action, ObjectChangeActionChoices.ACTION_UPDATE)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_edit_object_with_constrained_permission(self):
instance1, instance2 = self._get_queryset().all()[:2]
@ -602,7 +602,7 @@ class ViewTestCases:
with disable_warnings('django.request'):
self.assertHttpStatus(response, 403)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_bulk_import_objects_with_permission(self):
initial_count = self._get_queryset().count()
data = {
@ -665,7 +665,7 @@ class ViewTestCases:
if value is not None and not isinstance(field, ForeignKey):
self.assertEqual(value, value)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_bulk_import_objects_with_constrained_permission(self):
initial_count = self._get_queryset().count()
data = {
@ -720,7 +720,7 @@ class ViewTestCases:
with disable_warnings('django.request'):
self.assertHttpStatus(self.client.post(self._get_url('bulk_edit'), data), 403)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_bulk_edit_objects_with_permission(self):
pk_list = list(self._get_queryset().values_list('pk', flat=True)[:3])
data = {
@ -745,7 +745,7 @@ class ViewTestCases:
for i, instance in enumerate(self._get_queryset().filter(pk__in=pk_list)):
self.assertInstanceEqual(instance, self.bulk_edit_data)
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'], EXEMPT_EXCLUDE_MODELS=[])
def test_bulk_edit_objects_with_constrained_permission(self):
pk_list = list(self._get_queryset().values_list('pk', flat=True)[:3])
data = {