Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://svn.plone.org/svn/collective/feedfeeder/trunk@229079 db7f04ef-aaf3-0310-a811-c281ed44c4ad
- Loading branch information
maurits
committed
Dec 17, 2010
1 parent
ee46815
commit d88d738
Showing
13 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from zope.interface import Interface | ||
from zope.interface import implements | ||
from zope.component import getMultiAdapter | ||
|
||
from Products.Five import BrowserView | ||
|
||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
|
||
|
||
class IFeedItemView(Interface): | ||
""" """ | ||
|
||
def redirect_url(): | ||
""" Returns empty string or the url to be redirected, depending on | ||
the configuration of the feed folder. | ||
Returns an empty string if redirect is not enabled or if | ||
you have modify permissions | ||
""" | ||
|
||
def parent(): | ||
""" Returns the feed item parent """ | ||
|
||
def checkEditPermission(): | ||
""" Returns if you have the edit permission""" | ||
|
||
|
||
class FeedItemView(BrowserView): | ||
""" | ||
Verify class test | ||
>>> from zope.interface.verify import verifyClass | ||
>>> verifyClass(IFeedItemView, FeedItemView) | ||
True | ||
Fake objects | ||
------------ | ||
>>> fake_request = {} | ||
>>> class FakeFolder(object): | ||
... def __init__(self, redirect): | ||
... self.redirect = redirect | ||
... def getRedirect(self): | ||
... return self.redirect | ||
>>> class FakeItem(object): | ||
... def __init__(self, redirect): | ||
... self.folder = FakeFolder(redirect) | ||
... def getObjectInfo(self): | ||
... return {'link':'http://somewhere'} | ||
... def getFeedFolder(self): | ||
... return self.folder | ||
>>> class FakeFeedItemView(FeedItemView): | ||
... def checkEditPermission(self): | ||
... return True | ||
Test redirects | ||
-------------- | ||
Item with a folder with redirect enabled | ||
>>> item1 = FakeItem(True) | ||
>>> view1 = FakeFeedItemView(item1, fake_request) | ||
>>> bool(view1.redirect_url()) | ||
False | ||
Item with a folder with redirect not enabled | ||
>>> item2 = FakeItem(False) | ||
>>> view2 = FakeFeedItemView(item2, fake_request) | ||
>>> bool(view2.redirect_url()) | ||
False | ||
Test redirects with no edit permissions | ||
--------------------------------------- | ||
>>> class FakeFeedItemView(FeedItemView): | ||
... def checkEditPermission(self): | ||
... return False | ||
Item with a folder with redirect enabled | ||
>>> item1 = FakeItem(True) | ||
>>> view1 = FakeFeedItemView(item1, fake_request) | ||
>>> view1.redirect_url() | ||
'http://somewhere' | ||
Item with a folder with redirect not enabled | ||
>>> item2 = FakeItem(False) | ||
>>> view2 = FakeFeedItemView(item2, fake_request) | ||
>>> bool(view2.redirect_url()) | ||
False | ||
""" | ||
implements(IFeedItemView) | ||
|
||
def __call__(self): | ||
redirect_url = self.redirect_url() | ||
if redirect_url: | ||
return self.request.response.redirect(redirect_url) | ||
# Render our template as set in the zcml. | ||
return self.index() | ||
|
||
def redirect_url(self): | ||
object_info = self.context.getObjectInfo() | ||
parent = self.parent() | ||
if parent.getRedirect() and not self.checkEditPermission(): | ||
return object_info.get('link') | ||
else: | ||
return '' | ||
|
||
def parent(self): | ||
return self.context.getFeedFolder() | ||
|
||
def checkEditPermission(self): | ||
""" Returns if you have the edit permission""" | ||
membership = getMultiAdapter((self.context, self.request), | ||
name=u'plone_tools').membership() | ||
return membership.checkPermission( | ||
'Modify portal content', self.context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ def replaceItem(id): | |
def getItem(id): | ||
""" | ||
""" | ||
|
||
def getFeedFolder(): | ||
""" """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<feed xmlns="http://www.w3.org/2005/Atom"> | ||
<title>Philips Research Eindhoven News</title> | ||
<subtitle>General news of Philips Research Eindhoven - for internal use only.</subtitle> | ||
<updated>2007-07-30T23:32:36Z</updated> | ||
<id>http://resweb2.natlab.research.philips.com/NlwwNews/rss/NlwwNewsAtom.xml</id> | ||
<entry> | ||
<title>The title is changed</title> | ||
<id>oldnews</id> | ||
<content type="xhtml"> | ||
<div xmlns="http://www.w3.org/1999/xhtml"> | ||
The content is changed | ||
</div> | ||
</content> | ||
<updated></updated> | ||
<published>2008-07-30T23:32:36Z</published> | ||
<author><name>Not Reinout anymore</name></author> | ||
</entry> | ||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from Products.feedfeeder.tests.MainTestCase import MainTestCase | ||
|
||
|
||
class TestFields(MainTestCase): | ||
""" """ | ||
def afterSetUp(self): | ||
self.loginAsPortalOwner() | ||
|
||
feedfolder_id = self.folder.invokeFactory('FeedfeederFolder', 'feedfolder') | ||
|
||
self.feedfolder = getattr(self.folder, feedfolder_id) | ||
# self.feedfolder.invokeFactor | ||
|
||
def test_redirect_field(self): | ||
""" Does exists the redirect field? """ | ||
self.assertTrue(getattr(self.feedfolder, 'getRedirect')) | ||
|
||
def test_suite(): | ||
from unittest import TestSuite, makeSuite | ||
suite = TestSuite() | ||
suite.addTest(makeSuite(TestFields)) | ||
return suite | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters