Skip to content

Commit

Permalink
Read "allow_anon_views_about" from registry instead of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jcerjak committed Jan 25, 2015
1 parent 3049a17 commit ec8d8bb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,10 @@ Changelog
2.5.4 (unreleased)
------------------

- Read ``allow_anon_views_about`` settings from the registry instead of portal
properties (see https://github.com/plone/Products.CMFPlone/issues/216).
[jcerjak]

- Added support for site logos stored in the portal registry via the site
control panel for the logo viewlet with a fallback to the ``OFS.Image``
based ``logo.png`` file. Removed support of long-gone
Expand Down
12 changes: 7 additions & 5 deletions plone/app/layout/links/viewlets.py
Expand Up @@ -13,6 +13,7 @@
from zope.schema.interfaces import IVocabularyFactory
from zope.component import getUtility
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import ISecuritySchema
from Products.CMFPlone.interfaces.syndication import IFeedSettings
from Products.CMFPlone.interfaces.syndication import ISiteSyndicationSettings

Expand Down Expand Up @@ -62,12 +63,13 @@ def update(self):
name='plone_tools')

def show(self):
properties = self.tools.properties()
site_properties = getattr(properties, 'site_properties')
anonymous = self.portal_state.anonymous()
allowAnonymousViewAbout = site_properties.getProperty(
'allowAnonymousViewAbout', True)
return not anonymous or allowAnonymousViewAbout
registry = getUtility(IRegistry)
settings = registry.forInterface(
ISecuritySchema,
prefix='plone',
)
return not anonymous or settings.allow_anon_views_about

def render(self):
if self.show():
Expand Down
14 changes: 9 additions & 5 deletions plone/app/layout/viewlets/content.py
Expand Up @@ -6,14 +6,17 @@
from AccessControl import getSecurityManager
from Acquisition import aq_inner
from DateTime import DateTime
from plone.registry.interfaces import IRegistry
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import _checkPermission
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.CMFEditions.Permissions import AccessPreviousVersions
from Products.CMFPlone import PloneMessageFactory as _
from Products.CMFPlone.interfaces import ISecuritySchema
from Products.CMFPlone.utils import base_hasattr
from Products.CMFPlone.utils import log
from zope.component import getUtility

from plone.app.layout.globals.interfaces import IViewView
from plone.app.layout.viewlets import ViewletBase
Expand Down Expand Up @@ -64,11 +67,12 @@ def update(self):
self.has_pam = HAS_PAM

def show(self):
properties = getToolByName(self.context, 'portal_properties')
site_properties = getattr(properties, 'site_properties')
allowAnonymousViewAbout = site_properties.getProperty(
'allowAnonymousViewAbout', True)
return not self.anonymous or allowAnonymousViewAbout
registry = getUtility(IRegistry)
settings = registry.forInterface(
ISecuritySchema,
prefix='plone',
)
return not self.anonymous or settings.allow_anon_views_about

def show_history(self):
has_access_preview_versions_permission = _checkPermission(
Expand Down
40 changes: 40 additions & 0 deletions plone/app/layout/viewlets/tests/test_content.py
Expand Up @@ -8,6 +8,8 @@
from plone.app.layout.viewlets.content import ContentRelatedItems
from plone.locking.tests import addMember
from plone.locking.interfaces import ILockable
from plone.registry.interfaces import IRegistry
from Products.CMFPlone.interfaces import ISecuritySchema

from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -35,6 +37,44 @@ def afterSetUp(self):
portal = getSite()
addMember(portal, 'Alan', roles=('Member', 'Manager'))
addMember(portal, 'Ano', roles=())
self.folder.invokeFactory('Document', 'doc1', title='Document 1')

registry = getUtility(IRegistry)
self.security_settings = registry.forInterface(
ISecuritySchema,
prefix='plone',
)

def _get_viewlet(self):
context = self.folder['doc1']
request = self.app.REQUEST
viewlet = DocumentBylineViewlet(context, request, None, None)
viewlet.update()
return viewlet

def test_show_anonymous_not_allowed(self):
self.security_settings.allow_anon_views_about = False
self.logout()
viewlet = self._get_viewlet()
self.assertFalse(viewlet.show())

def test_show_anonymous_allowed(self):
self.security_settings.allow_anon_views_about = True
self.logout()
viewlet = self._get_viewlet()
self.assertTrue(viewlet.show())

def test_show_logged_in_anonymous_not_allowed(self):
self.security_settings.allow_anon_views_about = False
self.login('Alan')
viewlet = self._get_viewlet()
self.assertTrue(viewlet.show())

def test_show_logged_in_anonymous_allowed(self):
self.security_settings.allow_anon_views_about = True
self.login('Alan')
viewlet = self._get_viewlet()
self.assertTrue(viewlet.show())

def test_anonymous_locked_icon(self):
request = self.app.REQUEST
Expand Down

0 comments on commit ec8d8bb

Please sign in to comment.