refac
This commit is contained in:
1 parent
4023f6722b
commit
638c7ab802
1 file changed
+25
-4
@@ -697,6 +697,31 @@ async def yjs_document_update(sid, data):
|
|||||||
log.warning(f'Session {sid} not in room {room}. Rejecting update.')
|
log.warning(f'Session {sid} not in room {room}. Rejecting update.')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Verify write permission — room membership only proves read access
|
||||||
|
user = SESSION_POOL.get(sid)
|
||||||
|
if not user:
|
||||||
|
return
|
||||||
|
|
||||||
|
if document_id.startswith('note:'):
|
||||||
|
note_id = document_id.split(':')[1]
|
||||||
|
note = await Notes.get_note_by_id(note_id)
|
||||||
|
if not note:
|
||||||
|
log.error(f'Note {note_id} not found')
|
||||||
|
return
|
||||||
|
|
||||||
|
if (
|
||||||
|
user.get('role') != 'admin'
|
||||||
|
and user.get('id') != note.user_id
|
||||||
|
and not await AccessGrants.has_access(
|
||||||
|
user_id=user.get('id'),
|
||||||
|
resource_type='note',
|
||||||
|
resource_id=note.id,
|
||||||
|
permission='write',
|
||||||
|
)
|
||||||
|
):
|
||||||
|
log.warning(f'User {user.get("id")} does not have write access to note {note_id}. Rejecting update.')
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await stop_item_tasks(REDIS, document_id)
|
await stop_item_tasks(REDIS, document_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -724,10 +749,6 @@ async def yjs_document_update(sid, data):
|
|||||||
skip_sid=sid,
|
skip_sid=sid,
|
||||||
)
|
)
|
||||||
|
|
||||||
user = SESSION_POOL.get(sid)
|
|
||||||
if not user:
|
|
||||||
return
|
|
||||||
|
|
||||||
async def debounced_save():
|
async def debounced_save():
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
await document_save_handler(document_id, data.get('data', {}), user)
|
await document_save_handler(document_id, data.get('data', {}), user)
|
||||||
|
|||||||
Reference in new issue
Block a user