witten
/
luminotes
Archived
1
0
Fork 0

Now, if you delete a notebook and the only remaining notebook is read-only,

then a new read-write notebook is created for you automatically. This fixes a
bug where you could delete a notebook and have only a read-only notebook
remaining, thereby having no way to add a new notebook.
This commit is contained in:
Dan Helfman 2008-01-24 22:02:02 +00:00
parent 43f4376821
commit ffd2d15175
5 changed files with 57 additions and 12 deletions

4
NEWS
View File

@ -1,3 +1,7 @@
1.1.3: January ??, 2008
* Now, if you delete a notebook and the only remaining notebook is read-only,
then a new read-write notebook is created for you automatically.
1.1.2: January 22, 2008
* You can no longer edit notes in the trash. You have to undelete them first.
* Fixed several race conditions between save_note() and other note-mutating

View File

@ -932,7 +932,8 @@ class Notebooks( object ):
)
def delete( self, notebook_id, user_id ):
"""
Delete the given notebook and redirect to a remaining notebook. If there is none, create one.
Delete the given notebook and redirect to a remaining read-write notebook. If there is none,
create one.
@type notebook_id: unicode
@param notebook_id: id of notebook to delete
@ -965,8 +966,10 @@ class Notebooks( object ):
self.__database.save( notebook, commit = False )
# redirect to a remaining undeleted notebook, or if there isn't one, create an empty notebook
remaining_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
# redirect to a remaining undeleted read-write notebook, or if there isn't one, create an empty notebook
remaining_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks(
parents_only = True, undeleted_only = True, read_write = True,
) )
if remaining_notebook is None:
remaining_notebook = self.__create_notebook( u"my notebook", user, commit = False )

View File

@ -37,27 +37,29 @@ class Test_controller( object ):
User.sql_remove_notebook = lambda self, notebook_id: \
lambda database: sql_remove_notebook( self, notebook_id, database )
def sql_load_notebooks( self, parents_only, undeleted_only, database ):
def sql_load_notebooks( self, parents_only, undeleted_only, read_write, database ):
notebooks = []
notebook_infos = database.user_notebook.get( self.object_id )
if not notebook_infos: return []
for notebook_info in notebook_infos:
( notebook_id, read_write, owner ) = notebook_info
( notebook_id, notebook_read_write, owner ) = notebook_info
notebook = database.objects.get( notebook_id )[ -1 ]
notebook.read_write = read_write
notebook.read_write = notebook_read_write
notebook.owner = owner
if parents_only and notebook.trash_id is None:
continue
if undeleted_only and notebook.deleted is True:
continue
if read_write and notebook_read_write is False:
continue
notebooks.append( notebook )
return notebooks
User.sql_load_notebooks = lambda self, parents_only = False, undeleted_only = False: \
lambda database: sql_load_notebooks( self, parents_only, undeleted_only, database )
User.sql_load_notebooks = lambda self, parents_only = False, undeleted_only = False, read_write = False: \
lambda database: sql_load_notebooks( self, parents_only, undeleted_only, read_write, database )
def sql_load_by_username( username, database ):
users = []

View File

@ -2417,7 +2417,7 @@ class Test_notebooks( Test_controller ):
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_delete_with_multiple_notebooks( self ):
def test_delete_with_remaining_notebook( self ):
# create a second notebook, which we should be redirected to after the first notebook is deleted
trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
self.database.save( trash, commit = False )
@ -2440,6 +2440,37 @@ class Test_notebooks( Test_controller ):
assert remaining_notebook_id
assert remaining_notebook_id == notebook.object_id
def test_delete_with_remaining_read_only_notebook( self ):
# create a second read-only notebook, which we should NOT be redirected to after the first
# notebook is deleted
trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
self.database.save( trash, commit = False )
notebook = Notebook.create( self.database.next_id( Notebook ), u"notebook", trash.object_id )
self.database.save( notebook, commit = False )
self.database.execute( self.user.sql_save_notebook( notebook.object_id, read_write = False, owner = False ) )
self.database.execute( self.user.sql_save_notebook( notebook.trash_id, read_write = False, owner = False ) )
self.database.commit()
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to a newly created notebook
remaining_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
notebook = self.database.last_saved_obj
assert isinstance( notebook, Notebook )
assert notebook.object_id == remaining_notebook_id
assert notebook.name == u"my notebook"
assert notebook.read_write == True
assert notebook.owner == True
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_contents_after_delete( self ):
self.login()

View File

@ -129,7 +129,7 @@ class User( Persistent ):
def sql_load_by_email_address( email_address ):
return "select * from luminotes_user_current where email_address = %s;" % quote( email_address )
def sql_load_notebooks( self, parents_only = False, undeleted_only = False ):
def sql_load_notebooks( self, parents_only = False, undeleted_only = False, read_write = False ):
"""
Return a SQL string to load a list of the notebooks to which this user has access.
"""
@ -143,10 +143,15 @@ class User( Persistent ):
else:
undeleted_only_clause = ""
if read_write:
read_write_clause = " and user_notebook.read_write = 't'"
else:
read_write_clause = ""
return \
"select notebook_current.*, user_notebook.read_write, user_notebook.owner from user_notebook, notebook_current " + \
"where user_notebook.user_id = %s%s%s and user_notebook.notebook_id = notebook_current.id order by revision;" % \
( quote( self.object_id ), parents_only_clause, undeleted_only_clause )
"where user_notebook.user_id = %s%s%s%s and user_notebook.notebook_id = notebook_current.id order by revision;" % \
( quote( self.object_id ), parents_only_clause, undeleted_only_clause, read_write_clause )
def sql_save_notebook( self, notebook_id, read_write = True, owner = True ):
"""