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_)
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_)
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
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)
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)
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_)
# # 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())
# 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)
# 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')
# # 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')
# 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())