From 88dd396febfe65586022202929fa4c37282e4452 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 3 Nov 2007 08:15:39 +0000 Subject: [PATCH] Fix for: I get "that note is in the trash" error when clicking on an old revision of a note that's not in the trash. This is because that particular revision of the note represents when the note used to be in the trash (because it was previously deleted). --- controller/Notebooks.py | 5 +++++ controller/test/Test_notebooks.py | 34 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/controller/Notebooks.py b/controller/Notebooks.py index adae9ad..44493c3 100644 --- a/controller/Notebooks.py +++ b/controller/Notebooks.py @@ -175,6 +175,11 @@ class Notebooks( object ): if note and note.notebook_id != notebook_id: notebook = self.__database.load( Notebook, notebook_id ) if notebook and note.notebook_id == notebook.trash_id: + if revision: + return dict( + note = note, + ) + return dict( note = None, note_id_in_trash = note.object_id, diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index 76a40eb..e5993bb 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -343,6 +343,18 @@ class Test_notebooks( Test_controller ): user = self.database.load( User, self.user.object_id ) assert user.storage_bytes == 0 + def test_load_note_with_incorrect_notebook( self ): + self.login() + + result = self.http_post( "/notebooks/load_note/", dict( + notebook_id = self.anon_notebook.object_id, + note_id = self.note.object_id, + ), session_id = self.session_id ) + + assert result.get( "error" ) + user = self.database.load( User, self.user.object_id ) + assert user.storage_bytes == 0 + def test_load_unknown_note( self ): self.login() @@ -1177,7 +1189,14 @@ class Test_notebooks( Test_controller ): note_id = self.note.object_id, ), session_id = self.session_id ) - # then undelete it + # get the revision of the deleted note + result = self.http_post( "/notebooks/load_note/", dict( + notebook_id = self.trash.object_id, + note_id = self.note.object_id, + ), session_id = self.session_id ) + deleted_revision = result[ "note" ].revision + + # then undelete the note result = self.http_post( "/notebooks/undelete_note/", dict( notebook_id = self.notebook.object_id, note_id = self.note.object_id, @@ -1199,6 +1218,19 @@ class Test_notebooks( Test_controller ): assert note.deleted_from_id == None assert note.notebook_id == self.notebook.object_id + # test that the revision of the note from when it was deleted is loadable + result = self.http_post( "/notebooks/load_note/", dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + revision = deleted_revision, + ), session_id = self.session_id ) + + note = result.get( "note" ) + assert note + assert note.object_id == self.note.object_id + assert note.deleted_from_id == self.notebook.object_id + assert note.notebook_id == self.trash.object_id + def test_undelete_note_that_is_not_deleted( self ): self.login()