mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 13:06:30 -06:00
9856 user and group
This commit is contained in:
parent
3f2c21f005
commit
eceac90b1c
@ -1,18 +1,18 @@
|
|||||||
import strawberry
|
import strawberry
|
||||||
from strawberry_django.optimizer import DjangoOptimizerExtension
|
from strawberry_django.optimizer import DjangoOptimizerExtension
|
||||||
|
from strawberry.schema.config import StrawberryConfig
|
||||||
|
from users.graphql.schema import UsersQuery
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class User:
|
class Query(UsersQuery):
|
||||||
name: str
|
pass
|
||||||
age: int
|
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
schema = strawberry.Schema(
|
||||||
class Query:
|
query=Query,
|
||||||
@strawberry.field
|
config=StrawberryConfig(auto_camel_case=False),
|
||||||
def user(self) -> User:
|
extensions=[
|
||||||
return User(name="Patrick", age=100)
|
DjangoOptimizerExtension,
|
||||||
|
]
|
||||||
|
)
|
||||||
schema = strawberry.Schema(query=Query)
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
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 django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
import graphene
|
from typing import List
|
||||||
|
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 netbox.graphql.fields import ObjectField, ObjectListField
|
||||||
from .types import *
|
from .types import *
|
||||||
from utilities.graphql_optimizer import gql_query_optimizer
|
|
||||||
|
|
||||||
|
|
||||||
class UsersQuery(graphene.ObjectType):
|
@strawberry.type
|
||||||
group = ObjectField(GroupType)
|
class UsersQuery:
|
||||||
group_list = ObjectListField(GroupType)
|
group: GroupType = strawberry.django.field()
|
||||||
|
group_list: List[GroupType] = strawberry.django.field()
|
||||||
|
|
||||||
def resolve_group_list(root, info, **kwargs):
|
user: UserType = strawberry.django.field()
|
||||||
return gql_query_optimizer(Group.objects.all(), info)
|
user_list: List[UserType] = strawberry.django.field()
|
||||||
|
|
||||||
user = ObjectField(UserType)
|
|
||||||
user_list = ObjectListField(UserType)
|
|
||||||
|
|
||||||
def resolve_user_list(root, info, **kwargs):
|
|
||||||
return gql_query_optimizer(get_user_model().objects.all(), info)
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
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 graphene_django import DjangoObjectType
|
from strawberry import auto
|
||||||
|
|
||||||
from users import filtersets
|
from users import filtersets
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
from .filters import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'GroupType',
|
'GroupType',
|
||||||
@ -11,28 +12,26 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class GroupType(DjangoObjectType):
|
@strawberry.django.type(
|
||||||
|
Group,
|
||||||
class Meta:
|
fields=['id', 'name'],
|
||||||
model = Group
|
filters=GroupFilter
|
||||||
fields = ('id', 'name')
|
)
|
||||||
filterset_class = filtersets.GroupFilterSet
|
class GroupType:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_queryset(cls, queryset, info):
|
def get_queryset(cls, queryset, info, **kwargs):
|
||||||
return RestrictedQuerySet(model=Group).restrict(info.context.user, 'view')
|
return RestrictedQuerySet(model=Group).restrict(info.context.request.user, 'view')
|
||||||
|
|
||||||
|
|
||||||
class UserType(DjangoObjectType):
|
@strawberry.django.type(
|
||||||
|
get_user_model(),
|
||||||
class Meta:
|
fields=[
|
||||||
model = get_user_model()
|
'id', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff',
|
||||||
fields = (
|
'is_active', 'date_joined', 'groups',
|
||||||
'id', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff', 'is_active', 'date_joined',
|
],
|
||||||
'groups',
|
filters=UserFilter
|
||||||
)
|
)
|
||||||
filterset_class = filtersets.UserFilterSet
|
class UserType:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_queryset(cls, queryset, info):
|
def get_queryset(cls, queryset, info, **kwargs):
|
||||||
return RestrictedQuerySet(model=get_user_model()).restrict(info.context.user, 'view')
|
return RestrictedQuerySet(model=get_user_model()).restrict(info.context.request.user, 'view')
|
||||||
|
Loading…
Reference in New Issue
Block a user