'Mark given folder deleted/undeleted based on the flag.
:param  folder:        the model object
:type   folder:        LibraryFolder
:param  undelete:      flag whether to delete (when False) or undelete
:type   undelete:      Bool
:returns:   the folder
:rtype:     LibraryFolder
:raises: ItemAccessibilityException'

def delete(self, trans, folder, undelete=False):

    if (not trans.user_is_admin()):
        folder = self.check_manageable(trans, folder)
    if undelete:
        folder.deleted = False
    else:
        folder.deleted = True
    trans.sa_session.add(folder)
    trans.sa_session.flush()
    return folder
