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