Exemple #1
0
 def test_renderedScrollerInitializedCorrectly(self):
     """
     L{hyperbola_view.BlogBlurbViewer.render_view} should return a
     L{hyperbola.hyperbola_view.ShareScrollTable} that is aware of
     all of the posts that have been made to the blog.
     """
     scroller = self._getRenderViewScroller()
     rows = scroller.rowsAfterValue(None, 10)
     self.assertEqual(len(rows), 1)
     theRow = rows[0]
     self.assertEqual(
         theRow['dateCreated'],
         self.blogPostItem.dateCreated.asPOSIXTimestamp())
     self.assertEqual(
         theRow['__id__'],
         IWebTranslator(self.userStore).toWebID(self.blogPostItem))
     blogPostFragment = theRow['blurbView']
     # the scrolltable fragment is not customized, so we want to
     # ensure that the proxy passed to the IColumns is the facet
     # shared to Everyone
     self.assertEqual(
         list(blogPostFragment.original.sharedInterfaces),
         list(self.blogPostSharedToEveryone.sharedInterfaces))
     self.assertIdentical(
         sharing.itemFromProxy(blogPostFragment.original),
         self.blogPostItem)
 def child_post(self, ctx):
     """
     If the user is authorized, return a L{BlurbPostingResource}
     """
     store = sharing.itemFromProxy(self.original).store
     if ihyperbola.ICommentable.providedBy(self.original):
         return BlurbPostingResource(
             store, self.original, self.customizedFor)
     return LoginPage.fromRequest(store.parent, inevow.IRequest(ctx))
    def _getAllTags(self):
        """
        Get all the tags in the same store as the underlying item of our
        parent blurb

        @rtype: C{list} of C{unicode}
        """
        store = sharing.itemFromProxy(self.parent.original).store
        return list(store.findOrCreate(Catalog).tagNames())
 def getRole(self):
     """
     Retrieve the role currently viewing this blurb viewer.
     """
     store = sharing.itemFromProxy(self.original).store
     if self.customizedFor is None:
         # If this hasn't been customized, it's public.
         return sharing.getEveryoneRole(store)
     else:
         # Otherwise, get the primary role of the current observer.
         return sharing.getPrimaryRole(store, self.customizedFor)
    def _getAllTags(self):
        """
        Get all the tags which have been applied to blurbs in the same store
        as the underlying item of our blurb.

        @rtype: C{list} of C{unicode}
        """
        store = sharing.itemFromProxy(self.original).store
        # query instead of using Catalog so that tags only applied to
        # PastBlurb items don't get included
        return list(store.query(
            Tag, Tag.object == Blurb.storeID).getColumn('name').distinct())
    def child_detail(self, ctx):
        """
        Return a L{BlogPostBlurbViewerDetail} for this blog post
        """
        f = blurbViewDetailDispatcher(self.original)
        f.customizeFor(self.customizedFor)
        _docFactorify(f)

        return publicresource.PublicAthenaLivePage(
            sharing.itemFromProxy(self.original).store.parent,
            f,
            forUser=self.customizedFor)
 def _absoluteURL(self):
     """
     Return the absolute URL the websharing system makes this blurb
     available at.
     """
     subStore = sharing.itemFromProxy(self.original).store
     site = ixmantissa.ISiteURLGenerator(subStore.parent)
     siteURL = site.encryptedRoot()
     blurbURL = websharing.linkTo(self.original)
     blurbURL.netloc = siteURL.netloc
     blurbURL.scheme = siteURL.scheme
     return str(blurbURL)
 def test_editPermsAuthorOnly(self):
     """
     Test that creating a blurb with the default permissions and then
     editing the perms to only allow the author to view the post results in
     a share that can't be accessed by anybody else
     """
     shareID = self.blog.post(u'', u'', self.me)
     share = getShare(self.userStore, self.me, shareID)
     shareID = itemFromProxy(share).editPermissions(
         {self.me: [ihyperbola.IViewable]})
     share = getShare(self.userStore, self.me, shareID)
     self.assertRaises(NoSuchShare,
                       lambda: getShare(self.userStore, self.you, shareID))
    def linkToItem(self, proxy):
        """
        This table's query results are proxies rather than items, so unwrap
        them to generate unique IDs.

        @param proxy: a shared proxy.
        @type proxy: L{xmantissa.sharing.SharedProxy}

        @return: the web ID of the item that C{proxy} is wrapping.
        @rtype: C{str}
        """
        return super(ShareScrollingElement, self).linkToItem(
            sharing.itemFromProxy(proxy))
Exemple #10
0
    def setUp(self):
        """
        Set up an environment suitable for testing the share-handling
        functionality of L{hyperbola_view.ShareScrollingElement}.
        """
        self._setUpStore()

        blogShare = self._shareAndGetProxy(self._makeBlurb(FLAVOR.BLOG))
        EVERYBODY = sharing.getEveryoneRole(self.userStore)
        sharing.itemFromProxy(blogShare).permitChildren(
            EVERYBODY, FLAVOR.BLOG_POST, ihyperbola.IViewable)

        # For sanity's sake, let's not have the role of the view and the role
        # implicitly chosen by not calling 'customizeFor' disagree.  (This
        # shouldn't be possible anyway, and in the future getRole should just
        # be looking at its proxy.)
        self.publicBlogShare = sharing.getShare(
            self.userStore, EVERYBODY, blogShare.shareID)
        selfRole = sharing.getSelfRole(self.userStore)
        blogPostShareID = blogShare.post(u'', u'', selfRole)
        self.blogPostSharedToEveryone = sharing.getShare(
            self.userStore, EVERYBODY, blogPostShareID)
        self.blogPostItem = sharing.itemFromProxy(self.blogPostSharedToEveryone)
 def test_editPermsAuthorOnly(self):
     """
     Test that creating a blurb with the default permissions and then
     editing the perms to only allow the author to view the post results in
     a share that can't be accessed by anybody else
     """
     shareID = self.blog.post(u'', u'', self.me)
     share = getShare(self.userStore, self.me, shareID)
     shareID = itemFromProxy(share).editPermissions(
         {self.me: [ihyperbola.IViewable]})
     share = getShare(self.userStore, self.me, shareID)
     self.assertRaises(
         NoSuchShare,
         lambda: getShare(self.userStore, self.you, shareID))
Exemple #12
0
def linkTo(sharedProxyOrItem):
    """
    Generate the path part of a URL to link to a share item or its proxy.

    @param sharedProxy: a L{sharing.SharedProxy} or L{sharing.Share}

    @return: a URL object, which when converted to a string will look
        something like '/users/user@host/shareID'.

    @rtype: L{nevow.url.URL}

    @raise: L{RuntimeError} if the store that the C{sharedProxyOrItem} is
        stored in is not accessible via the web, for example due to the fact
        that the store has no L{LoginMethod} objects to indicate who it is
        owned by.
    """
    if isinstance(sharedProxyOrItem, sharing.SharedProxy):
        userStore = sharing.itemFromProxy(sharedProxyOrItem).store
    else:
        userStore = sharedProxyOrItem.store
    appStore = isAppStore(userStore)
    if appStore:
        # This code-path should be fixed by #2703; PublicWeb is deprecated.
        from xmantissa.publicweb import PublicWeb
        substore = userStore.parent.getItemByID(userStore.idInParent)
        pw = userStore.parent.findUnique(PublicWeb,
                                         PublicWeb.application == substore)
        path = [pw.prefixURL.encode('ascii')]
    else:
        for lm in userbase.getLoginMethods(userStore):
            if lm.internal:
                path = ['users', lm.localpart.encode('ascii')]
                break
        else:
            raise RuntimeError("Shared item is in a user store with no"
                               " internal username -- can't generate a link.")
    if (sharedProxyOrItem.shareID == getDefaultShareID(userStore)):
        shareID = sharedProxyOrItem.shareID
        path.append('')
    else:
        shareID = None
        path.append(sharedProxyOrItem.shareID)
    return _ShareURL(shareID, scheme='', netloc='', pathsegs=path)
Exemple #13
0
def linkTo(sharedProxyOrItem):
    """
    Generate the path part of a URL to link to a share item or its proxy.

    @param sharedProxy: a L{sharing.SharedProxy} or L{sharing.Share}

    @return: a URL object, which when converted to a string will look
        something like '/users/user@host/shareID'.

    @rtype: L{nevow.url.URL}

    @raise: L{RuntimeError} if the store that the C{sharedProxyOrItem} is
        stored in is not accessible via the web, for example due to the fact
        that the store has no L{LoginMethod} objects to indicate who it is
        owned by.
    """
    if isinstance(sharedProxyOrItem, sharing.SharedProxy):
        userStore = sharing.itemFromProxy(sharedProxyOrItem).store
    else:
        userStore = sharedProxyOrItem.store
    appStore = isAppStore(userStore)
    if appStore:
        # This code-path should be fixed by #2703; PublicWeb is deprecated.
        from xmantissa.publicweb import PublicWeb

        substore = userStore.parent.getItemByID(userStore.idInParent)
        pw = userStore.parent.findUnique(PublicWeb, PublicWeb.application == substore)
        path = [pw.prefixURL.encode("ascii")]
    else:
        for lm in userbase.getLoginMethods(userStore):
            if lm.internal:
                path = ["users", lm.localpart.encode("ascii")]
                break
        else:
            raise RuntimeError("Shared item is in a user store with no" " internal username -- can't generate a link.")
    if sharedProxyOrItem.shareID == getDefaultShareID(userStore):
        shareID = sharedProxyOrItem.shareID
        path.append("")
    else:
        shareID = None
        path.append(sharedProxyOrItem.shareID)
    return _ShareURL(shareID, scheme="", netloc="", pathsegs=path)
 def view(self, request, tag):
     """
     Render the child blurbs of this blurb
     """
     blurbs = self._getChildBlurbs(request)
     if 0 < len(blurbs):
         blurbItem = sharing.itemFromProxy(self.original)
         fragment = ShareScrollingElement(
             self.getRole(),
             blurbItem.store,
             Blurb,
             Blurb.parent == blurbItem,
             [_BlurbTimestampColumn(), BlurbViewColumn()],
             Blurb.dateCreated, False,
             ixmantissa.IWebTranslator(blurbItem.store))
         _docFactorify(fragment)
         fragment.setFragmentParent(self)
         return fragment
     else:
         p = inevow.IQ(tag).onePattern('no-child-blurbs')
         return p.fillSlots('child-type-name', self._childTypeName)
 def test_postPermissions(self):
     """
     Verify that a post made on the blog by its owner cannot be commented on by
     people who are not authorized to comment on it.
     """
     postShareID = self.blog.post(u'My First Post', u'Hello, Viewers', self.me)
     self.assertNotIdentical(postShareID, None)
     sharedPost = getShare(self.userStore, self.you, postShareID)
     commentShareID = sharedPost.post(u'My Comemnt To Your Post',
                                      u'Your Bolg Sucks, man', self.you)
     self.assertNotIdentical(commentShareID, None)
     sharedComment = getShare(self.userStore, self.you, commentShareID)
     self.assertIdentical(sharedComment.parent, itemFromProxy(sharedPost))
     self.assertRaises(AttributeError,
                       lambda: sharedPost.edit(
             u'Ima Haxer', u'Haxed u', self.you, ()))
     newTitle = u'My Comment To Your Post'
     newBody = u'Your Blog Sucks, man'
     sharedComment.edit(newTitle, newBody, self.you, ())
     self.assertEquals(sharedComment.body, newBody)
     self.assertEquals(sharedComment.title, newTitle)
 def test_postPermissions(self):
     """
     Verify that a post made on the blog by its owner cannot be commented on by
     people who are not authorized to comment on it.
     """
     postShareID = self.blog.post(u'My First Post', u'Hello, Viewers',
                                  self.me)
     self.assertNotIdentical(postShareID, None)
     sharedPost = getShare(self.userStore, self.you, postShareID)
     commentShareID = sharedPost.post(u'My Comemnt To Your Post',
                                      u'Your Bolg Sucks, man', self.you)
     self.assertNotIdentical(commentShareID, None)
     sharedComment = getShare(self.userStore, self.you, commentShareID)
     self.assertIdentical(sharedComment.parent, itemFromProxy(sharedPost))
     self.assertRaises(
         AttributeError,
         lambda: sharedPost.edit(u'Ima Haxer', u'Haxed u', self.you, ()))
     newTitle = u'My Comment To Your Post'
     newBody = u'Your Blog Sucks, man'
     sharedComment.edit(newTitle, newBody, self.you, ())
     self.assertEquals(sharedComment.body, newBody)
     self.assertEquals(sharedComment.title, newTitle)