isGranted('EDIT'、$ userObject)を使用して、すべての管理者とマネージャー、およびその1人のユーザーが特定のユーザーデータを編集できるようにします。
コントロール編集$userObjectにACLを使用する必要がありますか?ログに記録されたユーザーと指定されたオブジェクトが同じであるか、ユーザーがマネージャーまたは管理者であるかを確認する追加の投票者を作成しました。
aclでは、すべての管理者、マネージャー、およびその1人のユーザーのuserObjectにACEを追加する必要があります。
Wchichの方法が推奨されますか?私はSymfonyの初心者です。
以下は投票者のコードです。
function vote(TokenInterface $token, $object, array $attributes)
{
$intersect=array_intersect(array('EDIT','VIEW' ), $attributes);
if (!empty($intersect))
{
//intersect is not empty, it seems to edit or view are in $attributes
//voter grants privileges for [user->granted object]
//manager->every customer, child-manager
//admin->every customer and manager
if ($token->getUser()->isAdmin())
{
return VoterInterface::ACCESS_GRANTED;
}
elseif ($token->getUser()->isCustomer())
{
//voter not want to think about customer grants, because customer grants currently are held in ACL
return VoterInterface::ACCESS_ABSTAIN;
}
/* @var $object \PSB\StoreBundle\Entity\Customer */
if (is_a($object, '\PSB\StoreBundle\Entity\Customer'))
{
if ($token->getUser()->isManager())
{
//managers also edit customers
return VoterInterface::ACCESS_GRANTED;
}
}
elseif (is_a($object, '\PSB\StoreBundle\Entity\Manager'))
{
/* @var $object \PSB\StoreBundle\Entity\Manager */
if ($token->getUser()->isManager())
{
//manager can edit own children
if ($token->getUser() == $object->getParent())
{
return VoterInterface::ACCESS_GRANTED;
}
}
}
}
return VoterInterface::ACCESS_ABSTAIN;
}