Skip to content

Commit

Permalink
Inconsistent organization member lists, return Person instead of `O…
Browse files Browse the repository at this point in the history
…rganizationMember` (#764)

Co-authored-by: Ivan Ivanov <[email protected]>
  • Loading branch information
why-not-try-calmer and suricactus authored Aug 15, 2023
1 parent 012c08a commit fe8338a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docker-app/qfieldcloud/core/querysets_utils.py
Original file line number Diff line number Diff line change
@@ -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 F, Q, QuerySet
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,
Expand All @@ -24,8 +25,14 @@ def get_team_members(team):
return TeamMember.objects.filter(team=team)


def get_organization_members(organization):
return OrganizationMember.objects.filter(organization=organization)
def get_organization_members(organization) -> QuerySet[Person]:
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 org_members.union(owner)

This comment has been minimized.

Copy link
@faebebin

faebebin Aug 16, 2023

Member

@why-not-try-calmer , @suricactus IMO a method named get_organization_members should return a QuerySet[OrganizationMember] (and not Person ) . Also then it would have probably not broken anything ...

This comment has been minimized.

Copy link
@faebebin

faebebin Aug 16, 2023

Member

I suggest revert for now?

This comment has been minimized.

Copy link
@suricactus

suricactus Aug 16, 2023

Author Collaborator

It was returning a QuerySet[OrganizationMember], but by returning Person it allows making a magic inclusion of users that still have permisisons on specific project but they are not OrganizationMember. I would prefer we keep it like it is in this PR.

This comment has been minimized.

Copy link
@faebebin

faebebin Aug 16, 2023

Member

agree, thanks 👍


def get_project_deltas(project):
Expand Down

0 comments on commit fe8338a

Please sign in to comment.