2011-04-15 2 views
5

나는 formalchemy 관리 인터페이스를 사용하는 피라미드 프로젝트를 가지고 있습니다. 필자는 기본 ACL 인증을 추가했으며 pyramid_formalchemy 플러그인은 인증 되었더라도 항상 거부합니다.피라미드 및 FormAlchemy 관리 인터페이스

인증 된 사용자 만 pyramid_formalchemy 관리 인터페이스를 사용하도록 허용하는 방법에 대한 의견이 있으십니까?

 
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') 

답변

11

pyramid_formalchemy는 누가 무엇을 할 수 있는지 결정하는 권한 'view', 'edit', 'delete', 'new'을 사용

권한 부여 정책

은 다음과 같이 추가했다. __acl__은 SQLAlchemy 모델 객체에서 전파됩니다. 따라서 각 모델 객체에 __acl__을 두어 원하는 그룹이 해당 권한에 액세스 할 수있게해야합니다. 예를 들어, pyramid_formalchemy pyramidapp 예제 프로젝트에서 : 물론

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

, 당신은이 factory 안타 때까지 __acl__ 다음은 리소스 트리의 혈통에서 찾게됩니다 제공하지 않는 경우. 기본적으로 pyramid_formalchemy는 자체 공장 pyramid_formalchemy.resources.Models 정의, 그러나 당신은 당신의 모든 모델에 대한 글로벌,이 서브 클래스과에 __acl__를 제공 할 수

from pyramid_formalchemy.resources import Models 

class ModelsWithACL(Models): 
    """A factory to override the default security setting""" 
    __acl__ = [ 
      (Allow, 'admin', ALL_PERMISSIONS), 
      (Allow, Authenticated, 'view'), 
      (Allow, 'editor', 'edit'), 
      (Allow, 'manager', ('new', 'edit', 'delete')), 
     ] 

config.formalchemy_admin('admin', package='package', view=..., factory=ModelsWithACL) 
+0

멋진 대답 훌륭한 설명. 감사! –