From 5f6817ebbef204a9cb2f92bde3964a220661d04f Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Thu, 16 Jan 2020 09:48:38 +0100 Subject: [PATCH] Use slug to identify instruments on server --- server/notes/inputs.py | 3 ++- server/notes/mutations.py | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/server/notes/inputs.py b/server/notes/inputs.py index 31e1ada3..cbf8440c 100644 --- a/server/notes/inputs.py +++ b/server/notes/inputs.py @@ -4,7 +4,8 @@ from graphene import InputObjectType class AddNoteArgument(InputObjectType): content = graphene.UUID() - content_block = graphene.ID() + block = graphene.String() + type = graphene.String() parent = graphene.ID() text = graphene.String(required=True) diff --git a/server/notes/mutations.py b/server/notes/mutations.py index 900317ca..c9d77a0f 100644 --- a/server/notes/mutations.py +++ b/server/notes/mutations.py @@ -59,18 +59,27 @@ class AddNote(relay.ClientIDMutation): note = kwargs.get('note') content_uuid = note.get('content', '') - content_block_id = note.get('content_block', '') + content_block_id = note.get('block', '') parent = note.get('parent') text = note.get('text') if content_uuid != '': - content_block = get_object(ContentBlock, content_block_id) + type = note.get('type') + if type == 'ContentBlockNode': + content_block = get_object(ContentBlock, content_block_id) - bookmark = ContentBlockBookmark.objects.get( - content_block=content_block, - uuid=content_uuid, - user=user - ) + bookmark = ContentBlockBookmark.objects.get( + content_block=content_block, + uuid=content_uuid, + user=user + ) + else: + instrument = BasicKnowledge.objects.get(slug=content_block_id) + bookmark = InstrumentBookmark.objects.get( + instrument=instrument, + uuid=content_uuid, + user=user + ) else: type, id = from_global_id(parent) if type == 'ModuleNode': @@ -176,7 +185,7 @@ class UpdateModuleBookmark(relay.ClientIDMutation): class UpdateInstrumentBookmark(relay.ClientIDMutation): class Input: uuid = graphene.UUID(required=True) - instrument = graphene.ID(required=True) + instrument = graphene.String(required=True) bookmarked = graphene.Boolean(required=True) success = graphene.Boolean() @@ -184,11 +193,11 @@ class UpdateInstrumentBookmark(relay.ClientIDMutation): @classmethod def mutate_and_get_payload(cls, root, info, **kwargs): user = info.context.user - instrument_id = kwargs.get('instrument') + instrument_slug = kwargs.get('instrument') uuid = kwargs.get('uuid') bookmarked = kwargs.get('bookmarked') - instrument = get_object(BasicKnowledge, instrument_id) + instrument = BasicKnowledge.objects.get(slug=instrument_slug) if bookmarked: InstrumentBookmark.objects.create(