Пример #1
0
  def setUp( self ):
    Test_controller.setUp( self )

    self.notebook = Notebook.create( self.database.next_id( Notebook ), u"my notebook", trash_id = u"foo" )
    self.database.save( self.notebook )

    self.anon_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes" )
    self.database.save( self.anon_notebook )
    self.anon_note = Note.create(
      self.database.next_id( Note ), u"<h3>my note</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.anon_note )

    self.login_note = Note.create(
      self.database.next_id( Note ), u"<h3>login</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.login_note )

    self.blog_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes blog" )
    self.database.save( self.blog_notebook )
    self.blog_note = Note.create(
      self.database.next_id( Note ), u"<h3>my blog entry</h3>",
      notebook_id = self.blog_notebook.object_id,
    )
    self.database.save( self.blog_note )

    self.guide_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes user guide" )
    self.database.save( self.guide_notebook )
    self.guide_note = Note.create(
      self.database.next_id( Note ), u"<h3>it's all self-explanatory</h3>",
      notebook_id = self.guide_notebook.object_id,
    )
    self.database.save( self.guide_note )

    self.privacy_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes privacy policy" )
    self.database.save( self.privacy_notebook )
    self.privacy_note = Note.create(
      self.database.next_id( Note ), u"<h3>yay privacy</h3>",
      notebook_id = self.privacy_notebook.object_id,
    )
    self.database.save( self.privacy_note )

    self.username = u"mulder"
    self.password = u"trustno1"
    self.email_address = u"*****@*****.**"
    self.user = None
    self.session_id = None

    self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
    self.database.save( self.user )
    self.database.execute( self.user.sql_save_notebook( self.notebook.object_id ) )

    self.anonymous = User.create( self.database.next_id( User ), u"anonymous" )
    self.database.save( self.anonymous )
    self.database.execute( self.anonymous.sql_save_notebook( self.anon_notebook.object_id, read_write = False, owner = False, rank = 0 ) )
    self.database.execute( self.anonymous.sql_save_notebook( self.blog_notebook.object_id, read_write = False, owner = False, rank = 1 ) )
    self.database.execute( self.anonymous.sql_save_notebook( self.guide_notebook.object_id, read_write = False, owner = False, rank = 2 ) )
    self.database.execute( self.anonymous.sql_save_notebook( self.privacy_notebook.object_id, read_write = False, owner = False, rank = 3 ) )
Пример #2
0
    def __make_extra_threads(self):
        self.general_thread2 = Notebook.create(self.database.next_id(Notebook),
                                               u"How does this thing work?")
        self.database.save(self.general_thread2)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.general_thread2.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(
                self.general_thread2.object_id,
                self.forum_tag.object_id,
                value=u"general"), )

        self.general_thread3 = Notebook.create(
            self.database.next_id(Notebook),
            u"I have a problem with my pantalones.")
        self.database.save(self.general_thread3)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.general_thread3.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(
                self.general_thread3.object_id,
                self.forum_tag.object_id,
                value=u"general"), )
Пример #3
0
  def setUp( self ):
    self.database = Database(
      Connection_wrapper( sqlite.connect( ":memory:", detect_types = sqlite.PARSE_DECLTYPES, check_same_thread = False ) ),
      cache = Stub_cache(),
    )
    self.database.execute_script( file( "model/schema.sqlite" ).read(), commit = True )

    self.username = u"mulder"
    self.password = u"trustno1"
    self.email_address = u"*****@*****.**"
    self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
    self.database.save( self.user, commit = False )

    self.trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
    self.database.save( self.trash, commit = False )
    self.notebook = Notebook.create( self.database.next_id( Notebook ), u"notebook", self.trash.object_id, user_id = self.user.object_id )
    self.database.save( self.notebook, commit = False )

    note_id = self.database.next_id( Note )
    self.note1 = Note.create( note_id, u"<h3>my title</h3>blah", notebook_id = self.notebook.object_id, startup = True, user_id = self.user.object_id )
    self.database.save( self.note1, commit = False )

    note_id = self.database.next_id( Note )
    self.note2 = Note.create( note_id, u"<h3>other title</h3>whee", notebook_id = self.notebook.object_id, user_id = self.user.object_id )
    self.database.save( self.note2, commit = False )
Пример #4
0
  def setUp( self ):
    self.object_id = "17"
    self.trash_id = "18"
    self.name = u"my notebook"
    self.trash_name = u"trash"
    self.user_id = u"me"
    self.delta = timedelta( seconds = 1 )
    self.read_write = Notebook.READ_WRITE
    self.owner = False
    self.rank = 17.5

    self.trash = Notebook.create( self.trash_id, self.trash_name, read_write = Notebook.READ_ONLY, deleted = False, user_id = self.user_id )
    self.notebook = Notebook.create( self.object_id, self.name, trash_id = self.trash.object_id, deleted = False, user_id = self.user_id, read_write = self.read_write, owner = self.owner, rank = self.rank )
    self.note = Note.create( "19", u"<h3>title</h3>blah" )
Пример #5
0
    def create_main_notebook(self):
        # create the main notebook
        main_notebook_id = self.database.next_id(Notebook)
        self.main_notebook = Notebook.create(main_notebook_id,
                                             u"Luminotes",
                                             rank=0)
        self.database.save(self.main_notebook, commit=False)

        # no need to create default notes for the desktop version
        if self.desktop is True:
            return

        # create an id for each note
        note_ids = {}
        for (filename, startup) in self.NOTE_FILES:
            note_ids[filename] = self.database.next_id(Note)

        rank = 0
        for (filename, startup) in self.NOTE_FILES:
            full_filename = os.path.join(self.HTML_PATH, filename)
            contents = fix_note_contents(
                file(full_filename).read(), main_notebook_id, note_ids,
                self.settings)

            if startup:
                rank += 1

            note = Note.create(note_ids[filename],
                               contents,
                               notebook_id=self.main_notebook.object_id,
                               startup=startup,
                               rank=startup and rank or None)
            self.database.save(note, commit=False)
Пример #6
0
    def default(self,
                thread_id,
                start=0,
                count=10,
                note_id=None,
                posts=None,
                user_id=None):
        """
    Provide the information necessary to display a forum thread.

    @type thread_id: unicode
    @param thread_id: id or "friendly id" of thread notebook to display
    @type start: unicode or NoneType
    @param start: index of recent note to start with (defaults to 0, the most recent note)
    @type count: int or NoneType
    @param count: number of recent notes to display (defaults to 10 notes)
    @type note_id: unicode or NoneType
    @param note_id: id of single note to load (optional)
    @type posts: integer or NoneType
    @param posts: ignored. used for link-visitedness purposes on the client side
    @type user_id: unicode or NoneType
    @param user_id: id of the current user
    @rtype: unicode
    @return: rendered HTML page
    @raise Validation_error: one of the arguments is invalid
    """
        # first try loading the thread by id, and then if not found, try loading by "friendly id"
        try:
            Valid_id()(thread_id)
            if not self.__database.load(Notebook, thread_id):
                raise ValueError()
        except ValueError:
            try:
                Valid_friendly_id()(thread_id)
            except ValueError:
                raise cherrypy.NotFound

            try:
                thread = self.__database.select_one(
                    Notebook, Notebook.sql_load_by_friendly_id(thread_id))
            except:
                raise cherrypy.NotFound
            if not thread:
                raise cherrypy.NotFound

            thread_id = thread.object_id

        result = self.__users.current(user_id)
        result.update(
            self.__notebooks.old_notes(thread_id, start, count, user_id))

        # if a single note was requested, just return that one note
        if note_id:
            note = self.__database.load(Note, note_id)
            if note:
                result["notes"] = [note]
            else:
                result["notes"] = []

        return result
Пример #7
0
  def create_main_notebook( self ):
    # create the main notebook
    main_notebook_id = self.database.next_id( Notebook )
    self.main_notebook = Notebook.create( main_notebook_id, u"Luminotes", rank = 0 )
    self.database.save( self.main_notebook, commit = False )

    # no need to create default notes for the desktop version
    if self.desktop is True:
      return

    # create an id for each note
    note_ids = {}
    for ( filename, startup ) in self.NOTE_FILES:
      note_ids[ filename ] = self.database.next_id( Note )

    rank = 0
    for ( filename, startup ) in self.NOTE_FILES:
      full_filename = os.path.join( self.HTML_PATH, filename )
      contents = fix_note_contents( file( full_filename ).read(), main_notebook_id, note_ids, self.settings )

      if startup:
        rank += 1

      note = Note.create( note_ids[ filename ], contents, notebook_id = self.main_notebook.object_id, startup = startup, rank = startup and rank or None )
      self.database.save( note, commit = False )
Пример #8
0
  def create_thread( self, user_id ):
    """
    Create a new forum thread with a blank post, and give the thread a default name. Then redirect
    to that new thread.

    @type user_id: unicode or NoneType
    @param user_id: id of current logged-in user (if any)
    @rtype dict
    @return { 'redirect': new_notebook_url }
    @raise Access_error: the current user doesn't have access to create a post
    @raise Validation_error: one of the arguments is invalid
    """
    if user_id is None:
      raise Access_error()

    user = self.__database.load( User, user_id )
    if user is None or not user.username or user.username == "anonymous":
      raise Access_error()

    anonymous = self.__database.select_one( User, User.sql_load_by_username( u"anonymous" ), use_cache = True )
    if anonymous is None:
      raise Access_error()

    # for now, crappy hard-coding to prevent just anyone from creating a blog thread
    if self.__name == u"blog" and user.username != u"witten":
      raise Access_error()

    # create the new notebook thread
    thread_id = self.__database.next_id( Notebook, commit = False )
    thread = Notebook.create( thread_id, self.DEFAULT_THREAD_NAME, user_id = user.object_id )
    self.__database.save( thread, commit = False )

    # associate the forum tag with the new notebook thread
    tag = self.__database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )
    self.__database.execute(
      anonymous.sql_save_notebook_tag( thread_id, tag.object_id, value = self.__name ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.__database.execute(
      anonymous.sql_save_notebook( thread_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )

    # create a blank post in which the user can  start off the thread
    note_id = self.__database.next_id( Notebook, commit = False )
    note = Note.create( note_id, u"<h3>", notebook_id = thread_id, startup = True, rank = 0, user_id = user_id )
    self.__database.save( note, commit = False )

    self.__database.commit()

    if self.__name == "blog":
      return dict(
        redirect = u"/blog/%s" % thread_id,
      )

    return dict(
      redirect = u"/forums/%s/%s" % ( self.__name, thread_id ),
    )
Пример #9
0
  def __make_extra_threads( self ):
    self.general_thread2 = Notebook.create( self.database.next_id( Notebook ), u"How does this thing work?" )
    self.database.save( self.general_thread2 )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.general_thread2.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.general_thread2.object_id, self.forum_tag.object_id, value = u"general" ),
    )

    self.general_thread3 = Notebook.create( self.database.next_id( Notebook ), u"I have a problem with my pantalones." )
    self.database.save( self.general_thread3 )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.general_thread3.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.general_thread3.object_id, self.forum_tag.object_id, value = u"general" ),
    )
Пример #10
0
  def make_thread( self ):
    title = u"Welcome to the Luminotes %s forum!" % self.forum_name

    # create a notebook thread to go in the forum
    notebook_id = self.database.next_id( Notebook, commit = False )
    thread_notebook = Notebook.create(
      notebook_id,
      title,
    )
    self.database.save( thread_notebook, commit = False )

    anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )

    # add a single welcome note to the new thread
    note_id = self.database.next_id( Note, commit = False )
    note = Note.create(
      note_id,
      u"""
      <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion
      forum, so please keep that in mind when posting. And have fun.
      """ % ( title, self.forum_name ),
      notebook_id,
      startup = True,
      rank = 0,
      user_id = anonymous.object_id,
      creation = datetime.now(),
    )
    self.database.save( note, commit = False )

    # load the forum tag, or create one if it doesn't exist
    tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )
    if not tag:
      tag_id = self.database.next_id( Tag, commit = False )
      tag = Tag.create(
        tag_id,
        notebook_id = None, # this tag is not in the namespace of a single notebook
        user_id = anonymous.object_id,
        name = u"forum",
        description = u"discussion forum threads"
      )
      self.database.save( tag, commit = False )

    # associate the forum tag with the previously created notebook thread, and set that
    # association's value to forum_name
    self.database.execute(
      anonymous.sql_save_notebook_tag( notebook_id, tag.object_id, value = self.forum_name ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.database.execute(
      anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )
Пример #11
0
    def setUp(self):
        self.database = Database(
            Connection_wrapper(
                sqlite.connect(":memory:",
                               detect_types=sqlite.PARSE_DECLTYPES,
                               check_same_thread=False)),
            cache=Stub_cache(),
        )
        self.database.execute_script(file("model/schema.sqlite").read(),
                                     commit=True)

        self.username = u"mulder"
        self.password = u"trustno1"
        self.email_address = u"*****@*****.**"
        self.user = User.create(self.database.next_id(User), self.username,
                                self.password, self.email_address)
        self.database.save(self.user, commit=False)

        self.trash = Notebook.create(self.database.next_id(Notebook), u"trash")
        self.database.save(self.trash, commit=False)
        self.notebook = Notebook.create(self.database.next_id(Notebook),
                                        u"notebook",
                                        self.trash.object_id,
                                        user_id=self.user.object_id)
        self.database.save(self.notebook, commit=False)

        note_id = self.database.next_id(Note)
        self.note1 = Note.create(note_id,
                                 u"<h3>my title</h3>blah",
                                 notebook_id=self.notebook.object_id,
                                 startup=True,
                                 user_id=self.user.object_id)
        self.database.save(self.note1, commit=False)

        note_id = self.database.next_id(Note)
        self.note2 = Note.create(note_id,
                                 u"<h3>other title</h3>whee",
                                 notebook_id=self.notebook.object_id,
                                 user_id=self.user.object_id)
        self.database.save(self.note2, commit=False)
Пример #12
0
  def default( self, thread_id, start = 0, count = 10, note_id = None, posts = None, user_id = None ):
    """
    Provide the information necessary to display a forum thread.

    @type thread_id: unicode
    @param thread_id: id or "friendly id" of thread notebook to display
    @type start: unicode or NoneType
    @param start: index of recent note to start with (defaults to 0, the most recent note)
    @type count: int or NoneType
    @param count: number of recent notes to display (defaults to 10 notes)
    @type note_id: unicode or NoneType
    @param note_id: id of single note to load (optional)
    @type posts: integer or NoneType
    @param posts: ignored. used for link-visitedness purposes on the client side
    @type user_id: unicode or NoneType
    @param user_id: id of the current user
    @rtype: unicode
    @return: rendered HTML page
    @raise Validation_error: one of the arguments is invalid
    """
    # first try loading the thread by id, and then if not found, try loading by "friendly id"
    try:
      Valid_id()( thread_id )
      if not self.__database.load( Notebook, thread_id ):
        raise ValueError()
    except ValueError:
      try:
        Valid_friendly_id()( thread_id )
      except ValueError:
        raise cherrypy.NotFound

      try:
        thread = self.__database.select_one( Notebook, Notebook.sql_load_by_friendly_id( thread_id ) )
      except:
        raise cherrypy.NotFound
      if not thread:
        raise cherrypy.NotFound

      thread_id = thread.object_id

    result = self.__users.current( user_id )
    result.update( self.__notebooks.old_notes( thread_id, start, count, user_id ) )

    # if a single note was requested, just return that one note
    if note_id:
      note = self.__database.load( Note, note_id )
      if note:
        result[ "notes" ] = [ note ]
      else:
        result[ "notes" ] = []

    return result
Пример #13
0
  def test_create_read_write_true_and_own_notes_only_true( self ):
    notebook = Notebook.create( self.object_id, self.name, trash_id = None, deleted = False, user_id = self.user_id, read_write = True, owner = self.owner, rank = self.rank, own_notes_only = True )

    assert notebook.object_id == self.object_id
    assert datetime.now( tz = utc ) - notebook.revision < self.delta
    assert notebook.name == self.name
    assert notebook.trash_id == None
    assert notebook.deleted == False
    assert notebook.user_id == self.user_id
    assert notebook.read_write == Notebook.READ_WRITE_FOR_OWN_NOTES
    assert notebook.owner == self.owner
    assert notebook.rank == self.rank
    assert notebook.tags == []
    assert notebook.note_count == None
Пример #14
0
  def test_create_read_write_none( self ):
    notebook = Notebook.create( self.object_id, self.name, trash_id = None, deleted = False, user_id = self.user_id, read_write = None, owner = self.owner, rank = self.rank )

    assert notebook.object_id == self.object_id
    assert datetime.now( tz = utc ) - notebook.revision < self.delta
    assert notebook.name == self.name
    assert notebook.trash_id == None
    assert notebook.deleted == False
    assert notebook.user_id == self.user_id
    assert notebook.read_write == Notebook.READ_WRITE
    assert notebook.owner == self.owner
    assert notebook.rank == self.rank
    assert notebook.tags == []
    assert notebook.note_count == None
Пример #15
0
    def convert_post(self, note):
        # create a notebook thread to go in the forum
        notebook_id = self.database.next_id(Notebook, commit=False)
        thread_notebook = Notebook.create(
            notebook_id,
            note.title,
        )
        self.database.save(thread_notebook, commit=False)

        anonymous = self.database.select_one(
            User, User.sql_load_by_username(u"anonymous"))

        # move the given note into the newly created notebook thread
        note.notebook_id = notebook_id
        note.startup = True
        note.rank = 0
        self.database.save(note, commit=False)

        # load the forum tag
        forum_tag = self.database.select_one(
            Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id))

        # associate the forum tag with the previously created notebook thread, and set that
        # association's value to the forum name
        self.database.execute(
            anonymous.sql_save_notebook_tag(notebook_id,
                                            forum_tag.object_id,
                                            value=u"blog"),
            commit=False,
        )

        # give the anonymous user access to the new notebook thread
        self.database.execute(
            anonymous.sql_save_notebook(notebook_id,
                                        read_write=True,
                                        owner=False,
                                        own_notes_only=True),
            commit=False,
        )

        blog_user = self.database.select_one(
            User, User.sql_load_by_username(self.blog_username))

        self.database.execute(
            blog_user.sql_save_notebook(notebook_id,
                                        read_write=True,
                                        owner=True),
            commit=False,
        )
Пример #16
0
  def convert_post( self, note ):
    # create a notebook thread to go in the forum
    notebook_id = self.database.next_id( Notebook, commit = False )
    thread_notebook = Notebook.create(
      notebook_id,
      note.title,
    )
    self.database.save( thread_notebook, commit = False )

    anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )

    # move the given note into the newly created notebook thread
    note.notebook_id = notebook_id
    note.startup = True
    note.rank = 0
    self.database.save( note, commit = False )

    # load the forum tag
    forum_tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )

    # associate the forum tag with the previously created notebook thread, and set that
    # association's value to the forum name
    self.database.execute(
      anonymous.sql_save_notebook_tag( notebook_id, forum_tag.object_id, value = u"blog" ),
      commit = False,
    )

    # give the anonymous user access to the new notebook thread
    self.database.execute(
      anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ),
      commit = False,
    )

    blog_user = self.database.select_one( User, User.sql_load_by_username( self.blog_username ) )

    self.database.execute(
      blog_user.sql_save_notebook( notebook_id, read_write = True, owner = True ),
      commit = False,
    )
Пример #17
0
    def make_thread(self):
        title = u"Welcome to the Luminotes %s forum!" % self.forum_name

        # create a notebook thread to go in the forum
        notebook_id = self.database.next_id(Notebook, commit=False)
        thread_notebook = Notebook.create(
            notebook_id,
            title,
        )
        self.database.save(thread_notebook, commit=False)

        anonymous = self.database.select_one(
            User, User.sql_load_by_username(u"anonymous"))

        # add a single welcome note to the new thread
        note_id = self.database.next_id(Note, commit=False)
        note = Note.create(
            note_id,
            u"""
      <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion
      forum, so please keep that in mind when posting. And have fun.
      """ % (title, self.forum_name),
            notebook_id,
            startup=True,
            rank=0,
            user_id=anonymous.object_id,
            creation=datetime.now(),
        )
        self.database.save(note, commit=False)

        # load the forum tag, or create one if it doesn't exist
        tag = self.database.select_one(
            Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id))
        if not tag:
            tag_id = self.database.next_id(Tag, commit=False)
            tag = Tag.create(
                tag_id,
                notebook_id=
                None,  # this tag is not in the namespace of a single notebook
                user_id=anonymous.object_id,
                name=u"forum",
                description=u"discussion forum threads")
            self.database.save(tag, commit=False)

        # associate the forum tag with the previously created notebook thread, and set that
        # association's value to forum_name
        self.database.execute(
            anonymous.sql_save_notebook_tag(notebook_id,
                                            tag.object_id,
                                            value=self.forum_name),
            commit=False,
        )

        # give the anonymous user access to the new notebook thread
        self.database.execute(
            anonymous.sql_save_notebook(notebook_id,
                                        read_write=True,
                                        owner=False,
                                        own_notes_only=True),
            commit=False,
        )
Пример #18
0
  def setUp( self ):
    Test_controller.setUp( self )

    self.notebook = Notebook.create( self.database.next_id( Notebook ), u"my notebook", trash_id = u"foo" )
    self.database.save( self.notebook )

    self.anon_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes", trash_id = u"bar" )
    self.database.save( self.anon_notebook )
    self.anon_note = Note.create(
      self.database.next_id( Note ), u"<h3>my note</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.anon_note )

    self.login_note = Note.create(
      self.database.next_id( Note ), u"<h3>login</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.login_note )

    self.username = u"mulder"
    self.password = u"trustno1"
    self.email_address = u"*****@*****.**"
    self.user = None
    self.session_id = None

    self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
    self.database.save( self.user )
    self.database.execute( self.user.sql_save_notebook( self.notebook.object_id ) )

    self.anonymous = User.create( self.database.next_id( User ), u"anonymous" )
    self.database.save( self.anonymous )
    self.database.execute( self.anonymous.sql_save_notebook( self.anon_notebook.object_id ) )

    self.blog_user = User.create( self.database.next_id( User ), u"witten", self.password, self.email_address )
    self.database.save( self.blog_user )

    tag_id = self.database.next_id( Tag )
    self.forum_tag = Tag.create(
      tag_id,
      notebook_id = None, # this tag is not in the namespace of a single notebook
      user_id = self.anonymous.object_id,
      name = u"forum",
      description = u"a discussion forum"
    )
    self.database.save( self.forum_tag )

    self.general_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the general forum!" )
    self.database.save( self.general_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.general_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.general_thread.object_id, self.forum_tag.object_id, value = u"general" ),
    )

    self.support_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the support forum!" )
    self.database.save( self.support_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.support_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.support_thread.object_id, self.forum_tag.object_id, value = u"support" ),
    )

    self.blog_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the blog!" )
    self.database.save( self.blog_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.blog_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.blog_user.sql_save_notebook( self.blog_thread.object_id, read_write = Notebook.READ_WRITE ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.blog_thread.object_id, self.forum_tag.object_id, value = u"forum" ),
    )
Пример #19
0
    def setUp(self):
        Test_controller.setUp(self)

        self.notebook = Notebook.create(self.database.next_id(Notebook),
                                        u"my notebook",
                                        trash_id=u"foo")
        self.database.save(self.notebook)

        self.anon_notebook = Notebook.create(self.database.next_id(Notebook),
                                             u"Luminotes")
        self.database.save(self.anon_notebook)
        self.anon_note = Note.create(
            self.database.next_id(Note),
            u"<h3>my note</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.anon_note)

        self.login_note = Note.create(
            self.database.next_id(Note),
            u"<h3>login</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.login_note)

        self.blog_notebook = Notebook.create(self.database.next_id(Notebook),
                                             u"Luminotes blog")
        self.database.save(self.blog_notebook)
        self.blog_note = Note.create(
            self.database.next_id(Note),
            u"<h3>my blog entry</h3>",
            notebook_id=self.blog_notebook.object_id,
        )
        self.database.save(self.blog_note)

        self.guide_notebook = Notebook.create(self.database.next_id(Notebook),
                                              u"Luminotes user guide")
        self.database.save(self.guide_notebook)
        self.guide_note = Note.create(
            self.database.next_id(Note),
            u"<h3>it's all self-explanatory</h3>",
            notebook_id=self.guide_notebook.object_id,
        )
        self.database.save(self.guide_note)

        self.privacy_notebook = Notebook.create(
            self.database.next_id(Notebook), u"Luminotes privacy policy")
        self.database.save(self.privacy_notebook)
        self.privacy_note = Note.create(
            self.database.next_id(Note),
            u"<h3>yay privacy</h3>",
            notebook_id=self.privacy_notebook.object_id,
        )
        self.database.save(self.privacy_note)

        self.username = u"mulder"
        self.password = u"trustno1"
        self.email_address = u"*****@*****.**"
        self.user = None
        self.session_id = None

        self.user = User.create(self.database.next_id(User), self.username,
                                self.password, self.email_address)
        self.database.save(self.user)
        self.database.execute(
            self.user.sql_save_notebook(self.notebook.object_id))

        self.anonymous = User.create(self.database.next_id(User), u"anonymous")
        self.database.save(self.anonymous)
        self.database.execute(
            self.anonymous.sql_save_notebook(self.anon_notebook.object_id,
                                             read_write=False,
                                             owner=False,
                                             rank=0))
        self.database.execute(
            self.anonymous.sql_save_notebook(self.blog_notebook.object_id,
                                             read_write=False,
                                             owner=False,
                                             rank=1))
        self.database.execute(
            self.anonymous.sql_save_notebook(self.guide_notebook.object_id,
                                             read_write=False,
                                             owner=False,
                                             rank=2))
        self.database.execute(
            self.anonymous.sql_save_notebook(self.privacy_notebook.object_id,
                                             read_write=False,
                                             owner=False,
                                             rank=3))
Пример #20
0
    def create_thread(self, user_id):
        """
    Create a new forum thread with a blank post, and give the thread a default name. Then redirect
    to that new thread.

    @type user_id: unicode or NoneType
    @param user_id: id of current logged-in user (if any)
    @rtype dict
    @return { 'redirect': new_notebook_url }
    @raise Access_error: the current user doesn't have access to create a post
    @raise Validation_error: one of the arguments is invalid
    """
        if user_id is None:
            raise Access_error()

        user = self.__database.load(User, user_id)
        if user is None or not user.username or user.username == "anonymous":
            raise Access_error()

        anonymous = self.__database.select_one(
            User, User.sql_load_by_username(u"anonymous"), use_cache=True)
        if anonymous is None:
            raise Access_error()

        # for now, crappy hard-coding to prevent just anyone from creating a blog thread
        if self.__name == u"blog" and user.username != u"witten":
            raise Access_error()

        # create the new notebook thread
        thread_id = self.__database.next_id(Notebook, commit=False)
        thread = Notebook.create(thread_id,
                                 self.DEFAULT_THREAD_NAME,
                                 user_id=user.object_id)
        self.__database.save(thread, commit=False)

        # associate the forum tag with the new notebook thread
        tag = self.__database.select_one(
            Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id))
        self.__database.execute(
            anonymous.sql_save_notebook_tag(thread_id,
                                            tag.object_id,
                                            value=self.__name),
            commit=False,
        )

        # give the anonymous user access to the new notebook thread
        self.__database.execute(
            anonymous.sql_save_notebook(thread_id,
                                        read_write=True,
                                        owner=False,
                                        own_notes_only=True),
            commit=False,
        )

        # create a blank post in which the user can  start off the thread
        note_id = self.__database.next_id(Notebook, commit=False)
        note = Note.create(note_id,
                           u"<h3>",
                           notebook_id=thread_id,
                           startup=True,
                           rank=0,
                           user_id=user_id)
        self.__database.save(note, commit=False)

        self.__database.commit()

        if self.__name == "blog":
            return dict(redirect=u"/blog/%s" % thread_id, )

        return dict(redirect=u"/forums/%s/%s" % (self.__name, thread_id), )
Пример #21
0
    def setUp(self):
        Test_controller.setUp(self)

        self.notebook = Notebook.create(self.database.next_id(Notebook),
                                        u"my notebook",
                                        trash_id=u"foo")
        self.database.save(self.notebook)

        self.anon_notebook = Notebook.create(self.database.next_id(Notebook),
                                             u"Luminotes",
                                             trash_id=u"bar")
        self.database.save(self.anon_notebook)
        self.anon_note = Note.create(
            self.database.next_id(Note),
            u"<h3>my note</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.anon_note)

        self.login_note = Note.create(
            self.database.next_id(Note),
            u"<h3>login</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.login_note)

        self.username = u"mulder"
        self.password = u"trustno1"
        self.email_address = u"*****@*****.**"
        self.user = None
        self.session_id = None

        self.user = User.create(self.database.next_id(User), self.username,
                                self.password, self.email_address)
        self.database.save(self.user)
        self.database.execute(
            self.user.sql_save_notebook(self.notebook.object_id))

        self.anonymous = User.create(self.database.next_id(User), u"anonymous")
        self.database.save(self.anonymous)
        self.database.execute(
            self.anonymous.sql_save_notebook(self.anon_notebook.object_id))

        self.blog_user = User.create(self.database.next_id(User), u"witten",
                                     self.password, self.email_address)
        self.database.save(self.blog_user)

        tag_id = self.database.next_id(Tag)
        self.forum_tag = Tag.create(
            tag_id,
            notebook_id=
            None,  # this tag is not in the namespace of a single notebook
            user_id=self.anonymous.object_id,
            name=u"forum",
            description=u"a discussion forum")
        self.database.save(self.forum_tag)

        self.general_thread = Notebook.create(
            self.database.next_id(Notebook), u"Welcome to the general forum!")
        self.database.save(self.general_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.general_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.general_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"general"), )

        self.support_thread = Notebook.create(
            self.database.next_id(Notebook), u"Welcome to the support forum!")
        self.database.save(self.support_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.support_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.support_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"support"), )

        self.blog_thread = Notebook.create(self.database.next_id(Notebook),
                                           u"Welcome to the blog!")
        self.database.save(self.blog_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.blog_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.blog_user.sql_save_notebook(self.blog_thread.object_id,
                                             read_write=Notebook.READ_WRITE), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.blog_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"forum"), )