1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

9856 type updates

This commit is contained in:
Arthur
2024-02-22 16:35:24 -08:00
parent 3c24cf97b6
commit d4812b28fd
8 changed files with 130 additions and 18 deletions

View File

@ -1,4 +1,4 @@
from typing import List from typing import Annotated, List
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -59,12 +59,15 @@ class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, Ob
@strawberry_django.type( @strawberry_django.type(
models.CircuitType, models.CircuitType,
# fields='__all__', fields='__all__',
exclude=['color',], # bug - remove color from exclude
filters=CircuitTypeFilter filters=CircuitTypeFilter
) )
class CircuitTypeType(OrganizationalObjectType): class CircuitTypeType(OrganizationalObjectType):
pass color: str
@strawberry_django.field
def circuits(self) -> List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]:
return self.circuits.all()
@strawberry_django.type( @strawberry_django.type(

View File

@ -1,4 +1,7 @@
import graphene from typing import TYPE_CHECKING, Annotated, List, Union
import strawberry
import strawberry_django
from circuits.graphql.types import CircuitTerminationType, ProviderNetworkType from circuits.graphql.types import CircuitTerminationType, ProviderNetworkType
from circuits.models import CircuitTermination, ProviderNetwork from circuits.models import CircuitTermination, ProviderNetwork
from dcim.graphql.types import ( from dcim.graphql.types import (

View File

@ -2,6 +2,7 @@ import strawberry
import strawberry_django import strawberry_django
from typing import TYPE_CHECKING, Annotated, List, Union from typing import TYPE_CHECKING, Annotated, List, Union
__all__ = ( __all__ = (
'CabledObjectMixin', 'CabledObjectMixin',
'PathEndpointMixin', 'PathEndpointMixin',
@ -33,8 +34,18 @@ class CabledObjectMixin:
@strawberry.type @strawberry.type
class PathEndpointMixin: class PathEndpointMixin:
pass
# @strawberry_django.field @strawberry_django.field
# def connected_endpoints(self) -> List[Annotated["ObjectChangeType", strawberry.lazy('.types')]]: def link_peers(self) -> List[Annotated[Union[
# # Handle empty values Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')],
# return self.connected_endpoints or None Annotated["ConsolePortType", strawberry.lazy('dcim.graphql.types')],
Annotated["ConsoleServerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["FrontPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["InterfaceType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerFeedType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerOutletType", strawberry.lazy('dcim.graphql.types')],
Annotated["PowerPortType", strawberry.lazy('dcim.graphql.types')],
Annotated["ProviderNetworkType", strawberry.lazy('dcim.graphql.types')],
Annotated["RearPortType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("ConnectedEndpointType")]]:
return self.connected_endpoints or None

View File

@ -124,11 +124,11 @@ class CableTerminationType(NetBoxObjectType):
@strawberry_django.type( @strawberry_django.type(
models.Cable, models.Cable,
# fields='__all__', fields='__all__',
exclude=('color', ), # bug - temp
filters=CableFilter filters=CableFilter
) )
class CableType(NetBoxObjectType): class CableType(NetBoxObjectType):
color: str
@strawberry_django.field @strawberry_django.field
def terminations(self) -> List[CableTerminationType]: def terminations(self) -> List[CableTerminationType]:
@ -161,6 +161,7 @@ class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
filters=ConsolePortTemplateFilter filters=ConsolePortTemplateFilter
) )
class ConsolePortTemplateType(ComponentTemplateObjectType): class ConsolePortTemplateType(ComponentTemplateObjectType):
_name: str
def resolve_type(self, info): def resolve_type(self, info):
return self.type or None return self.type or None

View File

@ -1,3 +1,5 @@
from typing import Annotated, List
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -35,6 +37,58 @@ __all__ = (
class ConfigContextType(ObjectType): class ConfigContextType(ObjectType):
pass pass
@strawberry_django.field
def roles(self) -> List[Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def device_types(self) -> List[Annotated["DeviceTypeType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def tags(self) -> List[Annotated["TagType", strawberry.lazy('extras.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def platforms(self) -> List[Annotated["PlatformType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def regions(self) -> List[Annotated["RegionType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def cluster_groups(self) -> List[Annotated["ClusterGroupType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def tenant_groups(self) -> List[Annotated["TenantGroupType", strawberry.lazy('tenancy.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def cluster_types(self) -> List[Annotated["ClusterTypeType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def clusters(self) -> List[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def locations(self) -> List[Annotated["LocationType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def sites(self) -> List[Annotated["SiteType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def tenants(self) -> List[Annotated["TenantType", strawberry.lazy('tenancy.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def site_groups(self) -> List[Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.type( @strawberry_django.type(
models.ConfigTemplate, models.ConfigTemplate,
@ -42,7 +96,22 @@ class ConfigContextType(ObjectType):
filters=ConfigTemplateFilter filters=ConfigTemplateFilter
) )
class ConfigTemplateType(TagsMixin, ObjectType): class ConfigTemplateType(TagsMixin, ObjectType):
pass
@strawberry_django.field
def virtualmachines(self) -> List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def devices(self) -> List[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def platforms(self) -> List[Annotated["PlatformType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def device_roles(self) -> List[Annotated["DeviceRoleType", strawberry.lazy('dcim.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.type( @strawberry_django.type(

View File

@ -31,7 +31,10 @@ class BaseObjectType:
@classmethod @classmethod
def get_queryset(cls, queryset, info, **kwargs): def get_queryset(cls, queryset, info, **kwargs):
# Enforce object permissions on the queryset # Enforce object permissions on the queryset
return queryset.restrict(info.context.request.user, 'view') if hasattr(queryset, 'restrict'):
return queryset.restrict(info.context.request.user, 'view')
else:
return queryset
@strawberry_django.field @strawberry_django.field
def display(self) -> str: def display(self) -> str:

View File

@ -743,7 +743,6 @@ if not ENABLE_LOCALIZATION:
# #
STRAWBERRY_DJANGO = { STRAWBERRY_DJANGO = {
"TYPE_DESCRIPTION_FROM_MODEL_DOCSTRING": True, "TYPE_DESCRIPTION_FROM_MODEL_DOCSTRING": True,
# "GENERATE_ENUMS_FROM_CHOICES": True,
} }
# #

View File

@ -1,3 +1,5 @@
from typing import Annotated, List
import strawberry import strawberry
import strawberry_django import strawberry_django
@ -24,7 +26,18 @@ __all__ = (
filters=ClusterFilter filters=ClusterFilter
) )
class ClusterType(VLANGroupsMixin, NetBoxObjectType): class ClusterType(VLANGroupsMixin, NetBoxObjectType):
pass
@strawberry_django.field
def virtual_machines(self) -> List[Annotated["VirtualMachineType", strawberry.lazy('virtualization.graphql.types')]]:
return self.virtual_machines.all()
@strawberry_django.field
def vlan_groups(self) -> List[Annotated["VLANGroupType", strawberry.lazy('ipam.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def devices(self) -> List[Annotated["DeviceType", strawberry.lazy('dcim.graphql.types')]]:
return self.devices.all()
@strawberry_django.type( @strawberry_django.type(
@ -33,7 +46,14 @@ class ClusterType(VLANGroupsMixin, NetBoxObjectType):
filters=ClusterGroupFilter filters=ClusterGroupFilter
) )
class ClusterGroupType(VLANGroupsMixin, OrganizationalObjectType): class ClusterGroupType(VLANGroupsMixin, OrganizationalObjectType):
pass
@strawberry_django.field
def vlan_groups(self) -> List[Annotated["VLANGroupType", strawberry.lazy('ipam.graphql.types')]]:
return self.vlan_groups.all()
@strawberry_django.field
def clusters(self) -> List[Annotated["ClusterType", strawberry.lazy('virtualization.graphql.types')]]:
return self.clusters.all()
@strawberry_django.type( @strawberry_django.type(
@ -42,7 +62,10 @@ class ClusterGroupType(VLANGroupsMixin, OrganizationalObjectType):
filters=ClusterTypeFilter filters=ClusterTypeFilter
) )
class ClusterTypeType(OrganizationalObjectType): class ClusterTypeType(OrganizationalObjectType):
pass
@strawberry_django.field
def clusters(self) -> List[ClusterType]:
return self.clusters.all()
@strawberry_django.type( @strawberry_django.type(