diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index a4eb4ed9a..fb9a7cd47 100644 --- a/netbox/dcim/graphql/types.py +++ b/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 diff --git a/netbox/extras/graphql/mixins.py b/netbox/extras/graphql/mixins.py new file mode 100644 index 000000000..5c857db8c --- /dev/null +++ b/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')