/**
  * Manages the part of action when the form is valid.
  *
  * @param \Symfony\Component\HttpFoundation\Request            $request The request
  * @param \Symfony\Component\Form\FormInterface                $form    The form
  * @param \Kreta\Component\User\Model\Interfaces\UserInterface $user    The user
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 private function manageValidForm(Request $request, FormInterface $form, UserInterface $user)
 {
     $user->setEnabled(true);
     $user->setConfirmationToken(null);
     $dispatcher = $this->get('event_dispatcher');
     $event = new FilterUserResponseEvent($user, $request, new Response());
     $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, new FormEvent($form, $request));
     $this->get('fos_user.user_manager')->updateUser($user);
     $dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, $event);
     if (!$this->getUser() instanceof UserInterface) {
         throw new AccessDeniedException('This user does not have access to this section.');
     }
     $dispatcher->dispatch(AuthorizationEvent::NAME, new AuthorizationEvent($request));
     return $this->redirect($this->generateUrl('kreta_web_homepage'));
 }
 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]);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function isParticipant(UserInterface $user)
 {
     foreach ($this->project->getParticipants() as $participant) {
         if ($user->getId() === $participant->getUser()->getId()) {
             return true;
         }
     }
     return false;
 }
Example #4
0
 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);
 }
Example #5
0
 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;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function getUserRole(UserInterface $user)
 {
     foreach ($this->participants as $participant) {
         if ($participant->getUser()->getId() === $user->getId()) {
             return $participant->getRole();
         }
     }
     return null;
 }