Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from SURFnet/54-ignore-existing-group-membership
Browse files Browse the repository at this point in the history
54 - Improve searching
  • Loading branch information
lucasvanlierop authored Nov 22, 2016
2 parents 6870986 + b88b711 commit afc64dd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/vendor/
/bin/
/composer.phar
/log/capistrano.log
app/config/parameters.yml
.vagrant
.idea
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion app/config/deployment/deploy.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
12 changes: 12 additions & 0 deletions src/AppBundle/Manager/MembershipManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
15 changes: 14 additions & 1 deletion src/AppBundle/Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,8 @@ public function findUser($id)
* @param string $loginName
*
* @return User|User[]
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function findUsers(
$query = null,
Expand All @@ -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');
Expand All @@ -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)
)
)
);

Expand Down

0 comments on commit afc64dd

Please sign in to comment.