Skip to content

Give priority to users connected to collaboration server (aka no websocket feature) #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 7, 2025

Conversation

lunika
Copy link
Member

@lunika lunika commented Jun 25, 2025

Purpose

Some users have no access to the websocket protocol and can't collaborate to a document. This lead to inconsistent document content because they will override the content on every save.

With this PR we implement a new behavior to prevent the loss of data.
Priority is given to users connected to the collaboration server, while users are connected to it, users without websocket can't save their content, no matter if a user without websocket came first on the document.
Also there is a priority between user without websocket. The first user saving a document acquire a lock and this lock remains active while the user is working on the document. After 2 minutes of inactivity, the user release the lock and an other user without a websocket can save its work.

Proposal

  • ✨(y-provider) add endpoint returning document connection state
  • ✨(back) check on document update if user can save it

@lunika lunika requested a review from AntoLC June 25, 2025 15:41
@lunika lunika self-assigned this Jun 25, 2025
@lunika lunika added the enhancement improve an existing feature label Jun 25, 2025
@lunika lunika force-pushed the feat/no-websocket-v2 branch from 7110c60 to e1409ae Compare June 25, 2025 15:43
@lunika lunika requested a review from qbey June 26, 2025 14:10
@@ -470,6 +471,7 @@ class Base(Configuration):
SESSION_COOKIE_AGE = values.PositiveIntegerValue(
default=60 * 60 * 12, environ_name="SESSION_COOKIE_AGE", environ_prefix=None
)
SESSION_COOKIE_NAME = "docs_sessionid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: every user will be disconnected on next deployment

if self._can_user_edit_document(serializer.instance.id, set_cache=True):
return super().perform_update(serializer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to raise a specific error content to display a proper message to the user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to understand what you mean. I raise nothing here.

Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the feature frontside to test if can-edit toggle correctly, seems to works well!

@lunika lunika force-pushed the feat/no-websocket-v2 branch 3 times, most recently from 247ce1e to b964298 Compare July 4, 2025 09:22
if role == "reader":
assert response.status_code == 401
else:
assert response.status_code == 200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the docstring as well.

@AntoLC AntoLC force-pushed the feat/no-websocket-v2 branch 3 times, most recently from 11398b1 to 34ed3b6 Compare July 4, 2025 14:57
@lunika lunika force-pushed the feat/no-websocket-v2 branch from 34ed3b6 to 8e532c2 Compare July 7, 2025 08:04
lunika added 2 commits July 7, 2025 10:15
We need a new endpoint in the y-provider server allowing the backend to
retrieve the number of active connections on a document and if a session
key exists.
When a document is updated, users not connected to the collaboration
server can override work made by other people connected to the
collaboration server. To avoid this, the priority is given to user
connected to the collaboration server. If the websocket property in the
request payload is missing or set to False, the backend fetch the
collaboration server to now if the user can save or not. If users are
already connected, the user can't save. Also, only one user without
websocket can save a connect, the first user saving acquire a lock and
all other users can't save.
To implement this behavior, we need to track all users, connected and
not, so a session is created for every user in the
ForceSessionMiddleware.
@lunika lunika force-pushed the feat/no-websocket-v2 branch from 8e532c2 to f13cd0d Compare July 7, 2025 08:16
lunika and others added 4 commits July 7, 2025 10:20
The endpoint can_edit is added to the DocumentViewset, it will give the
information to the frontend application id the current user can edit the
Docs based on the no-websocket rules.
An already existing feature flag
COLLABORATION_WS_NOT_CONNECTED_READY_ONLY was used bu the frontend
application to disable or not the edition for a user not connected to
the websocket. We want to reuse it in the backend application to disable
or not the no websocket feature.
We added a system to know if a user is alone
on a document or not. We adapt the
frontend to block the edition only
when the user is not alone on the document.
Seems to have some circular dependencies appearing.
We will import what we need directly from the
feature instead of the parent docs index file.
@lunika lunika force-pushed the feat/no-websocket-v2 branch from f13cd0d to 50ce604 Compare July 7, 2025 08:21
@lunika lunika merged commit 50ce604 into main Jul 7, 2025
20 of 21 checks passed
@lunika lunika deleted the feat/no-websocket-v2 branch July 7, 2025 08:41
@virgile-dev
Copy link
Collaborator

🥳

@AntoLC AntoLC mentioned this pull request Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improve an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants