diff --git a/jupyter_server_documents/rooms/yroom_file_api.py b/jupyter_server_documents/rooms/yroom_file_api.py index 72eabd1..afaa6b2 100644 --- a/jupyter_server_documents/rooms/yroom_file_api.py +++ b/jupyter_server_documents/rooms/yroom_file_api.py @@ -105,6 +105,7 @@ def __init__(self, *args, **kwargs): self._last_path = None self._last_modified = None self._stopped = False + self._is_writable = True # Initialize content-related primitives self._content_loading = False @@ -199,6 +200,10 @@ async def _load_content(self, jupyter_ydoc: YBaseDoc) -> None: format=self.file_format )) + # The content manager uses this to tell consumers of the API if the file is writable. + # We need to save this so we can use it during save. + self._is_writable = file_data.get('writable', True) + if self.file_type == "notebook": self.log.info(f"Processing outputs for loaded notebook: '{self.room_id}'.") file_data = self.outputs_manager.process_loaded_notebook(file_id=self.file_id, file_data=file_data) @@ -364,6 +369,9 @@ async def save(self, jupyter_ydoc: YBaseDoc): instead. """ try: + # Return immediately if the content manager has marked this file as non-writable + if not self._is_writable: + return # Build arguments to `CM.save()` path = self.get_path() content = jupyter_ydoc.source