Skip to content

✨Role "Commenter" on Docs #1691

@AntoLC

Description

@AntoLC

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:

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:

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:

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

No one assigned

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions