From f7626d985c298ed0a600d89a4fcf4cd0eca25927 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 16 Jun 2008 16:22:50 -0700 Subject: [PATCH] Fixed a bug that caused image files to get deleted if there were multiple images embedded within a single note. Prevented a link pulldown from auto-opening by hovering if another pulldown is already open. --- NEWS | 6 +++ controller/Files.py | 2 +- controller/test/Test_files.py | 90 +++++++++++++++++++++++++++++++++++ static/js/Wiki.js | 6 ++- 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 943d9e6..96fc938 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +1.4.2: June 16, 2008: + * Fixed a bug that caused image files to get deleted if there were multiple + images embedded within a single note. + * Prevented a link pulldown from auto-opening by hovering if another + pulldown is already open. + 1.4.1: June 16, 2008: * Implemented support for embedded images within wiki notes. * You can now open a link pulldown by simply hovering the mouse over a link diff --git a/controller/Files.py b/controller/Files.py index a7d9546..d2eb25f 100644 --- a/controller/Files.py +++ b/controller/Files.py @@ -206,7 +206,7 @@ cherrypy._cpcgifs.FieldStorage = FieldStorage class Files( object ): - FILE_LINK_PATTERN = re.compile( u'.+', re.IGNORECASE ) + FILE_LINK_PATTERN = re.compile( u'(', re.IGNORECASE ) """ Controller for dealing with uploaded files, corresponding to the "/files" URL. diff --git a/controller/test/Test_files.py b/controller/test/Test_files.py index 52d5aaf..95a69f9 100644 --- a/controller/test/Test_files.py +++ b/controller/test/Test_files.py @@ -1728,6 +1728,51 @@ class Test_files( Test_controller ): assert other_db_file is None assert not Upload_file.exists( other_file_id ) + def test_purge_unused_multiple_files( self ): + self.login() + + self.http_upload( + "/files/upload?file_id=%s" % self.file_id, + dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + ), + filename = self.filename, + file_data = self.file_data, + content_type = self.content_type, + session_id = self.session_id, + ) + + self.note.contents = 'file link' % self.file_id + self.database.save( self.note ) + + other_file_id = u"23" + self.http_upload( + "/files/upload?file_id=%s" % other_file_id, + dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + ), + filename = u"otherfile.png", + file_data = u"whee", + content_type = self.content_type, + session_id = self.session_id, + ) + + # one file is linked from the note's contents but the other is not. the file that is not linked + # should be deleted + cherrypy.root.files.purge_unused( self.note ) + + db_file = self.database.load( File, self.file_id ) + assert db_file + assert db_file.object_id == self.file_id + assert db_file.filename == self.filename + assert Upload_file.exists( self.file_id ) + + other_db_file = self.database.load( File, other_file_id ) + assert other_db_file is None + assert not Upload_file.exists( other_file_id ) + def test_purge_unused_multiple_files_with_quote_filename( self ): self.login() @@ -1773,6 +1818,51 @@ class Test_files( Test_controller ): assert other_db_file is None assert not Upload_file.exists( other_file_id ) + def test_purge_unused_multiple_image_files( self ): + self.login() + + self.http_upload( + "/files/upload?file_id=%s" % self.file_id, + dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + ), + filename = self.filename, + file_data = self.file_data, + content_type = self.content_type, + session_id = self.session_id, + ) + + self.note.contents = '' % self.file_id + self.database.save( self.note ) + + other_file_id = u"23" + self.http_upload( + "/files/upload?file_id=%s" % other_file_id, + dict( + notebook_id = self.notebook.object_id, + note_id = self.note.object_id, + ), + filename = u"otherfile.png", + file_data = u"whee", + content_type = self.content_type, + session_id = self.session_id, + ) + + # one images file is linked from the note's contents but the other is not. the file that is not + # linked should be deleted + cherrypy.root.files.purge_unused( self.note ) + + db_file = self.database.load( File, self.file_id ) + assert db_file + assert db_file.object_id == self.file_id + assert db_file.filename == self.filename + assert Upload_file.exists( self.file_id ) + + other_db_file = self.database.load( File, other_file_id ) + assert other_db_file is None + assert not Upload_file.exists( other_file_id ) + def login( self ): result = self.http_post( "/users/login", dict( username = self.username, diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 2174b3c..4c52e64 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -875,8 +875,10 @@ Wiki.prototype.editor_focused = function ( editor, synchronous ) { } Wiki.prototype.editor_mouse_hovered = function ( editor, target ) { - // if the mouse is hovering over a link, open a link pulldown - if ( target.nodeName == "A" ) + var pulldowns = getElementsByTagAndClassName( "div", "pulldown" ); + + // if the mouse is hovering over a link, and no pulldowns are open, open a link pulldown + if ( target.nodeName == "A" && pulldowns.length == 0 ) this.display_link_pulldown( editor, target, true ); // the mouse is hovering over something else, so clear all ephemeral pulldowns else