Merge remote-tracking branch 'origin/dune-risky' into dune-risky

This commit is contained in:
Julien Fastré 2021-07-13 16:59:38 +02:00
commit 915a2e7284
2 changed files with 4 additions and 82 deletions

View File

@ -96,29 +96,6 @@ final class ActivityACLAwareRepository
$where = ''; $where = '';
$parameters = []; $parameters = [];
// condition will be:
// FROM activity JOIN person -- not set by us
// ON activity.person_id = person.id -- not set by us
// WHERE -- not set by us
// activity.person_id = ? AND -- only if $context = person
// ( -- begin loop through centers, center#0
// person.center_id = ?
// AND ( -- begin loop for scopes within centers
// activity.scope_id = ? -- scope#0
// OR -- if scope#i where i > 0
// activity.scope_id = ? -- scope#1
// )
// )
// OR -- if center#i where i > 0
// ( -- begin loop through centers, center#1
// person.center_id = ?
// AND ( -- begin loop for scopes within centers
// activity.scope_id = ? -- scope#0
// OR -- if scope#i where i > 0
// activity.scope_id = ? -- scope#1
// )
// )
$metadataActivity = $this->em->getClassMetadata(Activity::class); $metadataActivity = $this->em->getClassMetadata(Activity::class);
$metadataPerson = $this->em->getClassMetadata(Person::class); $metadataPerson = $this->em->getClassMetadata(Person::class);
$activityToPerson = $metadataActivity->getAssociationMapping('person')['joinColumns'][0]['name']; $activityToPerson = $metadataActivity->getAssociationMapping('person')['joinColumns'][0]['name'];
@ -190,58 +167,3 @@ final class ActivityACLAwareRepository
} }
} }
/*
$qb = $this->repository->createQueryBuilder('a');
$qb->select(['a.id', "'activity'", 'a.date']);
$qb->join('a.person', 'p');
switch($context) {
case 'center':
$qb->where($this->queryTimelineIndexerWhereForCenter($qb, $args['centers']));
break;
default:
throw new \LogicException('context not supported');
}
if ($from) {
$qb->andWhere($qb->gt('a.date', ':from'));
$qb->setParameter('from', $from);
}
if ($to) {
$qb->andWhere($qb->gt('a.date', ':to'));
$qb->setParameter('to', $to);
}
return $qb->getQuery();
}
private function queryTimelineIndexerWhereForCenter(QueryBuilder $qb, array $centers): Orx
{
$i = 0;
$orx = $qb->expr()->orX();
foreach ($centers as $center) {
$andx = $qb->expr()->andX();
$andx->add($qb->expr()->eq('p.center', ":center_$i"));
$qb->setParameter("center_$i", $center);
$i++;
$scopes = $this->authorizationHelper->getReachableCircles(
$this->tokenStorage->getToken()->getUser(),
new Role(ActivityVoter::SEE_DETAILS),
$center,
);
foreach ($scopes as $scope) {
$andx->add($qb->expr()->eq('a.scope', ":scope_$i"));
$qb->setParameter("scope_$i", $scope);
$i++;
}
$orx->add($andx);
}
return $orx;
}
} */

View File

@ -117,7 +117,7 @@ class TimelineActivityProvider implements TimelineProviderInterface
private function getWhereClauseForPerson(Person $person) private function getWhereClauseForPerson(Person $person)
{ {
$parameters = []; $parameters = [];
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity'); $metadataActivity = $this->em->getClassMetadata(Activity::class);
$associationMapping = $metadataActivity->getAssociationMapping('person'); $associationMapping = $metadataActivity->getAssociationMapping('person');
$role = new Role('CHILL_ACTIVITY_SEE'); $role = new Role('CHILL_ACTIVITY_SEE');
$reachableScopes = $this->helper->getReachableScopes($this->user, $reachableScopes = $this->helper->getReachableScopes($this->user,
@ -154,8 +154,8 @@ class TimelineActivityProvider implements TimelineProviderInterface
private function getFromClausePerson() private function getFromClausePerson()
{ {
$metadataActivity = $this->em->getClassMetadata('ChillActivityBundle:Activity'); $metadataActivity = $this->em->getClassMetadata(Activity::class);
$metadataPerson = $this->em->getClassMetadata('ChillPersonBundle:Person'); $metadataPerson = $this->em->getClassMetadata(Person::class);
$associationMapping = $metadataActivity->getAssociationMapping('person'); $associationMapping = $metadataActivity->getAssociationMapping('person');
return $metadataActivity->getTableName().' JOIN ' return $metadataActivity->getTableName().' JOIN '
@ -173,7 +173,7 @@ class TimelineActivityProvider implements TimelineProviderInterface
*/ */
public function getEntities(array $ids) public function getEntities(array $ids)
{ {
$activities = $this->em->getRepository('ChillActivityBundle:Activity') $activities = $this->em->getRepository(Activity::class)
->findBy(array('id' => $ids)); ->findBy(array('id' => $ids));
$result = array(); $result = array();