-
Notifications
You must be signed in to change notification settings - Fork 350
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
Conversation
7110c60
to
e1409ae
Compare
@@ -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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
src/backend/core/tests/documents/test_api_documents_can_edit.py
Outdated
Show resolved
Hide resolved
src/frontend/servers/y-provider/__tests__/getDocumentConnectionInfoHandler.test.ts
Outdated
Show resolved
Hide resolved
247ce1e
to
b964298
Compare
if role == "reader": | ||
assert response.status_code == 401 | ||
else: | ||
assert response.status_code == 200 |
There was a problem hiding this comment.
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.
11398b1
to
34ed3b6
Compare
34ed3b6
to
8e532c2
Compare
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.
8e532c2
to
f13cd0d
Compare
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.
f13cd0d
to
50ce604
Compare
🥳 |
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