示例#1
0
    def test_all_merged_tagged_values_dict(self):
        from zope.interface import Interface

        class IIFace1(Interface):
            pass

        class IIFace2(Interface):
            pass

        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {}
        )

        IIFace1.setTaggedValue('foo', {'a': 10})
        IIFace1.setTaggedValue('bar', {'a': 11})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 10}
        )
        IIFace2.setTaggedValue('foo', {'a': 12})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 12}
        )
        IIFace2.setTaggedValue('foo', {'a': 13, 'b': 14})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 13, 'b': 14}
        )
示例#2
0
    def test_all_merged_tagged_values_dict(self):
        from zope.interface import Interface

        class IIFace1(Interface):
            pass

        class IIFace2(Interface):
            pass

        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {}
        )

        IIFace1.setTaggedValue('foo', {'a': 10})
        IIFace1.setTaggedValue('bar', {'a': 11})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 10}
        )
        IIFace2.setTaggedValue('foo', {'a': 12})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 12}
        )
        IIFace2.setTaggedValue('foo', {'a': 13, 'b': 14})
        self.assertEqual(
            utils.all_merged_tagged_values_dict((IIFace1, IIFace2), 'foo'),
            {'a': 13, 'b': 14}
        )
示例#3
0
    def __call__(self, name, value):
        # Short circuit for things like views or viewlets
        if name == '':
            return 1

        context = aq_parent(self)

        # we may want to cache this based on the combined mod-times
        # of fti and context, but even this is not save in the case someone
        # decides to have behaviors bound on something different than context
        # or fti, i.e. schemas for subtrees.
        protection_dict = all_merged_tagged_values_dict(
            iterSchemata(context),
            READ_PERMISSIONS_KEY
        )

        if name not in protection_dict:
            return 1

        permission = queryUtility(IPermission, name=protection_dict[name])
        if permission is not None:
            return getSecurityManager().checkPermission(
                permission.title, context
            )

        return 0
示例#4
0
    def __call__(self, name, value):
        # Short circuit for things like views or viewlets
        if name == '':
            return 1

        context = aq_parent(self)

        # we may want to cache this based on the combined mod-times
        # of fti and context, but even this is not save in the case someone
        # decides to have behaviors bound on something different than context
        # or fti, i.e. schemas for subtrees.
        protection_dict = all_merged_tagged_values_dict(
            iterSchemata(context), READ_PERMISSIONS_KEY)

        if name not in protection_dict:
            return 1

        permission = queryUtility(IPermission, name=protection_dict[name])
        if permission is not None:
            return getSecurityManager().checkPermission(
                permission.title, context)

        return 0