public function testAccountUserView()
 {
     $this->client->request('GET', $this->getUrl('orob2b_account_account_user_view', ['id' => $this->accountUser->getId()]));
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $content = $result->getContent();
     $this->assertContains('Address Book', $content);
 }
 public function testUpdateFromPredefined()
 {
     //TODO: see BB-1134
     $this->markTestSkipped('Must be fixed in scope with BB-1134');
     $currentUserRoles = $this->currentUser->getRoles();
     $oldRoleId = $this->predefinedRole->getId();
     $crawler = $this->client->request('GET', $this->getUrl('orob2b_account_frontend_account_user_role_update', ['id' => $oldRoleId]));
     $form = $crawler->selectButton('Save and Close')->form();
     $token = $this->getContainer()->get('security.csrf.token_manager')->getToken('orob2b_account_frontend_account_user_role')->getValue();
     $this->client->followRedirects(true);
     $crawler = $this->client->request($form->getMethod(), $form->getUri(), ['input_action' => '', 'orob2b_account_frontend_account_user_role' => ['_token' => $token, 'label' => self::CUSTOMIZED_ROLE, 'appendUsers' => $this->currentUser->getId()]]);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $content = $crawler->html();
     $this->assertContains('Account User Role has been saved', $content);
     // Find id of new role
     $response = $this->requestFrontendGrid('frontend-account-account-user-roles-grid', ['frontend-account-account-user-roles-grid[_filter][label][value]' => self::CUSTOMIZED_ROLE]);
     $result = $this->getJsonResponseContent($response, 200);
     $result = reset($result['data']);
     $newRoleId = $result['id'];
     $this->assertNotEquals($newRoleId, $oldRoleId);
     /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUserRole $role */
     $role = $this->getUserRoleRepository()->find($newRoleId);
     $this->assertNotNull($role);
     $this->assertEquals(self::CUSTOMIZED_ROLE, $role->getLabel());
     $this->assertNotEmpty($role->getRole());
     /** @var \OroB2B\Bundle\AccountBundle\Entity\AccountUser $user */
     $user = $this->getCurrentUser();
     // Add new role
     $this->assertCount(count($currentUserRoles) + 1, $user->getRoles());
     $this->assertEquals($user->getRole($role->getRole()), $role);
 }
 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 if ($this->form->get('passwordGenerate')->getData()) {
                     $generatedPassword = $this->userManager->generatePassword(10);
                     $accountUser->setPlainPassword($generatedPassword);
                 }
                 if ($this->form->get('sendEmail')->getData()) {
                     $this->userManager->sendWelcomeEmail($accountUser);
                 }
             }
             $token = $this->securityFacade->getToken();
             if ($token instanceof OrganizationContextTokenInterface) {
                 $organization = $token->getOrganizationContext();
                 $accountUser->setOrganization($organization)->addOrganization($organization);
             }
             $this->userManager->updateUser($accountUser);
             return true;
         }
     }
     return false;
 }
 /**
  * @Route(
  *      "/disable/{id}",
  *      name="orob2b_account_frontend_account_user_disable",
  *      requirements={"id"="\d+"}
  * )
  * @AclAncestor("orob2b_account_frontend_account_user_update")
  *
  * {@inheritdoc}
  */
 public function disableAction(AccountUser $accountUser)
 {
     /** @var $user AccountUser */
     $user = $this->getUser();
     if ($user->getId() == $accountUser->getId()) {
         throw new ForbiddenException('self disable');
     }
     return parent::disableAction($accountUser);
 }
 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 $this->userManager->register($accountUser);
             }
             $this->userManager->updateUser($accountUser);
             $this->userManager->reloadUser($accountUser);
             return true;
         }
     }
     return false;
 }
 /**
  * @param AccountUser $user
  * @param AccountOwnerAwareInterface $object
  * @return bool
  */
 protected function isSameUser(AccountUser $user, AccountOwnerAwareInterface $object)
 {
     return $object->getAccountUser() && $user->getId() === $object->getAccountUser()->getId();
 }
 /**
  * @param AccountUser $entity
  * @return array
  */
 protected function getAddressBookOptions($entity)
 {
     $addressListUrl = $this->generateUrl('orob2b_api_account_get_accountuser_addresses', ['entityId' => $entity->getId()]);
     $addressCreateUrl = $this->generateUrl('orob2b_account_account_user_address_create', ['entityId' => $entity->getId()]);
     $currentAddresses = $this->get('fragment.handler')->render($addressListUrl);
     return ['wid' => $this->getRequest()->get('_wid'), 'entityId' => $entity->getId(), 'addressListUrl' => $addressListUrl, 'addressCreateUrl' => $addressCreateUrl, 'addressUpdateRouteName' => 'orob2b_account_account_user_address_update', 'currentAddresses' => $currentAddresses];
 }