From 23d014321570a4de21889db4735cff47fb6400e4 Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Tue, 8 Aug 2023 15:29:16 +0200 Subject: [PATCH 1/4] get_organization_members now making a QuerySet Union over owner as Person and OrganizationMember as member --- docker-app/qfieldcloud/core/querysets_utils.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/docker-app/qfieldcloud/core/querysets_utils.py b/docker-app/qfieldcloud/core/querysets_utils.py index 80567e388..a163d6220 100644 --- a/docker-app/qfieldcloud/core/querysets_utils.py +++ b/docker-app/qfieldcloud/core/querysets_utils.py @@ -1,13 +1,14 @@ from functools import reduce from operator import and_, or_ -from django.db.models import Q, QuerySet +from django.db.models import Q, QuerySet, F from django.db.models import Value as V from django.db.models.functions import StrIndex from qfieldcloud.core.models import ( Delta, Organization, OrganizationMember, + Person, Project, ProjectCollaborator, Team, @@ -25,7 +26,19 @@ def get_team_members(team): def get_organization_members(organization): - return OrganizationMember.objects.filter(organization=organization) + return ( + Person.objects.filter(organizationmember__organization=organization) + .annotate( + role=F("organizationmember__role"), + # organization=F("organizationmember__organization"), + ) + .union( + Person.objects.filter(pk=organization.organization_owner.id).annotate( + role=V("owner"), + # organization=V(organization), + ) + ) + ) def get_project_deltas(project): From 9f8fc9966ab3ce6cd653a984a1c808be665be2dc Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Tue, 8 Aug 2023 16:09:04 +0200 Subject: [PATCH 2/4] format --- docker-app/qfieldcloud/core/querysets_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-app/qfieldcloud/core/querysets_utils.py b/docker-app/qfieldcloud/core/querysets_utils.py index a163d6220..9b16dcc8f 100644 --- a/docker-app/qfieldcloud/core/querysets_utils.py +++ b/docker-app/qfieldcloud/core/querysets_utils.py @@ -1,7 +1,7 @@ from functools import reduce from operator import and_, or_ -from django.db.models import Q, QuerySet, F +from django.db.models import F, Q, QuerySet from django.db.models import Value as V from django.db.models.functions import StrIndex from qfieldcloud.core.models import ( From cad7e1f0114aa473414b393827918e17a86aca4d Mon Sep 17 00:00:00 2001 From: why-not-try-calmer Date: Thu, 10 Aug 2023 13:24:34 +0200 Subject: [PATCH 3/4] removed commented code --- .../qfieldcloud/core/querysets_utils.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/docker-app/qfieldcloud/core/querysets_utils.py b/docker-app/qfieldcloud/core/querysets_utils.py index 9b16dcc8f..e607adcd4 100644 --- a/docker-app/qfieldcloud/core/querysets_utils.py +++ b/docker-app/qfieldcloud/core/querysets_utils.py @@ -25,20 +25,14 @@ def get_team_members(team): return TeamMember.objects.filter(team=team) -def get_organization_members(organization): - return ( - Person.objects.filter(organizationmember__organization=organization) - .annotate( - role=F("organizationmember__role"), - # organization=F("organizationmember__organization"), - ) - .union( - Person.objects.filter(pk=organization.organization_owner.id).annotate( - role=V("owner"), - # organization=V(organization), - ) - ) +def get_organization_members(organization) -> QuerySet[Person]: + non_owning_members = Person.objects.filter( + organizationmember__organization=organization + ).annotate(role=F("organizationmember__role")) + owner = Person.objects.filter(pk=organization.organization_owner.id).annotate( + role=V("owner") ) + return non_owning_members.union(owner) def get_project_deltas(project): From 861e308774ebc1452730101a228459e415defb12 Mon Sep 17 00:00:00 2001 From: Adrien Date: Fri, 11 Aug 2023 15:33:51 +0200 Subject: [PATCH 4/4] Update docker-app/qfieldcloud/core/querysets_utils.py Co-authored-by: Ivan Ivanov --- docker-app/qfieldcloud/core/querysets_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-app/qfieldcloud/core/querysets_utils.py b/docker-app/qfieldcloud/core/querysets_utils.py index e607adcd4..c28ee171c 100644 --- a/docker-app/qfieldcloud/core/querysets_utils.py +++ b/docker-app/qfieldcloud/core/querysets_utils.py @@ -26,13 +26,13 @@ def get_team_members(team): def get_organization_members(organization) -> QuerySet[Person]: - non_owning_members = Person.objects.filter( + org_members = Person.objects.filter( organizationmember__organization=organization ).annotate(role=F("organizationmember__role")) owner = Person.objects.filter(pk=organization.organization_owner.id).annotate( role=V("owner") ) - return non_owning_members.union(owner) + return org_members.union(owner) def get_project_deltas(project):