我想使用投票器将文件夹的权限授予用户以查看编辑管理器……在symfony 3.4中,我使用acl并没有问题,并且由于在symfony版本4中我们无法使用它,或者我没有任何相关文档,我想使用投票,但我不知道是否可以将用户访问权限应用于其他用户。 这是我在ACL中用于为用户注册对文件夹的新访问权限的代码
$aclProvider = $this->get('security.acl.provider'); $objectIdentity = ObjectIdentity::fromDomainObject($folder); try { $acl = $aclProvider->createAcl($objectIdentity); } catch (\Exception $e) { $acl = $aclProvider->findAcl($objectIdentity); } // retrieving the security identity of the currently logged-in user $securityIdentity = UserSecurityIdentity::fromAccount($user); $roles = ["view", "edit", "management", "administration", "noaccess"]; if (in_array($role, $roles)) { $aces = $acl->getObjectAces(); foreach ($aces as $index => $ace) { if ($ace->getSecurityIdentity() == $securityIdentity) { /* $ttt[$index]=$ace->getSecurityIdentity(); print_r($ttt);*/ $acl->deleteObjectAce($index); } } } // grant role access switch ($role) { case "view": $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_VIEW); break; case "edit": $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_EDIT); break; case "management": $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_MASTER); break; case "administration": if (true === $this->isGranted('OWNER', $folder) || $this->isGranted('ROLE_ADMIN') ) { $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER); } else { return new JsonResponse(array('success' => false,"message" > => "Vous n'avez pas la permission de donner l'accès à ce dossier " . $folder->getName() . " !")); } break; case "noaccess": break; default: throw $this->createNotFoundException(); } $aclProvider->updateAcl($acl); $em = $this->getDoctrine()->getManager(); $documents = $em->getRepository('AppBundle:Document')->findByFolder($folder); foreach ($documents as $document) { $this->grantAccessToFile($document, $user, $role); } $folders = $em->getRepository('AppBundle:Folder')->findBySubfolder($folder); foreach ($folders as $oneFolder) { $this->grantAccessToFolder($oneFolder, $user, $role); }