diff --git a/.gitignore b/.gitignore index 7ff52f6..d470ccd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /vendor/ /bin/ /composer.phar +/log/capistrano.log app/config/parameters.yml .vagrant .idea diff --git a/README.md b/README.md index 781a4de..028a57b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,17 @@ Also make sure there is a directory `/project/dir/` available which is writable If you want to deploy the app you will need capistrano-symfony: -`gem install capistrano-symfony --pre-release` +``` +gem install airbrussh +gem install capistrano +gem install capistrano-composer +gem install capistrano-harrow +gem install capistrano-symfony +gem install i18n +gem install net-scp +gem install net-ssh +gem install sshkit +``` ### Vhost diff --git a/Vagrantfile b/Vagrantfile index 3c0752a..432ca83 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -61,4 +61,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision :shell, path: "provision/windows.sh" end + config.ssh.forward_agent = true + end diff --git a/app/config/deployment/deploy.rb b/app/config/deployment/deploy.rb index 9d09ce3..c44fdab 100644 --- a/app/config/deployment/deploy.rb +++ b/app/config/deployment/deploy.rb @@ -1,5 +1,4 @@ # config valid only for current version of Capistrano -lock '3.4.0' set :application, 'grouphub.api' set :repo_url, 'git@github.com:SURFnet/grouphub.api.git' diff --git a/src/AppBundle/Manager/MembershipManager.php b/src/AppBundle/Manager/MembershipManager.php index 0fa2005..31128d5 100644 --- a/src/AppBundle/Manager/MembershipManager.php +++ b/src/AppBundle/Manager/MembershipManager.php @@ -2,9 +2,11 @@ namespace AppBundle\Manager; +use AppBundle\Entity\User; use AppBundle\Entity\UserInGroup; use AppBundle\Event\GroupEvent; use Doctrine\Bundle\DoctrineBundle\Registry; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Tools\Pagination\Paginator; @@ -132,7 +134,17 @@ public function findMemberships( */ public function addMembership(UserInGroup $userInGroup, $message) { + /** @var EntityManager $manager */ $manager = $this->doctrine->getManager(); + $existingUser = $manager->getRepository(UserInGroup::class)->findOneBy([ + 'user' => $userInGroup->getUser(), + 'group' => $userInGroup->getGroup() + ]); + + if ($existingUser instanceof UserInGroup) { + return; + } + $manager->persist($userInGroup); $manager->flush(); diff --git a/src/AppBundle/Manager/UserManager.php b/src/AppBundle/Manager/UserManager.php index 540d82d..8bc8d3b 100644 --- a/src/AppBundle/Manager/UserManager.php +++ b/src/AppBundle/Manager/UserManager.php @@ -3,6 +3,7 @@ namespace AppBundle\Manager; use AppBundle\Entity\User; +use AppBundle\Entity\UserAnnotation; use AppBundle\Event\UserEvent; use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\ORM\Query\Expr; @@ -54,6 +55,8 @@ public function findUser($id) * @param string $loginName * * @return User|User[] + * + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function findUsers( $query = null, @@ -66,6 +69,8 @@ public function findUsers( /** @var QueryBuilder $qb */ $qb = $this->doctrine->getRepository('AppBundle:User')->createQueryBuilder('u'); + $qb->leftJoin(UserAnnotation::class, 'a', Expr\Join::LEFT_JOIN, 'a.user = u.id'); + if ($sort === 'name') { $sort = new Expr\OrderBy('u.lastName'); $sort->add('u.firstName'); @@ -86,12 +91,20 @@ public function findUsers( if (!empty($query)) { $terms = explode(' ', $query); + if (!empty($terms)) { + $qb->setParameter('annotation_type_email', 'email'); + } + foreach ($terms as $i => $term) { $qb->andWhere( $qb->expr()->orX( $qb->expr()->like('u.firstName', ':term' . $i), $qb->expr()->like('u.lastName', ':term' . $i), - $qb->expr()->like('u.loginName', ':term' . $i) + $qb->expr()->like('u.loginName', ':term' . $i), + $qb->expr()->andX( + $qb->expr()->like('a.attribute', ':annotation_type_email'), + $qb->expr()->like('a.value', ':term' . $i) + ) ) );