From af93e3c6feb98bb6beabf258ba6d778208965766 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 28 Oct 2019 17:24:21 +0100 Subject: Sites: fix permissions for collaborators --- archaeological_operations/models.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'archaeological_operations') diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index c295e40ac..900779643 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -398,6 +398,22 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem, return Find.objects.filter( base_finds__context_record__archaeological_site__pk=self.pk) + @classmethod + def _get_query_owns_dicts(cls, ishtaruser, no_rel=False): + profile = ishtaruser.current_profile + town_ids = [] + if profile: + town_ids = [town['pk'] + for town in profile.query_towns.values('pk').all()] + query_owns = [ + { + 'collaborators__pk': ishtaruser.person.pk, + 'history_creator': ishtaruser.user_ptr, + 'towns__pk__in': town_ids, + } + ] + return query_owns + @classmethod def get_query_owns(cls, ishtaruser): from archaeological_warehouse.models import Warehouse @@ -421,9 +437,9 @@ class ArchaeologicalSite(DocumentItem, BaseHistorizedItem, QRCodeItem, no_rel=True) ) | cls._construct_query_own( 'top_operations__', Operation._get_query_owns_dicts(ishtaruser) - ) | cls._construct_query_own('', [ - {'history_creator': ishtaruser.user_ptr} - ]) + ) | cls._construct_query_own( + '', cls._get_query_owns_dicts(ishtaruser) + ) return q @classmethod -- cgit v1.2.3