/** * {@inheritdoc} */ public function isParticipant(UserInterface $user) { foreach ($this->project->getParticipants() as $participant) { if ($user->getId() === $participant->getUser()->getId()) { return true; } } return false; }
function it_throws_access_denied_exception_because_the_user_is_not_the_owner_of_notification(EntityManager $manager, QueryBuilder $queryBuilder, Expr $expr, Expr\Comparison $comparison, AbstractQuery $query, NotificationInterface $notification, UserInterface $user, UserInterface $user2) { $this->getQueryBuilderSpec($manager, $queryBuilder); $this->addEqCriteriaSpec($queryBuilder, $expr, ['id' => 'notification-id'], $comparison); $queryBuilder->getQuery()->shouldBeCalled()->willReturn($query); $query->getSingleResult()->shouldBeCalled()->willReturn($notification); $notification->getUser()->shouldBeCalled()->willReturn($user); $user->getId()->shouldBeCalled()->willReturn('user-id'); $user2->getId()->shouldBeCalled()->willReturn('user2-id'); $this->shouldThrow(new AccessDeniedException())->during('findOneByUser', ['notification-id', $user2]); }
function it_is_not_participant(UserInterface $anotherUser) { $project = new Project(); $user = new User(); $participant = new Participant($project, $user); $project->addParticipant($participant); $this->setProject($project)->shouldReturn($this); $anotherUser->getId()->shouldBeCalled()->willReturn('user-id'); $this->isParticipant($anotherUser)->shouldReturn(false); }
function it_does_not_get_user_role(UserInterface $anotherUser) { $project = new Project(); $user = new User(); $participant = new Participant($project, $user); $this->addParticipant($participant)->shouldReturn($this); $anotherUser->getId()->shouldBeCalled()->willReturn('user-id'); $this->getUserRole($anotherUser)->shouldReturn(null); }
/** * Finds the notifications of id and user given. * * @param string $notificationId The notification id * @param \Kreta\Component\User\Model\Interfaces\UserInterface $user The user * * @return \Kreta\Component\Notification\Model\Interfaces\NotificationInterface * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function findOneByUser($notificationId, UserInterface $user) { $notification = $this->find($notificationId, false); if ($notification->getUser()->getId() !== $user->getId()) { throw new AccessDeniedException(); } return $notification; }
/** * {@inheritdoc} */ public function getUserRole(UserInterface $user) { foreach ($this->participants as $participant) { if ($participant->getUser()->getId() === $user->getId()) { return $participant->getRole(); } } return null; }