(user) add organization data on users API

This will allow the frontend to display data about
organizations when displaying a user or a list of
users.
This commit is contained in:
Quentin BEY
2024-11-22 14:18:50 +01:00
committed by BEY Quentin
parent 5692c50f21
commit edbd1f0061
5 changed files with 119 additions and 14 deletions

View File

@@ -359,14 +359,8 @@ class Organization(BaseModel):
"""
Compute and return abilities for a given user on the organization.
"""
try:
# Use the role from queryset annotation if available
is_admin = self.user_role == OrganizationRoleChoices.ADMIN
except AttributeError:
is_admin = self.organization_accesses.filter(
user=user,
role=OrganizationRoleChoices.ADMIN,
).exists()
# Use the role from queryset annotation will raise on purpose if not used properly
is_admin = self.user_role == OrganizationRoleChoices.ADMIN # pylint: disable=no-member
return {
"get": user.organization_id == self.pk,