Skip to content

Commit

Permalink
fix(api): filter with areas zones (COM/DEP...)
Browse files Browse the repository at this point in the history
Use ST_Intersects when the provided geom_model is different from the
actual model of the query. It enables to intersect the geometry rather
than using cor_area_synthese table that could give sensitive info to the
user
  • Loading branch information
Maxime Vergez committed Nov 6, 2023
1 parent 760d43b commit 02a13b3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions backend/geonature/core/gn_synthese/utils/query_select_sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,17 @@ def filter_other_filters(self, user):
# generic filters
for colname, value in self.filters.items():
if colname.startswith("area"):
cor_area_synthese_alias = aliased(CorAreaSynthese)
self.add_join(
cor_area_synthese_alias,
cor_area_synthese_alias.id_synthese,
self.model.id_synthese,
)
self.query = self.query.where(cor_area_synthese_alias.id_area.in_(value))
if self.geom_column.class_ != self.model:
l_areas_cte = LAreas.query.filter(LAreas.id_area.in_(value)).cte("area_filter")
self.query = self.query.where(func.ST_Intersects(self.geom_column, l_areas_cte.c.geom))
else:
cor_area_synthese_alias = aliased(CorAreaSynthese)
self.add_join(
cor_area_synthese_alias,
cor_area_synthese_alias.id_synthese,
self.model.id_synthese,
)
self.query = self.query.where(cor_area_synthese_alias.id_area.in_(value))
elif colname.startswith("id_"):
col = getattr(self.model.__table__.columns, colname)
if isinstance(value, list):
Expand Down

0 comments on commit 02a13b3

Please sign in to comment.