Skip to content

Commit

Permalink
fix: Adds a check for the TaxonomyOrg.rel_type when serializing orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Feb 7, 2024
1 parent 286230a commit b372861
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from organizations.models import Organization

from ...models import TaxonomyOrg


class TaxonomyOrgListQueryParamsSerializer(TaxonomyListQueryParamsSerializer):
"""
Expand Down Expand Up @@ -73,16 +75,19 @@ class TaxonomyOrgSerializer(TaxonomySerializer):
def get_orgs(self, obj) -> list[str]:
"""
Return the list of orgs for the taxonomy.
"""
return [taxonomy_org.org.short_name for taxonomy_org in obj.taxonomyorg_set.all() if taxonomy_org.org]
"""
return [
taxonomy_org.org.short_name for taxonomy_org in obj.taxonomyorg_set.all()
if taxonomy_org.org and taxonomy_org.rel_type == TaxonomyOrg.RelType.OWNER
]

def get_all_orgs(self, obj) -> bool:
"""
Return True if the taxonomy is associated with all orgs.
"""
is_all_orgs = False
for taxonomy_org in obj.taxonomyorg_set.all():
if taxonomy_org.org_id is None:
if taxonomy_org.org_id is None and taxonomy_org.rel_type == TaxonomyOrg.RelType.OWNER:
return True
return False

Expand Down

0 comments on commit b372861

Please sign in to comment.