diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-07 18:21:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-19 14:45:57 +0100 |
commit | 7afcbc6e7a64364dd2a8164974e23c6e405a0165 (patch) | |
tree | e7cdbb227c11e1ab33ac316a7146ebe222783a13 /ishtar_common/models.py | |
parent | 04e9ebf7075eed34b2ea0bb22206780b6ee45a65 (diff) | |
download | Ishtar-7afcbc6e7a64364dd2a8164974e23c6e405a0165.tar.bz2 Ishtar-7afcbc6e7a64364dd2a8164974e23c6e405a0165.zip |
✨ Manage "{AREA}" keyword in permission queries (refs #6125)
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 18 |
1 files changed, 14 insertions, 4 deletions
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 |