Skip to content

Commit

Permalink
Merge 2a02de4 into 128bbec
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Aug 24, 2020
2 parents 128bbec + 2a02de4 commit 9d8a801
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
0.0.3 (unreleased)
==================

- Nothing changed yet.
- Move permission definition to a separate file, ``permissions.zcml``,
that is included by default. Use the ZCML ``<exclude>`` directive
before including this package's configuration if you were
experiencing configuration conflicts.


0.0.2 (2020-08-06)
Expand Down
9 changes: 2 additions & 7 deletions src/nti/webhooks/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,8 @@
<!-- Global event dispatchers are configured in subscribers.zcml -->

<!-- Permissions that we use. -->
<!-- These are duplicates, but that's OK: they are compared by ID -->
<permission
id="nti.actions.create"
title="Create new object" />
<permission
id="nti.actions.delete"
title="Delete existing object" />
<!-- See notes in this file about configuration conflicts -->
<include package="." file="permissions.zcml" />

<subscriber handler=".subscribers.apply_security_to_subscription"
trusted="true" />
Expand Down
24 changes: 24 additions & 0 deletions src/nti/webhooks/permissions.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- -*- mode: nxml -*- -->
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
i18n_domain="nti.webhooks">

<include package="zope.component" file="meta.zcml" />
<include package="zope.security" file="meta.zcml" />

<!--
Permissions that we use.
If you define these yourself and find a conflict, or you don't use them at all,
then you can exclude these *before* including this package:
<exclude package="nti.webhooks" file="permissions.zcml" />
-->
<permission
id="nti.actions.create"
title="Create new object" />
<permission
id="nti.actions.delete"
title="Delete existing object" />

</configure>
71 changes: 71 additions & 0 deletions src/nti/webhooks/tests/test_zcml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""
Tests for zcml.py and ZCML configuration.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


from nti.testing import base



class TestConfiguration(base.AbstractTestBase):

def test_duplicate_permissions_in_zcml_conflict(self, conflict=True):
# Duplicate permission IDs conflict; this is because
# the discriminator used by zope.component.zcml just includes
# ('utility', IPermission, <permission id>).
# Conflicts can be resolved if the path portion of one item is the
# subpath of another item (something about hierarchal includes) so
# to actually test this we have to write *two* files outside our
# hierarchy and include them both

from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationConflictError
import tempfile

if conflict:
exclude = ''
else:
exclude = '<exclude package="nti.webhooks" file="permissions.zcml" />'

for perm_id in ('nti.actions.create', 'nti.actions.delete'):
perm_zcml = """
<configure xmlns="http://namespaces.zope.org/zope"
i18n_domain="nti.somethingelse">
<include package="zope.security" />
<permission
id="%s"
title="something"/>
</configure>
""" % (perm_id,)

with tempfile.NamedTemporaryFile('wt') as perm_file:
perm_file.write(perm_zcml)
perm_file.flush()
with tempfile.NamedTemporaryFile('wt') as zcml_file:
zcml = """
<configure xmlns="http://namespaces.zope.org/zope"
i18n_domain="nti.somethingelse">
<include package="zope.component" file="meta.zcml" />
%s
<include package="nti.webhooks" />
<include file="%s" />
</configure>
""" % (exclude, perm_file.name,)
zcml_file.write(zcml)
zcml_file.flush()

if conflict:
with self.assertRaises(ConfigurationConflictError):
xmlconfig.file(zcml_file.name)
else:
xmlconfig.file(zcml_file.name)

def test_duplicate_permissions_in_zcml_excluded(self):
# Adding the exclude directive *before* processing the file fixes things.
self.test_duplicate_permissions_in_zcml_conflict(conflict=False)

0 comments on commit 9d8a801

Please sign in to comment.