From 7afcbc6e7a64364dd2a8164974e23c6e405a0165 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 7 Feb 2025 18:21:00 +0100 Subject: ✨ Manage "{AREA}" keyword in permission queries (refs #6125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 4fb7711d3..0690693f5 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -3703,15 +3703,25 @@ class UserProfile(models.Model): if query: if "{USER}" in query: query = query.replace("{USER}", f"id:{ishtar_user.person_id}") + if "{AREA}" in query: + area_names = [] + for profile in ishtar_user.person.profiles.all(): + area_names += profile.areas.values_list("label", flat=True) + area_names = list(set(area_names)) + query = query.replace( + "{AREA}", ";".join(f'"{name}"'for name in area_names) + ) query = {"search_vector": query} q = _get_item(None, return_query=True, ishtaruser=ishtar_user, query=query) result = list(q.values_list("pk", flat=True)) if permission_query.limit_to_attached_areas: - profile = ishtar_user.current_profile - if not profile: # no areas attached - return [] - town_ids = list(profile.query_towns.values_list("pk", flat=True)) + town_ids = [] + for profile in ishtar_user.person.profiles.all(): + town_ids += list(profile.query_towns.values_list("pk", flat=True)) + if not town_ids: + return + town_ids = list(set(town_ids)) result_limit = [] get_limit_to_area_query = getattr( model_class, "get_limit_to_area_query", None -- cgit v1.2.3