Skip to content

Commit

Permalink
Move project exclusion flag logic to transfer_project and reorder ass…
Browse files Browse the repository at this point in the history
…et filter backends
  • Loading branch information
rajpatel24 committed Jan 28, 2025
1 parent f68da4c commit a440a11
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions kobo/apps/project_ownership/models/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def transfer_project(self):
self.statuses.filter(status_type__in=status_types).update(
status=TransferStatusChoices.SUCCESS
)
# Update `is_excluded_from_projects_list` flag
self._update_project_exclusion_flag()
else:
_rewrite_mongo = True
with transaction.atomic():
Expand All @@ -147,6 +149,8 @@ def transfer_project(self):

self._sent_in_app_messages()

# Update `is_excluded_from_projects_list` flag
self._update_project_exclusion_flag()
# Do not delegate anything to Celery before the transaction has
# been validated. Otherwise, Celery could fetch outdated data.
transaction.on_commit(lambda: self._start_async_jobs(_rewrite_mongo))
Expand Down Expand Up @@ -331,6 +335,22 @@ def _update_invite_status(self):
self.invite.status = invite.status
self.invite.date_modified = invite.date_modified

def _update_project_exclusion_flag(self):
"""
Set `is_excluded_from_projects_list` to `True` for assets owned by the
sender or invitee joining the organization. These assets should be
excluded from the organization owner's `My Projects` list
"""
if isinstance(self.invite, OrgMembershipAutoInvite):
real_owner = get_real_owner(self.invite.sender)
self.asset.is_excluded_from_projects_list = (
real_owner != self.invite.sender
)
self.asset.save(
update_fields=['is_excluded_from_projects_list'],
adjust_content=False
)


class TransferStatus(AbstractTimeStampedModel):

Expand Down
2 changes: 1 addition & 1 deletion kpi/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ExcludeOrgAssetFilter(filters.BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
user = get_database_user(request.user)
organization = user.organization
if organization.is_owner(user) and organization.is_mmo:
if organization and organization.is_owner(user) and organization.is_mmo:
return queryset.exclude(is_excluded_from_projects_list=True)
return queryset

Expand Down
2 changes: 1 addition & 1 deletion kpi/views/v2/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ class AssetViewSet(
'subscribers_count',
]
filter_backends = [
ExcludeOrgAssetFilter,
KpiObjectPermissionsFilter,
SearchFilter,
AssetOrderingFilter,
ExcludeOrgAssetFilter
]
renderer_classes = [
renderers.BrowsableAPIRenderer,
Expand Down

0 comments on commit a440a11

Please sign in to comment.