mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 12:06:53 -06:00
Add changelog GraphQL relation for changelogged models
This commit is contained in:
parent
1518a460d5
commit
88d2441ab3
@ -1,5 +1,5 @@
|
||||
from circuits import filtersets, models
|
||||
from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType
|
||||
from netbox.graphql.types import ObjectType, OrganizationalObjectType, PrimaryObjectType
|
||||
|
||||
__all__ = (
|
||||
'CircuitTerminationType',
|
||||
@ -10,7 +10,7 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
class CircuitTerminationType(BaseObjectType):
|
||||
class CircuitTerminationType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.CircuitTermination
|
||||
|
@ -1,5 +1,5 @@
|
||||
from dcim import filtersets, models
|
||||
from extras.graphql.mixins import CustomFieldsMixin, ImageAttachmentsMixin, TagsMixin
|
||||
from extras.graphql.mixins import ChangelogMixin, CustomFieldsMixin, ImageAttachmentsMixin, TagsMixin
|
||||
from ipam.graphql.mixins import IPAddressesMixin, VLANGroupsMixin
|
||||
from netbox.graphql.types import BaseObjectType, OrganizationalObjectType, PrimaryObjectType
|
||||
|
||||
@ -47,6 +47,7 @@ __all__ = (
|
||||
|
||||
|
||||
class ComponentObjectType(
|
||||
ChangelogMixin,
|
||||
CustomFieldsMixin,
|
||||
TagsMixin,
|
||||
BaseObjectType
|
||||
@ -59,6 +60,7 @@ class ComponentObjectType(
|
||||
|
||||
|
||||
class ComponentTemplateObjectType(
|
||||
ChangelogMixin,
|
||||
BaseObjectType
|
||||
):
|
||||
"""
|
||||
|
@ -2,6 +2,7 @@ import graphene
|
||||
from graphene.types.generic import GenericScalar
|
||||
|
||||
__all__ = (
|
||||
'ChangelogMixin',
|
||||
'CustomFieldsMixin',
|
||||
'ImageAttachmentsMixin',
|
||||
'JournalEntriesMixin',
|
||||
@ -9,6 +10,13 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
class ChangelogMixin:
|
||||
changelog = graphene.List('extras.graphql.types.ObjectChangeType')
|
||||
|
||||
def resolve_changelog(self, info):
|
||||
return self.object_changes.restrict(info.context.user, 'view')
|
||||
|
||||
|
||||
class CustomFieldsMixin:
|
||||
custom_fields = GenericScalar()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from extras import filtersets, models
|
||||
from netbox.graphql.types import BaseObjectType
|
||||
from netbox.graphql.types import BaseObjectType, ObjectType
|
||||
|
||||
__all__ = (
|
||||
'ConfigContextType',
|
||||
@ -8,12 +8,13 @@ __all__ = (
|
||||
'ExportTemplateType',
|
||||
'ImageAttachmentType',
|
||||
'JournalEntryType',
|
||||
'ObjectChangeType',
|
||||
'TagType',
|
||||
'WebhookType',
|
||||
)
|
||||
|
||||
|
||||
class ConfigContextType(BaseObjectType):
|
||||
class ConfigContextType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ConfigContext
|
||||
@ -21,7 +22,7 @@ class ConfigContextType(BaseObjectType):
|
||||
filterset_class = filtersets.ConfigContextFilterSet
|
||||
|
||||
|
||||
class CustomFieldType(BaseObjectType):
|
||||
class CustomFieldType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.CustomField
|
||||
@ -29,7 +30,7 @@ class CustomFieldType(BaseObjectType):
|
||||
filterset_class = filtersets.CustomFieldFilterSet
|
||||
|
||||
|
||||
class CustomLinkType(BaseObjectType):
|
||||
class CustomLinkType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.CustomLink
|
||||
@ -37,7 +38,7 @@ class CustomLinkType(BaseObjectType):
|
||||
filterset_class = filtersets.CustomLinkFilterSet
|
||||
|
||||
|
||||
class ExportTemplateType(BaseObjectType):
|
||||
class ExportTemplateType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ExportTemplate
|
||||
@ -53,7 +54,7 @@ class ImageAttachmentType(BaseObjectType):
|
||||
filterset_class = filtersets.ImageAttachmentFilterSet
|
||||
|
||||
|
||||
class JournalEntryType(BaseObjectType):
|
||||
class JournalEntryType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.JournalEntry
|
||||
@ -61,7 +62,15 @@ class JournalEntryType(BaseObjectType):
|
||||
filterset_class = filtersets.JournalEntryFilterSet
|
||||
|
||||
|
||||
class TagType(BaseObjectType):
|
||||
class ObjectChangeType(BaseObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.ObjectChange
|
||||
fields = '__all__'
|
||||
filterset_class = filtersets.ObjectChangeFilterSet
|
||||
|
||||
|
||||
class TagType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Tag
|
||||
@ -69,7 +78,7 @@ class TagType(BaseObjectType):
|
||||
filterset_class = filtersets.TagFilterSet
|
||||
|
||||
|
||||
class WebhookType(BaseObjectType):
|
||||
class WebhookType(ObjectType):
|
||||
|
||||
class Meta:
|
||||
model = models.Webhook
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from graphene_django import DjangoObjectType
|
||||
|
||||
from extras.graphql.mixins import CustomFieldsMixin, JournalEntriesMixin, TagsMixin
|
||||
from extras.graphql.mixins import ChangelogMixin, CustomFieldsMixin, JournalEntriesMixin, TagsMixin
|
||||
|
||||
__all__ = (
|
||||
'BaseObjectType',
|
||||
@ -27,7 +27,19 @@ class BaseObjectType(DjangoObjectType):
|
||||
return queryset.restrict(info.context.user, 'view')
|
||||
|
||||
|
||||
class ObjectType(
|
||||
ChangelogMixin,
|
||||
BaseObjectType
|
||||
):
|
||||
"""
|
||||
Base GraphQL object type for unclassified models which support change logging
|
||||
"""
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class OrganizationalObjectType(
|
||||
ChangelogMixin,
|
||||
CustomFieldsMixin,
|
||||
BaseObjectType
|
||||
):
|
||||
@ -39,6 +51,7 @@ class OrganizationalObjectType(
|
||||
|
||||
|
||||
class PrimaryObjectType(
|
||||
ChangelogMixin,
|
||||
CustomFieldsMixin,
|
||||
JournalEntriesMixin,
|
||||
TagsMixin,
|
||||
|
@ -40,6 +40,11 @@ class ChangeLoggingMixin(models.Model):
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
object_changes = GenericRelation(
|
||||
to='extras.ObjectChange',
|
||||
content_type_field='changed_object_type',
|
||||
object_id_field='changed_object_id'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
Loading…
Reference in New Issue
Block a user