/** * Grant access to a resource. * * Immediately grant access to a resoure. Creates a new ACE in the * database, and dispatches a Camdram-specific event that is used * to trigger sending of emails. */ public function grantAccess(OwnableInterface $entity, User $user, User $granter) { $ace = new AccessControlEntry(); $ace->setUser($user); $ace->setEntityId($entity->getId())->setCreatedAt(new \DateTime())->setGrantedBy($granter)->setGrantedAt(new \DateTime())->setType($entity->getAceType()); $this->entityManager->persist($ace); $this->entityManager->flush(); /* Send a Camdram-specific event that should trigger an email * notification. */ $this->eventDispatcher->dispatch(CamdramSecurityEvents::ACE_CREATED, new AccessControlEntryEvent($ace)); }
/** * find an ACE for this User accessing the specified resource. */ public function findAce(User $user, OwnableInterface $entity) { $qb = $this->createQueryBuilder('e'); $query = $qb->where('e.user = :user')->andWhere('e.entityId = :entityId')->andWhere('e.type = :type')->setParameter('user', $user)->setParameter('entityId', $entity->getId())->setParameter('type', $entity->getAceType()); return $query->getQuery()->getOneOrNullResult(); }