mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-23 13:52:17 -06:00
Add GraphQL for users and groups
This commit is contained in:
0
netbox/users/graphql/__init__.py
Normal file
0
netbox/users/graphql/__init__.py
Normal file
12
netbox/users/graphql/schema.py
Normal file
12
netbox/users/graphql/schema.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import graphene
|
||||
|
||||
from netbox.graphql.fields import ObjectField, ObjectListField
|
||||
from .types import *
|
||||
|
||||
|
||||
class UsersQuery(graphene.ObjectType):
|
||||
group = ObjectField(GroupType)
|
||||
groups = ObjectListField(GroupType)
|
||||
|
||||
user = ObjectField(UserType)
|
||||
users = ObjectListField(UserType)
|
||||
37
netbox/users/graphql/types.py
Normal file
37
netbox/users/graphql/types.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from django.contrib.auth.models import Group, User
|
||||
from graphene_django import DjangoObjectType
|
||||
|
||||
from users import filtersets
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
|
||||
__all__ = (
|
||||
'GroupType',
|
||||
'UserType',
|
||||
)
|
||||
|
||||
|
||||
class GroupType(DjangoObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = ('id', 'name')
|
||||
filterset_class = filtersets.GroupFilterSet
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
return RestrictedQuerySet(model=Group)
|
||||
|
||||
|
||||
class UserType(DjangoObjectType):
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = (
|
||||
'id', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff', 'is_active', 'date_joined',
|
||||
'groups',
|
||||
)
|
||||
filterset_class = filtersets.UserFilterSet
|
||||
|
||||
@classmethod
|
||||
def get_queryset(cls, queryset, info):
|
||||
return RestrictedQuerySet(model=User)
|
||||
@@ -17,7 +17,7 @@ class AppTest(APITestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
class UserTest(APIViewTestCases.APIViewTestCase):
|
||||
class UserTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = User
|
||||
view_namespace = 'users'
|
||||
brief_fields = ['display', 'id', 'url', 'username']
|
||||
@@ -48,7 +48,7 @@ class UserTest(APIViewTestCases.APIViewTestCase):
|
||||
User.objects.bulk_create(users)
|
||||
|
||||
|
||||
class GroupTest(APIViewTestCases.APIViewTestCase):
|
||||
class GroupTest(APIViewTestCases.GraphQLTestCase, APIViewTestCases.APIViewTestCase):
|
||||
model = Group
|
||||
view_namespace = 'users'
|
||||
brief_fields = ['display', 'id', 'name', 'url']
|
||||
|
||||
Reference in New Issue
Block a user