Skip to content
Snippets Groups Projects
Commit 8586b1ab authored by Julian's avatar Julian
Browse files

Include base Deletion Mutation

parent 6753243f
No related branches found
No related tags found
3 merge requests!1237Release 3.0,!1207Resolve "Move DeleteDialog from Plank to Core",!1183Release 3.0
from django.db.models import Model
import graphene
from graphene_django import DjangoObjectType
......@@ -24,3 +26,23 @@ class FieldFileType(graphene.ObjectType):
def resolve_absolute_url(root, info, **kwargs):
return info.context.build_absolute_uri(root.url) if root else ""
class DeleteMutation(graphene.Mutation):
"""Mutation to delete an object."""
klass: Model = None
permission_required: str = ""
ok = graphene.Boolean()
class Arguments:
id = graphene.ID() # noqa
@classmethod
def mutate(cls, root, info, **kwargs):
obj = cls.klass.objects.get(pk=kwargs["id"])
if info.context.user.has_perm(cls.permission_required, obj):
obj.delete()
return cls(ok=True)
else:
raise Exception("Permission denied")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment