2016-03-03 82 views
0

我有一个具有买方(用户实体)和卖方(用户实体)的订单实体。许多用户的symfony2 ACL

我想通过Symfony2 ACL仅通过2位用户(买家和卖家)看到此订单。

我做了很多测试但没有成功。请帮助 ! 这是下面的脚本:

 // creating the ACL 
     $aclProvider = $this->get('security.acl.provider'); 
     $objectIdentity = ObjectIdentity::fromDomainObject($order); 
     try { 
      $acl = $aclProvider->findAcl($objectIdentity); 
     } catch(\Symfony\Component\Security\Acl\Exception\AclNotFoundException $e) { 
      $acl = $aclProvider->createAcl($objectIdentity); 
     } 

     // mask builder permissions 
     $maskBuilder = new MaskBuilder(); 
     $maskBuilder->add('view') 
        ->add('edit'); 
     $mask = $maskBuilder->get(); 

     // security identity for the seller 
     $securityIdentitySeller = new UserSecurityIdentity($order->getSeller(), "ACMEUserBundle\Entity\User"); 
     $acl->insertObjectAce($securityIdentitySeller, $mask); 

     // security identity for the buyer 
     $securityIdentityBuyer = new UserSecurityIdentity($order->getBuyer(), "ACMEUserBundle\Entity\User"); 
     $acl->insertObjectAce($securityIdentityBuyer, MaskBuilder::MASK_OWNER); 

     // update the acl 
     $aclProvider->updateAcl($acl); 

==================================== ==================================== 不幸的是,这个脚本在数据库中用相同的用户创建了2个ACE (订单卖家)

回答

0

您的情况听起来几乎完全像Symfony Cookbook section on ACL中提供的示例。这个例子是关于一个博客作者,除了博客自己以外,他只希望博客上的评论作者能够编辑他或她自己的评论。其他评论者不应该能够编辑其他评论者的评论。这个例子和你的情况唯一真正的区别是编辑权限和查看权限。一旦你有必要的ACL过滤,你可以通过多种方式处理这些细节,详见菜谱。

+0

我用一些脚本编辑了我的问题,以便更多地理解我 – wessbac