Просмотр исходного кода

Closes #4840: Enable change logging for config contexts

Jeremy Stretch 5 лет назад
Родитель
Сommit
59091efa86

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -26,6 +26,7 @@ When running a report or custom script, the task is now queued for background pr
 * [#4807](https://github.com/netbox-community/netbox/issues/4807) - Add bulk edit ability for device bay templates
 * [#4817](https://github.com/netbox-community/netbox/issues/4817) - Standardize device/VM component `name` field to 64 characters
 * [#4837](https://github.com/netbox-community/netbox/issues/4837) - Use dynamic form widget for relationships to MPTT objects (e.g. regions)
+* [#4840](https://github.com/netbox-community/netbox/issues/4840) - Enable change logging for config contexts
 
 ### Configuration Changes
 

+ 1 - 1
netbox/extras/api/serializers.py

@@ -233,7 +233,7 @@ class ConfigContextSerializer(ValidatedModelSerializer):
         model = ConfigContext
         fields = [
             'id', 'url', 'name', 'weight', 'description', 'is_active', 'regions', 'sites', 'roles', 'platforms',
-            'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags', 'data',
+            'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags', 'data', 'created', 'last_updated',
         ]
 
 

+ 23 - 0
netbox/extras/migrations/0045_configcontext_changelog.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.6 on 2020-07-09 20:54
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('extras', '0044_jobresult'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='configcontext',
+            name='created',
+            field=models.DateField(auto_now_add=True, null=True),
+        ),
+        migrations.AddField(
+            model_name='configcontext',
+            name='last_updated',
+            field=models.DateTimeField(auto_now=True, null=True),
+        ),
+    ]

+ 1 - 1
netbox/extras/models/models.py

@@ -434,7 +434,7 @@ class ImageAttachment(models.Model):
 # Config contexts
 #
 
-class ConfigContext(models.Model):
+class ConfigContext(ChangeLoggedModel):
     """
     A ConfigContext represents a set of arbitrary data available to any Device or VirtualMachine matching its assigned
     qualifiers (region, site, etc.). For example, the data stored in a ConfigContext assigned to site A and tenant B

+ 1 - 0
netbox/extras/tests/test_views.py

@@ -45,6 +45,7 @@ class TagTestCase(ViewTestCases.OrganizationalObjectViewTestCase):
 # Blocked by absence of standard create/edit, bulk create views
 class ConfigContextTestCase(
     ViewTestCases.GetObjectViewTestCase,
+    ViewTestCases.GetObjectChangelogViewTestCase,
     ViewTestCases.DeleteObjectViewTestCase,
     ViewTestCases.ListObjectsViewTestCase,
     ViewTestCases.BulkEditObjectsViewTestCase,

+ 2 - 1
netbox/extras/urls.py

@@ -1,7 +1,7 @@
 from django.urls import path
 
 from extras import views
-from extras.models import Tag
+from extras.models import ConfigContext, Tag
 
 
 app_name = 'extras'
@@ -25,6 +25,7 @@ urlpatterns = [
     path('config-contexts/<int:pk>/', views.ConfigContextView.as_view(), name='configcontext'),
     path('config-contexts/<int:pk>/edit/', views.ConfigContextEditView.as_view(), name='configcontext_edit'),
     path('config-contexts/<int:pk>/delete/', views.ConfigContextDeleteView.as_view(), name='configcontext_delete'),
+    path('config-contexts/<int:pk>/changelog/', views.ObjectChangeLogView.as_view(), name='configcontext_changelog', kwargs={'model': ConfigContext}),
 
     # Image attachments
     path('image-attachments/<int:pk>/edit/', views.ImageAttachmentEditView.as_view(), name='imageattachment_edit'),

+ 10 - 0
netbox/templates/extras/configcontext.html

@@ -31,6 +31,16 @@
             </a>
         {% endif %}
     </div>
+    <ul class="nav nav-tabs">
+        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
+            <a href="{{ configcontext.get_absolute_url }}">Config Context</a>
+        </li>
+        {% if perms.extras.view_objectchange %}
+            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
+                <a href="{% url 'extras:configcontext_changelog' pk=configcontext.pk %}">Change Log</a>
+            </li>
+        {% endif %}
+    </ul>
     <h1>{% block title %}{{ configcontext }}{% endblock %}</h1>
 {% endblock %}