Skip to content

Commit

Permalink
subcommunities: implement expire invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Nov 21, 2024
1 parent 22eea5a commit 9f34f06
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion site/zenodo_rdm/subcommunities/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SubCommunityInvitationRequest,
SubCommunityRequest,
)
from invenio_communities.proxies import current_communities
from invenio_notifications.services.uow import NotificationOp
from invenio_rdm_records.proxies import (
current_community_records_service,
Expand Down Expand Up @@ -224,11 +225,37 @@ def execute(self, identity, uow):
class SubcommunityInvitationExpireAction(actions.ExpireAction):
"""Expire action."""

def _get_community_records(self, community_id):
"""Get the records of a community."""
return current_community_records_service.search(
system_identity, community_id=community_id
)

def execute(self, identity, uow):
"""Accepts the request."""
"""Execute expire action."""
child = self.request.receiver.resolve().id
parent = self.request.created_by.resolve().id

# Move records
records = self._get_community_records(child)
current_rdm_records.record_communities_service.bulk_add(
system_identity, parent, (x["id"] for x in records), uow=uow
)

current_communities.service.bulk_update_parent(
system_identity, [child], parent_id=parent, uow=uow
)

super().execute(identity, uow)

uow.register(
NotificationOp(
notifications.SubComInvitationExpire.build(
identity=identity, request=self.request
)
)
)


class ZenodoSubCommunityInvitationRequest(SubCommunityInvitationRequest):
"""Request from a Zenodo community to add a child community."""
Expand Down

0 comments on commit 9f34f06

Please sign in to comment.