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

Add image_attachments to Device, Location, Rack, Site

jeremystretch 4 лет назад
Родитель
Сommit
8ad958708f
2 измененных файлов с 17 добавлено и 4 удалено
  1. 5 4
      netbox/dcim/graphql/types.py
  2. 12 0
      netbox/extras/graphql/mixins.py

+ 5 - 4
netbox/dcim/graphql/types.py

@@ -1,4 +1,5 @@
 from dcim import filtersets, models
+from extras.graphql.mixins import ImageAttachmentsMixin
 from ipam.graphql.mixins import IPAddressesMixin
 from netbox.graphql.types import BaseObjectType, ObjectType, TaggedObjectType
 
@@ -97,7 +98,7 @@ class ConsoleServerPortTemplateType(BaseObjectType):
         return self.type or None
 
 
-class DeviceType(TaggedObjectType):
+class DeviceType(ImageAttachmentsMixin, TaggedObjectType):
 
     class Meta:
         model = models.Device
@@ -186,7 +187,7 @@ class InventoryItemType(TaggedObjectType):
         filterset_class = filtersets.InventoryItemFilterSet
 
 
-class LocationType(ObjectType):
+class LocationType(ImageAttachmentsMixin, ObjectType):
 
     class Meta:
         model = models.Location
@@ -276,7 +277,7 @@ class PowerPortTemplateType(BaseObjectType):
         return self.type or None
 
 
-class RackType(TaggedObjectType):
+class RackType(ImageAttachmentsMixin, TaggedObjectType):
 
     class Meta:
         model = models.Rack
@@ -330,7 +331,7 @@ class RegionType(ObjectType):
         filterset_class = filtersets.RegionFilterSet
 
 
-class SiteType(TaggedObjectType):
+class SiteType(ImageAttachmentsMixin, TaggedObjectType):
 
     class Meta:
         model = models.Site

+ 12 - 0
netbox/extras/graphql/mixins.py

@@ -0,0 +1,12 @@
+import graphene
+
+__all__ = (
+    'ImageAttachmentsMixin',
+)
+
+
+class ImageAttachmentsMixin:
+    image_attachments = graphene.List('extras.graphql.types.ImageAttachmentType')
+
+    def resolve_image_attachments(self, info):
+        return self.images.restrict(info.context.user, 'view')