-
Notifications
You must be signed in to change notification settings - Fork 472
Description
Feature Request
Adding the role commenter brings some challenges because a commenter does not have the editing abilities but can create a thread and to create a thread, we need to add a "mark" on the document, meaning editing the document.
In simple:
- commenter cannot edit
- commenter can create a thread
- create thread needs editing
Possible solution
Add the "mark" backend side
What Blocknote do in their REST example.
They made a setter to add a mark to a document, backend nodejs side: https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus/blob/main/hocuspocus-server/src/setMark.ts
They setup a nodejs server with some routes to interact with the document backend side, the route that interest us is /:threadId/addToDocument, it is this one setting the mark:
https://github.com/TypeCellOS/BlockNote-demo-nextjs-hocuspocus/blob/main/hocuspocus-server/src/threads.ts#L85-L98
Frontend side, when they create a thread, they call addThreadToDocument: https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/comments/extension.ts#L337-L340
It will then call this route backend side that will add the mark:
https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/comments/threadstore/yjs/RESTYjsThreadStore.ts#L61
How can we replicate that
As Blocknote is doing we will send the necessary informations to the routes POST threads:
docs/src/frontend/apps/impress/src/features/docs/doc-editor/components/comments/DocsThreadStore.tsx
Lines 202 to 215 in 54fe70d
| public createThread = async (options: { | |
| initialComment: { | |
| body: CommentBody; | |
| metadata?: unknown; | |
| }; | |
| metadata?: unknown; | |
| }) => { | |
| const response = await fetchAPI(`documents/${this.docId}/threads/`, { | |
| method: 'POST', | |
| body: JSON.stringify({ | |
| body: options.initialComment.body, | |
| }), | |
| }); | |
If the user has the right (at least "commenter"), the backend will call the collaboration server to add a mark to the document:
docs/src/backend/core/api/viewsets.py
Lines 2192 to 2203 in 54fe70d
| def perform_create(self, serializer): | |
| """Create the first comment of the thread.""" | |
| body = serializer.validated_data["body"] | |
| del serializer.validated_data["body"] | |
| thread = serializer.save() | |
| models.Comment.objects.create( | |
| thread=thread, | |
| user=self.request.user if self.request.user.is_authenticated else None, | |
| body=body, | |
| ) | |
To do so, we will have to implement a new route setMark as here, setMark would be expose only to the Django backend:
docs/src/frontend/servers/y-provider/src/servers/appServer.ts
Lines 45 to 50 in 54fe70d
| app.get( | |
| routes.COLLABORATION_GET_CONNECTIONS, | |
| httpSecurity, | |
| getDocumentConnectionInfoHandler, | |
| ); | |
Thanks to the collaboration server, the mark should appear instantly to the client when it is set.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status