-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(organization): expose
owner_label
in ProjectView endpoint respo…
…nse TASK-1384 (#5388) ### 📣 Summary The Project view endpoint has been updated to include the owner label in its response. ### 📖 Description The Project view endpoint has been updated to include the owner label in its response. This fix ensures that the front end can retrieve the owner information directly from the endpoint, improving usability across the application.
- Loading branch information
1 parent
06f8a52
commit 68a0cac
Showing
4 changed files
with
57 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from collections import defaultdict | ||
from django.db.models import Prefetch | ||
|
||
from kobo.apps.organizations.models import Organization | ||
from kpi.models.asset import Asset | ||
|
||
|
||
class AssetViewSetListMixin: | ||
|
||
def get_organizations_per_asset_ids(self, asset_ids: list) -> dict: | ||
|
||
assets = ( | ||
Asset.objects.only('owner', 'uid', 'name') | ||
.filter(id__in=asset_ids) | ||
.select_related('owner') | ||
.prefetch_related( | ||
Prefetch( | ||
'owner__organizations_organization', | ||
queryset=Organization.objects.all().order_by( | ||
'-organization_users__created' | ||
), | ||
to_attr='organizations', | ||
) | ||
) | ||
) | ||
organizations_per_asset = defaultdict(dict) | ||
for asset in assets: | ||
try: | ||
organizations_per_asset[asset.id] = asset.owner.organizations[0] | ||
except IndexError: | ||
pass | ||
|
||
return organizations_per_asset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters