Compare commits

..

2 Commits

Author SHA1 Message Date
Martin Rødvand
576099e3b8 Formatting 2025-07-24 22:07:56 +02:00
Martin Rødvand
a5d1500307 Add conditional to hide internet dependent links in an isolated deployment 2025-07-24 22:04:41 +02:00
3 changed files with 16 additions and 61 deletions

View File

@@ -1,7 +1,5 @@
from django.conf import settings
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.views.static import serve
from django_rq.queues import get_connection from django_rq.queues import get_connection
from drf_spectacular.utils import extend_schema, extend_schema_view from drf_spectacular.utils import extend_schema, extend_schema_view
from rest_framework import status from rest_framework import status
@@ -202,17 +200,6 @@ class ImageAttachmentViewSet(NetBoxModelViewSet):
serializer_class = serializers.ImageAttachmentSerializer serializer_class = serializers.ImageAttachmentSerializer
filterset_class = filtersets.ImageAttachmentFilterSet filterset_class = filtersets.ImageAttachmentFilterSet
@action(
methods=['GET'],
detail=True,
url_path='download',
url_name='download',
)
def download(self, request, pk, *args, **kwargs):
obj = get_object_or_404(self.queryset, pk=pk)
# Render and return the elevation as an SVG drawing with the correct content type
return serve(request, obj.image.name, document_root=settings.MEDIA_ROOT)
# #
# Journal entries # Journal entries

View File

@@ -1,8 +1,6 @@
import datetime import datetime
from PIL import Image
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.files.base import File
from django.urls import reverse from django.urls import reverse
from django.utils.timezone import make_aware, now from django.utils.timezone import make_aware, now
from rest_framework import status from rest_framework import status
@@ -618,38 +616,6 @@ class ImageAttachmentTest(
) )
ImageAttachment.objects.bulk_create(image_attachments) ImageAttachment.objects.bulk_create(image_attachments)
def test_image_download(self):
self.add_permissions('extras.view_imageattachment')
ct = ContentType.objects.get_for_model(Site)
site = Site.objects.get(name='Site 1', slug='site-1')
image = Image.new('RGB', size=(1, 1), color=(255, 0, 0))
image.save('test_image_download.png', format='PNG')
image_file = File(open('test_image_download.png', 'rb'))
content = image_file.read()
attachment = ImageAttachment(
object_type=ct,
object_id=site.pk,
name='Image Attachment 4',
image_height=1,
image_width=1
)
attachment.image.save('test_image_download.png', image_file, save=True)
attachment.save()
image = ImageAttachment.objects.get(name='Image Attachment 4')
url = reverse('extras-api:imageattachment-download', kwargs={'pk': image.pk})
response = self.client.get(url, **self.header)
downloaded_content = b''.join(response.streaming_content)
self.assertEqual(response.headers.get('Content-Type'), 'image/png')
self.assertEqual(response.headers.get('Content-Length'), '69')
self.assertEqual(
response.headers.get('Content-Disposition'), f'inline; filename="site_{site.pk}_Image_Attachment_4.png"'
)
self.assertEqual(content, downloaded_content)
class JournalEntryTest(APIViewTestCases.APIViewTestCase): class JournalEntryTest(APIViewTestCases.APIViewTestCase):
model = JournalEntry model = JournalEntry

View File

@@ -55,7 +55,7 @@ Blocks:
{# Release info #} {# Release info #}
<div class="text-muted text-center fs-5 my-3"> <div class="text-muted text-center fs-5 my-3">
{{ settings.RELEASE.name }} {{ settings.RELEASE.name }}
{% if not settings.RELEASE.features.commercial %} {% if not settings.RELEASE.features.commercial and not settings.ISOLATED_DEPLOYMENT %}
<div> <div>
<a href="https://netboxlabs.com/netbox-cloud/" class="text-muted">{% trans "Get" %} Cloud</a> | <a href="https://netboxlabs.com/netbox-cloud/" class="text-muted">{% trans "Get" %} Cloud</a> |
<a href="https://netboxlabs.com/netbox-enterprise/" class="text-muted">{% trans "Get" %} Enterprise</a> <a href="https://netboxlabs.com/netbox-enterprise/" class="text-muted">{% trans "Get" %} Enterprise</a>
@@ -184,7 +184,7 @@ Blocks:
{% endif %} {% endif %}
{# Commercial links #} {# Commercial links #}
{% if settings.RELEASE.features.commercial %} {% if settings.RELEASE.features.commercial and not settings.ISOLATED_DEPLOYMENT %}
{# LinkedIn #} {# LinkedIn #}
<li class="list-inline-item"> <li class="list-inline-item">
<a href="https://www.linkedin.com/company/netboxlabs/" target="_blank" class="link-secondary" rel="noopener" aria-label="LinkedIn"> <a href="https://www.linkedin.com/company/netboxlabs/" target="_blank" class="link-secondary" rel="noopener" aria-label="LinkedIn">
@@ -200,18 +200,20 @@ Blocks:
{# Community links #} {# Community links #}
{% else %} {% else %}
{# GitHub #} {% if not settings.ISOLATED_DEPLOYMENT %}
<li class="list-inline-item"> {# GitHub #}
<a href="https://github.com/netbox-community/netbox" target="_blank" class="link-secondary" rel="noopener" aria-label="{% trans "Source Code" %}"> <li class="list-inline-item">
<i title="{% trans "Source Code" %}" class="mdi mdi-github text-primary" data-bs-placement="top" data-bs-toggle="tooltip"></i> <a href="https://github.com/netbox-community/netbox" target="_blank" class="link-secondary" rel="noopener" aria-label="{% trans "Source Code" %}">
</a> <i title="{% trans "Source Code" %}" class="mdi mdi-github text-primary" data-bs-placement="top" data-bs-toggle="tooltip"></i>
</li> </a>
{# NetDev Slack #} </li>
<li class="list-inline-item"> {# NetDev Slack #}
<a href="https://netdev.chat" target="_blank" class="link-secondary" rel="noopener" aria-label="{% trans "Community" %}"> <li class="list-inline-item">
<i title="{% trans "Community" %}" class="mdi mdi-slack text-primary" data-bs-placement="top" data-bs-toggle="tooltip"></i> <a href="https://netdev.chat" target="_blank" class="link-secondary" rel="noopener" aria-label="{% trans "Community" %}">
</a> <i title="{% trans "Community" %}" class="mdi mdi-slack text-primary" data-bs-placement="top" data-bs-toggle="tooltip"></i>
</li> </a>
</li>
{% endif %}
{% endif %} {% endif %}
{% endblock footer_links %} {% endblock footer_links %}
</ul> </ul>