mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 13:06:30 -06:00
9856 user and circuits base
This commit is contained in:
parent
eceac90b1c
commit
700f015942
93
netbox/circuits/graphql/filters.py
Normal file
93
netbox/circuits/graphql/filters.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import strawberry
|
||||||
|
from strawberry import auto
|
||||||
|
from circuits import models, filtersets
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'CircuitTerminationFilter',
|
||||||
|
'CircuitFilter',
|
||||||
|
'CircuitTypeFilter',
|
||||||
|
'ProviderFilter',
|
||||||
|
'ProviderAccountFilter',
|
||||||
|
'ProviderNetworkFilter',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.CircuitTermination, lookups=True)
|
||||||
|
class CircuitTerminationFilter(filtersets.CircuitTerminationFilterSet):
|
||||||
|
id: auto
|
||||||
|
term_side: auto
|
||||||
|
port_speed: auto
|
||||||
|
upstream_speed: auto
|
||||||
|
xconnect_id: auto
|
||||||
|
description: auto
|
||||||
|
cable_end: auto
|
||||||
|
# q: auto
|
||||||
|
circuit_id: auto
|
||||||
|
site_id: auto
|
||||||
|
site: auto
|
||||||
|
# provider_network_id: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.Circuit, lookups=True)
|
||||||
|
class CircuitFilter(filtersets.CircuitFilterSet):
|
||||||
|
id: auto
|
||||||
|
cid: auto
|
||||||
|
description: auto
|
||||||
|
install_date: auto
|
||||||
|
termination_date: auto
|
||||||
|
commit_rate: auto
|
||||||
|
provider_id: auto
|
||||||
|
provider: auto
|
||||||
|
provider_account_id: auto
|
||||||
|
# provider_network_id: auto
|
||||||
|
type_id: auto
|
||||||
|
type: auto
|
||||||
|
status: auto
|
||||||
|
# region_id: auto
|
||||||
|
# region: auto
|
||||||
|
# site_group_id: auto
|
||||||
|
# site_group: auto
|
||||||
|
# site_id: auto
|
||||||
|
# site: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.CircuitType, lookups=True)
|
||||||
|
class CircuitTypeFilter(filtersets.CircuitTypeFilterSet):
|
||||||
|
id: auto
|
||||||
|
name: auto
|
||||||
|
slug: auto
|
||||||
|
description: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.Provider, lookups=True)
|
||||||
|
class ProviderFilter(filtersets.ProviderFilterSet):
|
||||||
|
id: auto
|
||||||
|
name: auto
|
||||||
|
slug: auto
|
||||||
|
# region_id: auto
|
||||||
|
# region: auto
|
||||||
|
# site_group_id: auto
|
||||||
|
# site_group: auto
|
||||||
|
# site_id: auto
|
||||||
|
# site: auto
|
||||||
|
# asn_id: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.ProviderAccount, lookups=True)
|
||||||
|
class ProviderAccountFilter(filtersets.ProviderAccountFilterSet):
|
||||||
|
id: auto
|
||||||
|
name: auto
|
||||||
|
account: auto
|
||||||
|
description: auto
|
||||||
|
# provider_id: auto
|
||||||
|
# provider: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(models.ProviderNetwork, lookups=True)
|
||||||
|
class ProviderNetworkFilter(filtersets.ProviderNetworkFilterSet):
|
||||||
|
id: auto
|
||||||
|
name: auto
|
||||||
|
service_id: auto
|
||||||
|
description: auto
|
||||||
|
# provider_id: auto
|
||||||
|
# provider: auto
|
@ -1,41 +1,26 @@
|
|||||||
import graphene
|
from typing import List
|
||||||
|
import strawberry
|
||||||
|
|
||||||
from circuits import models
|
from circuits import models
|
||||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
|
||||||
from .types import *
|
from .types import *
|
||||||
from utilities.graphql_optimizer import gql_query_optimizer
|
|
||||||
|
|
||||||
|
|
||||||
class CircuitsQuery(graphene.ObjectType):
|
@strawberry.type
|
||||||
circuit = ObjectField(CircuitType)
|
class CircuitsQuery:
|
||||||
circuit_list = ObjectListField(CircuitType)
|
circuit: CircuitType = strawberry.django.field()
|
||||||
|
circuit_list: List[CircuitType] = strawberry.django.field()
|
||||||
|
|
||||||
def resolve_circuit_list(root, info, **kwargs):
|
circuit_termination: CircuitTerminationType = strawberry.django.field()
|
||||||
return gql_query_optimizer(models.Circuit.objects.all(), info)
|
circuit_termination_list: List[CircuitTerminationType] = strawberry.django.field()
|
||||||
|
|
||||||
circuit_termination = ObjectField(CircuitTerminationType)
|
circuit_type: CircuitTypeType = strawberry.django.field()
|
||||||
circuit_termination_list = ObjectListField(CircuitTerminationType)
|
circuit_type_list: List[CircuitTypeType] = strawberry.django.field()
|
||||||
|
|
||||||
def resolve_circuit_termination_list(root, info, **kwargs):
|
provider: ProviderType = strawberry.django.field()
|
||||||
return gql_query_optimizer(models.CircuitTermination.objects.all(), info)
|
provider_list: List[ProviderType] = strawberry.django.field()
|
||||||
|
|
||||||
circuit_type = ObjectField(CircuitTypeType)
|
provider_account: ProviderAccountType = strawberry.django.field()
|
||||||
circuit_type_list = ObjectListField(CircuitTypeType)
|
provider_account_list: List[ProviderAccountType] = strawberry.django.field()
|
||||||
|
|
||||||
def resolve_circuit_type_list(root, info, **kwargs):
|
provider_network: ProviderNetworkType = strawberry.django.field()
|
||||||
return gql_query_optimizer(models.CircuitType.objects.all(), info)
|
provider_network_list: List[ProviderNetworkType] = strawberry.django.field()
|
||||||
|
|
||||||
provider = ObjectField(ProviderType)
|
|
||||||
provider_list = ObjectListField(ProviderType)
|
|
||||||
|
|
||||||
def resolve_provider_list(root, info, **kwargs):
|
|
||||||
return gql_query_optimizer(models.Provider.objects.all(), info)
|
|
||||||
|
|
||||||
provider_account = ObjectField(ProviderAccountType)
|
|
||||||
provider_account_list = ObjectListField(ProviderAccountType)
|
|
||||||
|
|
||||||
provider_network = ObjectField(ProviderNetworkType)
|
|
||||||
provider_network_list = ObjectListField(ProviderNetworkType)
|
|
||||||
|
|
||||||
def resolve_provider_network_list(root, info, **kwargs):
|
|
||||||
return gql_query_optimizer(models.ProviderNetwork.objects.all(), info)
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import graphene
|
import strawberry
|
||||||
|
|
||||||
from circuits import filtersets, models
|
from circuits import filtersets, models
|
||||||
from dcim.graphql.mixins import CabledObjectMixin
|
from dcim.graphql.mixins import CabledObjectMixin
|
||||||
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin
|
from extras.graphql.mixins import CustomFieldsMixin, TagsMixin, ContactsMixin
|
||||||
from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObjectType
|
from netbox.graphql.types import ObjectType, OrganizationalObjectType, NetBoxObjectType
|
||||||
|
from .filters import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'CircuitTerminationType',
|
'CircuitTerminationType',
|
||||||
@ -15,48 +16,61 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
|
@strawberry.django.type(
|
||||||
|
models.CircuitTermination,
|
||||||
class Meta:
|
fields='__all__',
|
||||||
model = models.CircuitTermination
|
filters=CircuitTerminationFilter
|
||||||
fields = '__all__'
|
)
|
||||||
filterset_class = filtersets.CircuitTerminationFilterSet
|
class CircuitTerminationType:
|
||||||
|
# class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.type(
|
||||||
|
models.Circuit,
|
||||||
|
fields='__all__',
|
||||||
|
filters=CircuitFilter
|
||||||
|
)
|
||||||
class CircuitType(NetBoxObjectType, ContactsMixin):
|
class CircuitType(NetBoxObjectType, ContactsMixin):
|
||||||
class Meta:
|
# class CircuitType(NetBoxObjectType, ContactsMixin):
|
||||||
model = models.Circuit
|
pass
|
||||||
fields = '__all__'
|
|
||||||
filterset_class = filtersets.CircuitFilterSet
|
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeType(OrganizationalObjectType):
|
@strawberry.django.type(
|
||||||
|
models.CircuitType,
|
||||||
class Meta:
|
fields='__all__',
|
||||||
model = models.CircuitType
|
filters=CircuitTypeFilter
|
||||||
fields = '__all__'
|
)
|
||||||
filterset_class = filtersets.CircuitTypeFilterSet
|
class CircuitTypeType:
|
||||||
|
# class CircuitTypeType(OrganizationalObjectType):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProviderType(NetBoxObjectType, ContactsMixin):
|
@strawberry.django.type(
|
||||||
|
models.Provider,
|
||||||
class Meta:
|
fields='__all__',
|
||||||
model = models.Provider
|
filters=ProviderFilter
|
||||||
fields = '__all__'
|
)
|
||||||
filterset_class = filtersets.ProviderFilterSet
|
class ProviderType:
|
||||||
|
# class ProviderType(NetBoxObjectType, ContactsMixin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountType(NetBoxObjectType):
|
@strawberry.django.type(
|
||||||
|
models.ProviderAccount,
|
||||||
class Meta:
|
fields='__all__',
|
||||||
model = models.ProviderAccount
|
filters=ProviderAccountFilter
|
||||||
fields = '__all__'
|
)
|
||||||
filterset_class = filtersets.ProviderAccountFilterSet
|
class ProviderAccountType:
|
||||||
|
# class ProviderAccountType(NetBoxObjectType):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkType(NetBoxObjectType):
|
@strawberry.django.type(
|
||||||
|
models.ProviderNetwork,
|
||||||
class Meta:
|
fields='__all__',
|
||||||
model = models.ProviderNetwork
|
filters=ProviderNetworkFilter
|
||||||
fields = '__all__'
|
)
|
||||||
filterset_class = filtersets.ProviderNetworkFilterSet
|
class ProviderNetworkType:
|
||||||
|
# class ProviderNetworkType(NetBoxObjectType):
|
||||||
|
pass
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import strawberry
|
||||||
import graphene
|
import graphene
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from graphene.types.generic import GenericScalar
|
from graphene.types.generic import GenericScalar
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import strawberry
|
import strawberry
|
||||||
from strawberry_django.optimizer import DjangoOptimizerExtension
|
from strawberry_django.optimizer import DjangoOptimizerExtension
|
||||||
from strawberry.schema.config import StrawberryConfig
|
from strawberry.schema.config import StrawberryConfig
|
||||||
|
from circuits.graphql.schema import CircuitsQuery
|
||||||
from users.graphql.schema import UsersQuery
|
from users.graphql.schema import UsersQuery
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class Query(UsersQuery):
|
class Query(CircuitsQuery, UsersQuery):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import graphene
|
import strawberry
|
||||||
|
from strawberry import auto
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from extras.graphql.mixins import (
|
from extras.graphql.mixins import (
|
||||||
@ -7,7 +8,6 @@ from extras.graphql.mixins import (
|
|||||||
JournalEntriesMixin,
|
JournalEntriesMixin,
|
||||||
TagsMixin,
|
TagsMixin,
|
||||||
)
|
)
|
||||||
from graphene_django import DjangoObjectType
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'BaseObjectType',
|
'BaseObjectType',
|
||||||
@ -21,20 +21,17 @@ __all__ = (
|
|||||||
# Base types
|
# Base types
|
||||||
#
|
#
|
||||||
|
|
||||||
class BaseObjectType(DjangoObjectType):
|
class BaseObjectType:
|
||||||
"""
|
"""
|
||||||
Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions.
|
Base GraphQL object type for all NetBox objects. Restricts the model queryset to enforce object permissions.
|
||||||
"""
|
"""
|
||||||
display = graphene.String()
|
display: auto
|
||||||
class_type = graphene.String()
|
class_type: auto
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_queryset(cls, queryset, info):
|
def get_queryset(cls, queryset, info):
|
||||||
# Enforce object permissions on the queryset
|
# Enforce object permissions on the queryset
|
||||||
return queryset.restrict(info.context.user, 'view')
|
return queryset.restrict(info.context.request.user, 'view')
|
||||||
|
|
||||||
def resolve_display(parent, info, **kwargs):
|
def resolve_display(parent, info, **kwargs):
|
||||||
return str(parent)
|
return str(parent)
|
||||||
@ -50,8 +47,7 @@ class ObjectType(
|
|||||||
"""
|
"""
|
||||||
Base GraphQL object type for unclassified models which support change logging
|
Base GraphQL object type for unclassified models which support change logging
|
||||||
"""
|
"""
|
||||||
class Meta:
|
pass
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class OrganizationalObjectType(
|
class OrganizationalObjectType(
|
||||||
@ -63,8 +59,7 @@ class OrganizationalObjectType(
|
|||||||
"""
|
"""
|
||||||
Base type for organizational models
|
Base type for organizational models
|
||||||
"""
|
"""
|
||||||
class Meta:
|
pass
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class NetBoxObjectType(
|
class NetBoxObjectType(
|
||||||
@ -77,15 +72,14 @@ class NetBoxObjectType(
|
|||||||
"""
|
"""
|
||||||
GraphQL type for most NetBox models. Includes support for custom fields, change logging, journaling, and tags.
|
GraphQL type for most NetBox models. Includes support for custom fields, change logging, journaling, and tags.
|
||||||
"""
|
"""
|
||||||
class Meta:
|
pass
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Miscellaneous types
|
# Miscellaneous types
|
||||||
#
|
#
|
||||||
|
|
||||||
class ContentTypeType(DjangoObjectType):
|
class ContentTypeType:
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ContentType
|
model = ContentType
|
||||||
|
28
netbox/users/graphql/filters.py
Normal file
28
netbox/users/graphql/filters.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import strawberry
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.auth.models import Group
|
||||||
|
from strawberry import auto
|
||||||
|
from users import filtersets
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'GroupFilter',
|
||||||
|
'UserFilter',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(Group, lookups=True)
|
||||||
|
class GroupFilter(filtersets.GroupFilterSet):
|
||||||
|
id: auto
|
||||||
|
name: auto
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.django.filter(get_user_model(), lookups=True)
|
||||||
|
class UserFilter(filtersets.UserFilterSet):
|
||||||
|
id: auto
|
||||||
|
username: auto
|
||||||
|
first_name: auto
|
||||||
|
last_name: auto
|
||||||
|
email: auto
|
||||||
|
is_staff: auto
|
||||||
|
is_active: auto
|
||||||
|
is_superuser: auto
|
@ -3,7 +3,6 @@ import strawberry
|
|||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
|
||||||
from .types import *
|
from .types import *
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user