Ejemplo n.º 1
0
 def add_in_registry():
     self.define_cls(typename='Core', name='Base', val=2)
     cls_ = self.define_cls(typename='Core', name='Base', val=2,
                            usesuper=True)
     self.define_cls(val=2, usesuper=True)
     from anyblok import Declarations
     Declarations.unregister(Declarations.Core.Base, cls_)
Ejemplo n.º 2
0
 def add_in_registry():
     self.define_cls(typename='Mixin', name='MTest', val=3)
     cls_ = self.define_cls(typename='Mixin', name='MTest', val=3,
                            usesuper=True)
     self.define_cls(val=3, usesuper=True, inherit='MTest')
     from anyblok import Declarations
     Declarations.unregister(Declarations.Mixin.MTest, cls_)
Ejemplo n.º 3
0
 def test_add_doublon(self):
     Declarations.add_declaration_type(cls_=OneType)
     try:
         Declarations.add_declaration_type(cls_=OneType)
         self.fail('No watch dog for doublon declarations type')
     except DeclarationsException:
         pass
Ejemplo n.º 4
0
    def test_add_decoration(self):
        @Declarations.add_declaration_type()
        class MyOneType(OneType):
            pass

        self.assertEqual(Declarations.declaration_types['MyOneType'],
                         MyOneType)

        @Declarations.register(Declarations.MyOneType)
        class SubType:
            pass

        Declarations.unregister(Declarations.MyOneType.SubType, SubType)
Ejemplo n.º 5
0
    def test_add(self):
        Declarations.add_declaration_type(cls_=OneType)
        self.assertEqual(Declarations.declaration_types['OneType'], OneType)

        class SubType:
            pass

        Declarations.register(Declarations.OneType, cls_=SubType)
        Declarations.unregister(Declarations.OneType, cls_=SubType)
Ejemplo n.º 6
0
 def add_in_registry():
     self.define_cls()
     cls_ = self.define_cls(val=2, usesuper=True)
     self.define_cls(val=2, usesuper=True)
     from anyblok import Declarations
     Declarations.unregister(Declarations.Model.Test, cls_)
Ejemplo n.º 7
0
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok import Declarations
from anyblok.column import Integer, String
from ..authorization import TestRuleOne, TestRuleTwo

register = Declarations.register
Model = Declarations.Model


@register(Model)
class Test:

    id = Integer(primary_key=True)
    label = String()


@register(Model)
class Test2:

    id = Integer(primary_key=True)
    label = String()


Declarations.AuthorizationBinding(Declarations.Model.Test,
                                  TestRuleOne(),
                                  permission='Read')
Declarations.AuthorizationBinding(Declarations.Model.Test, TestRuleTwo())
Ejemplo n.º 8
0
# This file is a part of the AnyBlok project
#
#    Copyright (C) 2015 Georges Racinet <*****@*****.**>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.

from anyblok import Declarations
from anyblok.authorization.rule.base import deny_all


@Declarations.register(Declarations.Model)
class Authorization:
    """Namespace for models supporting authorization policies."""


class DefaultModelDeclaration:
    """Pseudo model to represent the default value."""

    __registry_name__ = None


Declarations.AuthorizationBinding(DefaultModelDeclaration, deny_all)
Ejemplo n.º 9
0
# This file is a part of the AnyBlok project
#
#    Copyright (C) 2014 Jean-Sebastien SUZANNE <*****@*****.**>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok import Declarations
from anyblok.column import Integer
from ..authorization import TestRuleOne, TestRuleTwo

register = Declarations.register
Model = Declarations.Model


@register(Model)
class Test:

    test2 = Integer(foreign_key=Model.Test2.use('id'))


Declarations.AuthorizationBinding(Declarations.Model.Test,
                                  TestRuleOne(),
                                  permission='Other')
Declarations.AuthorizationBinding(Declarations.Model.Test,
                                  TestRuleOne())
Declarations.AuthorizationBinding(Declarations.Model.Test,
                                  TestRuleTwo(),
                                  permission='Write')
Ejemplo n.º 10
0
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok import Declarations
from anyblok.column import String
from anyblok.authorization.rule.modelaccess import ModelAccessRule
from anyblok.authorization.rule.attraccess import AttributeAccessRule

register = Declarations.register
Model = Declarations.Model


@register(Model)
class Test2:
    """We'll work on Test2, on which test_blok7 doesn't set any authz policy.
    """
    owner = String()


Declarations.AuthorizationBinding(Declarations.Model.Test2, ModelAccessRule())

Declarations.AuthorizationBinding(Declarations.Model.Test2,
                                  AttributeAccessRule('owner'),
                                  permission='Write')

Declarations.AuthorizationBinding(Declarations.Model.Test2,
                                  AttributeAccessRule(
                                      'owner', model_rule=ModelAccessRule()),
                                  permission='PermWithModelRule')
Ejemplo n.º 11
0
# This file is a part of the AnyBlok project
#
#    Copyright (C) 2015 Georges Racinet <*****@*****.**>
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file,You can
# obtain one at http://mozilla.org/MPL/2.0/.
from anyblok import Declarations
from anyblok.authorization.rule.modelaccess import ModelAccessRule

# Normally, this blok should be part of the edge
Declarations.AuthorizationBinding(Declarations.Model.Test2, ModelAccessRule())