Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket11189 #5

Merged
merged 3 commits into from
Nov 21, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Products/CMFPlone/browser/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def _getNavQuery(self):
def topLevelTabs(self, actions=None, category='portal_tabs'):
context = aq_inner(self.context)

mtool = getToolByName(context, 'portal_membership')
member = mtool.getAuthenticatedMember().id

portal_properties = getToolByName(context, 'portal_properties')
self.navtree_properties = getattr(portal_properties,
'navtree_properties')
Expand Down Expand Up @@ -179,11 +182,18 @@ def topLevelTabs(self, actions=None, category='portal_tabs'):

rawresult = self.portal_catalog.searchResults(query)

def get_link_url(item):
linkremote = item.getRemoteUrl and not member == item.Creator
if linkremote:
return (get_id(item), item.getRemoteUrl)
else:
return False

# now add the content to results
idsNotToList = self.navtree_properties.getProperty('idsNotToList', ())
for item in rawresult:
if not (item.getId in idsNotToList or item.exclude_from_nav):
id, item_url = get_view_url(item)
id, item_url = get_link_url(item) or get_view_url(item)
data = {'name': utils.pretty_title_or_id(context, item),
'id': item.getId,
'url': item_url,
Expand Down
7 changes: 7 additions & 0 deletions Products/CMFPlone/browser/navtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def decoratorFactory(self, node):
if portalType is not None and portalType in self.viewActionTypes:
itemUrl += '/view'

useRemoteUrl = False
getRemoteUrl = getattr(item, 'getRemoteUrl', None)
isCreator = self.memberId == getattr(item, 'Creator', None)
if getRemoteUrl and not isCreator:
useRemoteUrl = True

isFolderish = getattr(item, 'is_folderish', None)
showChildren = False
if isFolderish and (portalType is None or portalType not in self.parentTypesNQ):
Expand All @@ -173,6 +179,7 @@ def decoratorFactory(self, node):
newNode['no_display'] = False # We sort this out with the nodeFilter
# BBB getRemoteUrl and link_remote are deprecated, remove in Plone 4
newNode['getRemoteUrl'] = getattr(item, 'getRemoteUrl', None)
newNode['useRemoteUrl'] = useRemoteUrl
newNode['link_remote'] = newNode['getRemoteUrl'] and newNode['Creator'] != self.memberId

idnormalizer = queryUtility(IIDNormalizer)
Expand Down
21 changes: 21 additions & 0 deletions Products/CMFPlone/tests/testNavigationView.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,27 @@ def testPortalTabsNotIncludeViewNamesInCSSid(self):
for tab in tabs:
self.assertEqual(validateCSSIdentifier(tab['id']),True)

def testLinkRemoteUrlsUsedUnlessLinkCreator(self):
self.setRoles(['Manager'])
self.portal.invokeFactory('Link', 'link1')
self.portal.link1.setRemoteUrl('http://plone.org')
self.portal.link1.reindexObject()
view = self.view_class(self.portal, self.request)
tabs = view.topLevelTabs(actions=[])
for tab in tabs:
# as Creator tab for link1 should have url of the item
if tab['id'] == 'link1':
self.failUnless(tab['url'] == 'http://nohost/plone/link1')

self.setRoles(['Manager'])
self.portal.link1.setCreators(['some_other_user'])
self.portal.link1.reindexObject()
tabs = view.topLevelTabs(actions=[])
for tab in tabs:
# as non-Creator user, tab for link1 should have url of the remote url
if tab['id'] == 'link1':
self.failUnless(tab['url'] == 'http://plone.org')


class TestCatalogPortalTabs(TestBasePortalTabs):
view_class = CatalogNavigationTabs
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Changelog

4.2b1 - Unreleased
------------------
- Fixed the two high priority scenarios (global sections viewlet and nav
portlet) of http://dev.plone.org/ticket/11189.
[fulv]

- Remove uneeded kss debugging code
[jfroche]
Expand Down