Skip to content

Commit

Permalink
Adapt locking due to deprecation (collaborative editing)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronmolnar committed Mar 15, 2024
1 parent b96bfd3 commit a56d4c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions reptor/api/NotesAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,31 @@ def upload_file(

def _do_lock(self, note_id: str):
url = urljoin(self.base_endpoint, note_id, "lock/")
return self.post(url)
try:
return self.post(url)
except HTTPError as e:
if e.response.status_code == 404:
# Collaborative editing doesn't support locking
pass
else:
raise e
return

def _do_unlock(self, note_id: str):
url = urljoin(self.base_endpoint, note_id, "unlock/")
return self.post(url)
try:
self.post(url)
except HTTPError as e:
if e.response.status_code == 404:
# Collaborative editing doesn't support locking
pass
else:
raise e
return

@contextlib.contextmanager
def _lock_note(self, note_id: str, force_unlock: bool = False):
r = None
try:
r = self._do_lock(note_id)
except HTTPError as e:
Expand All @@ -309,9 +326,12 @@ def _lock_note(self, note_id: str, force_unlock: bool = False):
raise LockedException(f"Cannot unlock. Locked by @{locked_by}.")
else:
raise LockedException("Cannot unlock. Locked by other user.")
elif e.response.status_code == 404:
# Collaborative editing doesn't support locking
pass
else:
raise e
if not force_unlock and r.status_code == 200:
if not force_unlock and r and r.status_code == 200:
raise LockedException(
"This note is locked. (Unlock or force: --force-unlock)"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_notes_upload_with_notetitle(self, private_uploads_id):
assert note is not None
assert note_content.decode() in note["text"]

@pytest.mark.skip(reason="Locking is being deprecated.")
def test_locked_notes(self, private_notes_api, private_uploads_id):
# Lock "Uploads" note via notes_api
private_notes_api._do_lock(private_uploads_id)
Expand Down

0 comments on commit a56d4c7

Please sign in to comment.