Skip to content

Commit

Permalink
Use own permission for layoutedit tab.
Browse files Browse the repository at this point in the history
Permission is: 'collective.cover: Can Edit Layout'
  • Loading branch information
mauritsvanrees committed Nov 20, 2013
1 parent 9855521 commit d0d5f47
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/collective/cover/configure.zcml
Expand Up @@ -20,6 +20,11 @@
title="collective.cover: Can Export Layout"
/>

<permission
id="collective.cover.CanEditLayout"
title="collective.cover: Can Edit Layout"
/>

<grok:grok package="." />

<include package=".tiles" />
Expand Down
2 changes: 1 addition & 1 deletion src/collective/cover/content.py
Expand Up @@ -168,7 +168,7 @@ def update(self):
# XXX: we need to leave the view after saving or cancelling editing
class LayoutEdit(grok.View):
grok.context(ICover)
grok.require('cmf.ModifyPortalContent')
grok.require('collective.cover.CanEditLayout')

def update(self):
self.context = aq_inner(self.context)
Expand Down
6 changes: 6 additions & 0 deletions src/collective/cover/profiles.zcml
Expand Up @@ -61,6 +61,12 @@
handler=".upgrades.issue_330"
/>

<genericsetup:upgradeStep
title="New permission for Layout edit tab"
description="Protect Layout edit tab with new permission granted to Managers and Site Admins"
handler=".upgrades.layout_edit_permission"
/>

</genericsetup:upgradeSteps>

</configure>
4 changes: 4 additions & 0 deletions src/collective/cover/profiles/default/rolemap.xml
Expand Up @@ -5,5 +5,9 @@
<role name="Manager"/>
<role name="Site Administrator"/>
</permission>
<permission name="collective.cover: Can Edit Layout" acquire="False">
<role name="Manager"/>
<role name="Site Administrator"/>
</permission>
</permissions>
</rolemap>
Expand Up @@ -62,6 +62,6 @@
<action title="Layout" action_id="layoutedit" category="object"
condition_expr="not:object/@@plone_lock_info/is_locked_for_current_user|python:True"
url_expr="string:${object_url}/layoutedit" visible="True" i18n:attributes="title">
<permission value="Modify portal content" />
<permission value="collective.cover: Can Edit Layout" />
</action>
</object>
25 changes: 24 additions & 1 deletion src/collective/cover/tests/test_upgrades.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from Products.CMFCore.utils import getToolByName
from collective.cover.config import DEFAULT_GRID_SYSTEM
from collective.cover.testing import INTEGRATION_TESTING
from plone.registry.interfaces import IRegistry
Expand Down Expand Up @@ -129,7 +130,7 @@ def setUp(self):
def test_upgrade_to_7_registrations(self):
version = self.setup.getLastVersionForProfile(self.profile_id)[0]
self.assertTrue(version >= self.to_version)
self.assertEqual(self._how_many_upgrades_to_do(), 1)
self.assertEqual(self._how_many_upgrades_to_do(), 2)

def test_issue_330(self):
# check if the upgrade step is registered
Expand All @@ -149,3 +150,25 @@ def test_issue_330(self):
self._do_upgrade_step(step)
self.assertEqual(registry.records[record_name].value,
DEFAULT_GRID_SYSTEM)

def test_layout_edit_permission(self):
# check if the upgrade step is registered
title = u'New permission for Layout edit tab'
description = (u'Protect Layout edit tab with new permission '
u'granted to Managers and Site Admins')

step = self._get_upgrade_step(title)
self.assertIsNotNone(step)
self.assertEqual(step['description'], description)

# simulate state on previous version
types = getToolByName(self.portal, 'portal_types')
cover_type = types['collective.cover.content']
action = cover_type.getActionObject('object/layoutedit')
action.permissions = (u'Modify portal content', )

# run the upgrade step to validate the update
self._do_upgrade_step(step)
action = cover_type.getActionObject('object/layoutedit')
self.assertEqual(action.permissions,
(u'collective.cover: Can Edit Layout', ))
10 changes: 10 additions & 0 deletions src/collective/cover/upgrades.py
Expand Up @@ -9,6 +9,7 @@
import logging

logger = logging.getLogger(PROJECTNAME)
PROFILE_ID = 'profile-collective.cover:default'


def issue_201(context):
Expand Down Expand Up @@ -69,3 +70,12 @@ def issue_330(context):
# Reregister the interface.
registry = getUtility(IRegistry)
registry.registerInterface(ICoverSettings)


def layout_edit_permission(context):
"""New permission for Layout edit tab.
We need to apply our rolemap and typeinfo for this.
"""
context.runImportStepFromProfile(PROFILE_ID, 'rolemap')
context.runImportStepFromProfile(PROFILE_ID, 'typeinfo')

0 comments on commit d0d5f47

Please sign in to comment.