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:
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import Annotated, List
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
@ -59,12 +59,15 @@ class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, Ob
|
||||
|
||||
@strawberry_django.type(
|
||||
models.CircuitType,
|
||||
# fields='__all__',
|
||||
exclude=['color',], # bug - remove color from exclude
|
||||
fields='__all__',
|
||||
filters=CircuitTypeFilter
|
||||
)
|
||||
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(
|
||||
|
@ -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.models import CircuitTermination, ProviderNetwork
|
||||
from dcim.graphql.types import (
|
||||
|
@ -2,6 +2,7 @@ import strawberry
|
||||
import strawberry_django
|
||||
from typing import TYPE_CHECKING, Annotated, List, Union
|
||||
|
||||
|
||||
__all__ = (
|
||||
'CabledObjectMixin',
|
||||
'PathEndpointMixin',
|
||||
@ -33,8 +34,18 @@ class CabledObjectMixin:
|
||||
|
||||
@strawberry.type
|
||||
class PathEndpointMixin:
|
||||
pass
|
||||
# @strawberry_django.field
|
||||
# def connected_endpoints(self) -> List[Annotated["ObjectChangeType", strawberry.lazy('.types')]]:
|
||||
# # Handle empty values
|
||||
# return self.connected_endpoints or None
|
||||
|
||||
@strawberry_django.field
|
||||
def link_peers(self) -> List[Annotated[Union[
|
||||
Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')],
|
||||
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
|
||||
|
@ -124,11 +124,11 @@ class CableTerminationType(NetBoxObjectType):
|
||||
|
||||
@strawberry_django.type(
|
||||
models.Cable,
|
||||
# fields='__all__',
|
||||
exclude=('color', ), # bug - temp
|
||||
fields='__all__',
|
||||
filters=CableFilter
|
||||
)
|
||||
class CableType(NetBoxObjectType):
|
||||
color: str
|
||||
|
||||
@strawberry_django.field
|
||||
def terminations(self) -> List[CableTerminationType]:
|
||||
@ -161,6 +161,7 @@ class ConsolePortType(ComponentObjectType, CabledObjectMixin, PathEndpointMixin)
|
||||
filters=ConsolePortTemplateFilter
|
||||
)
|
||||
class ConsolePortTemplateType(ComponentTemplateObjectType):
|
||||
_name: str
|
||||
|
||||
def resolve_type(self, info):
|
||||
return self.type or None
|
||||
|
@ -1,3 +1,5 @@
|
||||
from typing import Annotated, List
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
|
||||
@ -35,6 +37,58 @@ __all__ = (
|
||||
class ConfigContextType(ObjectType):
|
||||
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(
|
||||
models.ConfigTemplate,
|
||||
@ -42,7 +96,22 @@ class ConfigContextType(ObjectType):
|
||||
filters=ConfigTemplateFilter
|
||||
)
|
||||
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(
|
||||
|
@ -31,7 +31,10 @@ class BaseObjectType:
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info, **kwargs):
|
||||
# Enforce object permissions on the queryset
|
||||
if hasattr(queryset, 'restrict'):
|
||||
return queryset.restrict(info.context.request.user, 'view')
|
||||
else:
|
||||
return queryset
|
||||
|
||||
@strawberry_django.field
|
||||
def display(self) -> str:
|
||||
|
@ -743,7 +743,6 @@ if not ENABLE_LOCALIZATION:
|
||||
#
|
||||
STRAWBERRY_DJANGO = {
|
||||
"TYPE_DESCRIPTION_FROM_MODEL_DOCSTRING": True,
|
||||
# "GENERATE_ENUMS_FROM_CHOICES": True,
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -1,3 +1,5 @@
|
||||
from typing import Annotated, List
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
|
||||
@ -24,7 +26,18 @@ __all__ = (
|
||||
filters=ClusterFilter
|
||||
)
|
||||
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(
|
||||
@ -33,7 +46,14 @@ class ClusterType(VLANGroupsMixin, NetBoxObjectType):
|
||||
filters=ClusterGroupFilter
|
||||
)
|
||||
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(
|
||||
@ -42,7 +62,10 @@ class ClusterGroupType(VLANGroupsMixin, OrganizationalObjectType):
|
||||
filters=ClusterTypeFilter
|
||||
)
|
||||
class ClusterTypeType(OrganizationalObjectType):
|
||||
pass
|
||||
|
||||
@strawberry_django.field
|
||||
def clusters(self) -> List[ClusterType]:
|
||||
return self.clusters.all()
|
||||
|
||||
|
||||
@strawberry_django.type(
|
||||
|
Reference in New Issue
Block a user