/**
  * Find mass leave requests assigned to gm
  *
  * @param User $generalManager
  * @param array $paginationParameters
  * @param array $parameters
  * @return Paginator
  */
 public function findMassLeaveRequests(User $generalManager, array $paginationParameters, array $parameters)
 {
     $dq = $this->createQueryBuilder('lr');
     $dq->select('lr')->where($dq->expr()->eq('lr.generalManager', '(:generalManager)'))->andWhere($dq->expr()->isNotNull('lr.leaveRequestGroup'))->andWhere($dq->expr()->eq('lr.generalManager', $generalManager->getId()))->setParameter('generalManager', $generalManager->getId());
     $dq = $this->findByParams($parameters, $dq);
     $dq->setFirstResult($paginationParameters['firstResult']);
     $dq->setMaxResults($paginationParameters['maxResults']);
     return new Paginator($dq->getQuery(), true);
 }
 /**
  * test findUserByEmployeeNameUsingLike method
  */
 public function testDeleteUsersByIds()
 {
     $newEmployee = new Employee();
     $newEmployee->setDateOfBirth(new \DateTime('1990-02-01'));
     $newEmployee->setJoiningDate(new \DateTime('2009-03-01'));
     $newEmployee->setNumberOfChildren(0);
     $newEmployee->setEmployeeName('employee');
     $newEmployee->setWorkingHours(8);
     $newEmployee->setBankAccountNumber('00000000-11468115');
     $newEmployee->setBankName('OTP');
     // Create a new user.
     $newUser = new User();
     $newUser->setUsername('test1');
     $newUser->setEmail('*****@*****.**');
     $newUser->setEmployee($newEmployee);
     $newUser->setSalt('');
     $newUser->setPassword('test1');
     $newUser->setIsActive(1);
     $newUser->setLdapEnabled(0);
     $newUser->setIsFirstLogin(0);
     // Save the new user into the local test database.
     $this->em->persist($newUser);
     $this->em->flush();
     // Get the saved user.
     $testUser = $this->em->getRepository("OpitOpitHrmUserBundle:User")->findOneByUsername('test1');
     $user = $this->em->getRepository("OpitOpitHrmUserBundle:User")->deleteUsersByIds($testUser->getId());
     $this->assertNotNull($user, 'testDeleteUsersByIds: The given result is null.');
 }
 /**
  * test findUserGroupsArray method
  */
 public function testFindUserGroupsArray()
 {
     $userGroups = $this->em->getRepository("OpitOpitHrmUserBundle:Groups")->findUserGroupsArray($this->user->getId());
     $this->assertNotNull($userGroups, 'testFindUserGroupsArray: The given result is null.');
 }
 /**
  * @internal
  */
 public function setEditRights(User $user, TravelRequest $travelRequest, $isNewTravelRequest, $currentStatusId)
 {
     $isEditLocked = true;
     $isStatusLocked = false;
     $userId = $user->getId();
     if (false === $isNewTravelRequest) {
         // the currently logged in user is always set as default
         $isStatusLocked = true;
         $isEditLocked = false;
     } else {
         if ($this->securityContext->isGranted('ROLE_ADMIN')) {
             $isEditLocked = false;
             $isStatusLocked = false;
             if (in_array($currentStatusId, array(Status::APPROVED, Status::REJECTED))) {
                 $isEditLocked = true;
                 $isStatusLocked = true;
             } elseif ($currentStatusId === Status::FOR_APPROVAL) {
                 $isEditLocked = true;
             }
         } elseif ($userId === $travelRequest->getUser()->getId()) {
             if (Status::CREATED !== $currentStatusId && Status::REVISE !== $currentStatusId) {
                 return false;
             }
             $isEditLocked = false;
         } elseif ($userId === $travelRequest->getGeneralManager()->getId()) {
             if (Status::FOR_APPROVAL !== $currentStatusId) {
                 return false;
             }
         }
     }
     return array('isEditLocked' => $isEditLocked, 'isStatusLocked' => $isStatusLocked);
 }
 /**
  * testing the resetPassword action.
  *
  * This should be the last method, because this is reset the password for the admin.
  */
 public function testResetPasswordAction()
 {
     $crawler = $this->client->request('POST', '/secured/user/password/reset', array('id' => $this->user->getId()));
     $this->assertJson($this->client->getResponse()->getContent(), 'testResetPasswordAction: The response\'s content is not a JSON object.');
     $this->assertTrue($this->client->getResponse()->headers->contains('Content-Type', 'application/json'), 'testResetPasswordAction: The content-type is not a json.');
 }
Exemple #6
0
 /**
  * {@inheritDoc}
  */
 public function doLoad(ObjectManager $manager)
 {
     $factory = $this->container->get('security.encoder_factory');
     $aclManager = $this->container->get('opit.security.acl.manager');
     $users = array();
     $managers = array();
     $user = new User();
     $encoder = $factory->getEncoder($user);
     $testAdmin = new User();
     $testAdmin->setUsername('admin');
     $testAdmin->setEmployee($this->createEmployee());
     $password = $encoder->encodePassword('admin', '');
     $testAdmin->setPassword($password);
     $testAdmin->setEmail('*****@*****.**');
     $testAdmin->setIsActive(1);
     if ('test' === $this->getCurrentEnvironment()) {
         $testAdmin->setIsFirstLogin(0);
     } else {
         $testAdmin->setIsFirstLogin(1);
     }
     $testAdmin->setLdapEnabled(0);
     $testAdmin->addGroup($this->getReference('admin-group'));
     $manager->persist($testAdmin);
     $testSystemAdmin = new User();
     $testSystemAdmin->setUsername('systemadmin');
     $testSystemAdmin->setEmployee($this->createEmployee());
     $password = $encoder->encodePassword('systemadmin', '');
     $testSystemAdmin->setPassword($password);
     $testSystemAdmin->setEmail('*****@*****.**');
     $testSystemAdmin->setIsActive(1);
     if ('test' === $this->getCurrentEnvironment()) {
         $testSystemAdmin->setIsFirstLogin(0);
     } else {
         $testSystemAdmin->setIsFirstLogin(1);
     }
     $testSystemAdmin->setLdapEnabled(0);
     $testSystemAdmin->addGroup($this->getReference('system-admin-group'));
     $manager->persist($testSystemAdmin);
     if (in_array($this->getCurrentEnvironment(), array('dev', 'test'))) {
         for ($i = 0; $i < 10; $i++) {
             $testEmployee = $this->createEmployee();
             $username = substr($testEmployee->getEmployeeName(), strpos($testEmployee->getEmployeeName(), ' ') + 1);
             $testUser = new User();
             $testUser->setUsername(strtolower($username));
             $testUser->setEmployee($testEmployee);
             $password = $encoder->encodePassword(strtolower($username), '');
             $testUser->setPassword($password);
             $testUser->setLdapEnabled(0);
             $testUser->setEmail(strtolower($username) . '@mail.local');
             $testUser->setIsActive(1);
             $testUser->setIsFirstLogin(1);
             $testUser->addGroup($this->getReference('user-group'));
             $users[] = $testUser;
             $manager->persist($testUser);
         }
         $this->addReference('testUser-user', $testUser);
         $testTeamManager = new User();
         $testTeamManager->setUsername('teamManager');
         $testTeamManager->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('teamManager', '');
         $testTeamManager->setPassword($password);
         $testTeamManager->setEmail('*****@*****.**');
         $testTeamManager->setIsActive(1);
         $testTeamManager->setIsFirstLogin(1);
         $testTeamManager->addGroup($this->getReference('team-manager-group'));
         $testTeamManager->addGroup($this->getReference('user-group'));
         $testTeamManager->setLdapEnabled(0);
         $managers[] = $testTeamManager;
         $manager->persist($testTeamManager);
         $testGeneralManager = new User();
         $testGeneralManager->setUsername('generalManager');
         $testGeneralManager->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('generalManager', '');
         $testGeneralManager->setPassword($password);
         $testGeneralManager->setEmail('*****@*****.**');
         $testGeneralManager->setIsActive(1);
         $testGeneralManager->setIsFirstLogin(1);
         $testGeneralManager->addGroup($this->getReference('general-manager-group'));
         $testGeneralManager->addGroup($this->getReference('user-group'));
         $testGeneralManager->setLdapEnabled(0);
         $managers[] = $testGeneralManager;
         $manager->persist($testGeneralManager);
         $user = new User();
         $user->setUsername('user');
         $user->setEmployee($this->createEmployee());
         $password = $encoder->encodePassword('user', '');
         $user->setPassword($password);
         $user->setEmail('*****@*****.**');
         $user->setIsActive(1);
         $user->setIsFirstLogin(1);
         $user->addGroup($this->getReference('user-group'));
         $user->setLdapEnabled(0);
         $users[] = $user;
         $manager->persist($user);
         $this->addReference('admin', $testAdmin);
         $this->addReference('user', $user);
         $this->addReference('generalManager', $testGeneralManager);
     }
     $manager->flush();
     $aclManager->grant($testSystemAdmin, $this->getReference('system-admin-group'));
     $aclManager->grant($testAdmin, $this->getReference('admin-group'));
     foreach ($users as $user) {
         $aclManager->grant($user, $this->getReference('system-admin-group'));
     }
     foreach ($managers as $manager) {
         $aclManager->grant($manager, $this->getReference('admin-group'));
     }
 }