金字塔与形式管理

2024-06-02 05:03:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个金字塔项目使用形式化学管理界面。我添加了基本的ACL认证和金字塔形式的插件always denys,即使我已经通过了身份验证。在

对于如何只允许经过身份验证的用户使用金字塔形式的管理界面有什么想法?在

授权策略是这样添加的:

authn_policy = AuthTktAuthenticationPolicy('MYhiddenSECRET', callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()

config = Configurator(
   settings=settings,
   root_factory='package.auth.RootFactory',
   authentication_policy=authn_policy,
   authorization_policy=authz_policy
)

# pyramid_formalchemy's configuration
config.include('pyramid_formalchemy')
config.include('fa.jquery')
config.formalchemy_admin('admin', package='package', view='fa.jquery.pyramid.ModelView')

Tags: 身份验证pyramidconfigpackage界面settingsincludeadmin
1条回答
网友
1楼 · 发布于 2024-06-02 05:03:18

pyramid_formalchemy使用权限'view', 'edit', 'delete', 'new'来确定谁可以做什么。__acl__是从SQLAlchemy模型对象向下传播的。因此,您需要在每个模型对象上放置一个__acl__,以允许所需的组访问这些权限。例如,在pyramid_formalchemypyramidapp示例项目中:

class Bar(Base):
    __tablename__ = 'bar'
    __acl__ = [
            (Allow, 'admin', ALL_PERMISSIONS),
            (Allow, 'bar_manager', ('view', 'new', 'edit', 'delete')),
        ]
    id = Column(Integer, primary_key=True)
    foo = Column(Unicode(255))

当然,如果您不提供__acl__,那么它将在资源树的沿袭中查找,直到找到factory。默认情况下,pyramid_formalchemy定义了自己的工厂pyramid_formalchemy.resources.Models,但是您可以将其子类化并为其提供一个__acl__,作为所有模型的全局:

^{pr2}$

相关问题 更多 >