mirror of
https://github.com/netbox-community/netbox.git
synced 2026-02-05 14:56:24 -06:00
Initial work on contacts
This commit is contained in:
@@ -10,3 +10,15 @@ class TenancyQuery(graphene.ObjectType):
|
||||
|
||||
tenant_group = ObjectField(TenantGroupType)
|
||||
tenant_group_list = ObjectListField(TenantGroupType)
|
||||
|
||||
contact = ObjectField(ContactType)
|
||||
contact_list = ObjectListField(ContactType)
|
||||
|
||||
contact_role = ObjectField(ContactRoleType)
|
||||
contact_role_list = ObjectListField(ContactRoleType)
|
||||
|
||||
contact_group = ObjectField(ContactGroupType)
|
||||
contact_group_list = ObjectListField(ContactGroupType)
|
||||
|
||||
contact_assignment = ObjectField(ContactAssignmentType)
|
||||
contact_assignment_list = ObjectListField(ContactAssignmentType)
|
||||
|
||||
@@ -1,12 +1,29 @@
|
||||
import graphene
|
||||
|
||||
from tenancy import filtersets, models
|
||||
from netbox.graphql.types import OrganizationalObjectType, PrimaryObjectType
|
||||
|
||||
__all__ = (
|
||||
'ContactAssignmentType',
|
||||
'ContactGroupType',
|
||||
'ContactRoleType',
|
||||
'ContactType',
|
||||
'TenantType',
|
||||
'TenantGroupType',
|
||||
)
|
||||
|
||||
|
||||
class ContactAssignmentsMixin:
|
||||
assignments = graphene.List('tenancy.graphql.types.ContactAssignmentType')
|
||||
|
||||
def resolve_assignments(self, info):
|
||||
return self.assignments.restrict(info.context.user, 'view')
|
||||
|
||||
|
||||
#
|
||||
# Tenants
|
||||
#
|
||||
|
||||
class TenantType(PrimaryObjectType):
|
||||
|
||||
class Meta:
|
||||
@@ -21,3 +38,39 @@ class TenantGroupType(OrganizationalObjectType):
|
||||
model = models.TenantGroup
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.TenantGroupFilterSet
|
||||
|
||||
|
||||
#
|
||||
# Contacts
|
||||
#
|
||||
|
||||
class ContactType(ContactAssignmentsMixin, PrimaryObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Contact
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ContactFilterSet
|
||||
|
||||
|
||||
class ContactRoleType(ContactAssignmentsMixin, OrganizationalObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ContactRole
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ContactRoleFilterSet
|
||||
|
||||
|
||||
class ContactGroupType(OrganizationalObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ContactGroup
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ContactGroupFilterSet
|
||||
|
||||
|
||||
class ContactAssignmentType(OrganizationalObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ContactAssignment
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ContactAssignmentFilterSet
|
||||
|
||||
Reference in New Issue
Block a user