added team permissions for activities (#1872)

This commit is contained in:
Kevin Papst
2020-08-08 18:50:04 +02:00
committed by GitHub
parent dc162bf385
commit 0914ebf737
84 changed files with 4300 additions and 3279 deletions

View File

@@ -130,18 +130,26 @@ class ActivityRepository extends EntityRepository
$teams = array_merge($teams, $user->getTeams()->toArray());
}
$qb->leftJoin('p.teams', 'teams')
$qb->leftJoin('a.teams', 'teams')
->leftJoin('p.teams', 'p_teams')
->leftJoin('c.teams', 'c_teams');
if (empty($teams)) {
$qb->andWhere($qb->expr()->isNull('c_teams'));
$qb->andWhere($qb->expr()->isNull('teams'));
$qb->andWhere($qb->expr()->isNull('p_teams'));
$qb->andWhere($qb->expr()->isNull('c_teams'));
return;
}
$orProject = $qb->expr()->orX(
$orActivity = $qb->expr()->orX(
$qb->expr()->isNull('teams'),
$qb->expr()->isMemberOf(':teams', 'a.teams')
);
$qb->andWhere($orActivity);
$orProject = $qb->expr()->orX(
$qb->expr()->isNull('p_teams'),
$qb->expr()->isMemberOf(':teams', 'p.teams')
);
$qb->andWhere($orProject);
@@ -253,6 +261,7 @@ class ActivityRepository extends EntityRepository
$qb
->select('a')
->distinct()
->from(Activity::class, 'a')
->leftJoin('a.project', 'p')
->leftJoin('p.customer', 'c')
@@ -320,7 +329,7 @@ class ActivityRepository extends EntityRepository
$qb->andWhere($where);
}
$this->addPermissionCriteria($qb, $query->getCurrentUser());
$this->addPermissionCriteria($qb, $query->getCurrentUser(), $query->getTeams());
if ($query->hasSearchTerm()) {
$searchAnd = $qb->expr()->andX();
@@ -353,13 +362,6 @@ class ActivityRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// $qb->addGroupBy('a.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -214,6 +214,7 @@ class CustomerRepository extends EntityRepository
$qb
->select('c')
->distinct()
->from(Customer::class, 'c')
;
@@ -268,13 +269,6 @@ class CustomerRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// $qb->addGroupBy('c.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -137,6 +137,7 @@ class InvoiceRepository extends EntityRepository
$qb
->select('i')
->distinct()
->from(Invoice::class, 'i')
;
@@ -151,13 +152,6 @@ class InvoiceRepository extends EntityRepository
$this->addPermissionCriteria($qb, $query->getCurrentUser());
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// $qb->addGroupBy('i.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
// $qb->addGroupBy($orderBy);
return $qb;
}

View File

@@ -93,6 +93,15 @@ final class ActivityIdLoader implements LoaderInterface
->andWhere($qb->expr()->in('a.id', $ids))
->getQuery()
->execute();
$qb = $em->createQueryBuilder();
$qb->select('PARTIAL a.{id}', 'teams', 'teamlead')
->from(Activity::class, 'a')
->leftJoin('a.teams', 'teams')
->leftJoin('teams.teamlead', 'teamlead')
->andWhere($qb->expr()->in('a.id', $ids))
->getQuery()
->execute();
}
}
}

View File

@@ -255,6 +255,7 @@ class ProjectRepository extends EntityRepository
$qb
->select('p')
->distinct()
->from(Project::class, 'p')
->leftJoin('p.customer', 'c')
;
@@ -366,13 +367,6 @@ class ProjectRepository extends EntityRepository
}
}
// this will make sure, that we do not accidentally create results with multiple rows
// => which would result in a wrong LIMIT / pagination results
// $qb->addGroupBy('p.id');
// the second group by is needed due to SQL standard (even though logically not really required for this query)
// $qb->addGroupBy($orderBy);
return $qb;
}