Skip to content

Commit

Permalink
subcommunities: implement accept invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed Nov 20, 2024
1 parent 784aeb6 commit 193ddc6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions site/zenodo_rdm/subcommunities/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from invenio_access.permissions import system_identity
from invenio_communities.subcommunities.services.request import (
AcceptSubcommunity,
AcceptSubcommunityInvitation,
DeclineSubcommunity,
SubCommunityInvitationRequest,
SubCommunityRequest,
Expand All @@ -28,6 +29,7 @@
from invenio_requests.proxies import current_events_service
from invenio_requests.resolvers.registry import ResolverRegistry
from marshmallow import fields
from marshmallow.exceptions import ValidationError


class SubcommunityAcceptAction(AcceptSubcommunity):
Expand Down Expand Up @@ -128,7 +130,18 @@ class ZenodoSubCommunityRequest(SubCommunityRequest):
}


class SubCommunityInvitationAcceptAction(AcceptSubcommunity):
class SubcommunityInvitationCreateAction(actions.CreateAction):
"""Represents an accept action used to accept a subcommunity."""

def execute(self, identity, uow):
"""Execute approve action."""
parent = self.request.created_by.resolve()
if not parent.children.allow:
raise ValidationError("Assigned parent is not allowed to be a parent.")
super().execute(identity, uow)


class SubCommunityInvitationAcceptAction(AcceptSubcommunityInvitation):
"""Represents an accept action used to accept a subcommunity.
Zenodo re-implementation of the accept action, to also move the records.
Expand All @@ -142,13 +155,13 @@ def _get_community_records(self, community_id):

def execute(self, identity, uow):
"""Execute approve action."""
to_be_moved = self.request.topic.resolve().id
move_to = self.request.receiver.resolve().id
child = self.request.receiver.resolve().id
parent = self.request.created_by.resolve().id

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

Expand Down Expand Up @@ -220,12 +233,12 @@ class ZenodoSubCommunityInvitationRequest(SubCommunityInvitationRequest):
"""Request from a Zenodo community to add a child community."""

available_actions = {
"create": actions.CreateAction,
"delete": actions.DeleteAction,
"cancel": actions.CancelAction,
# Custom implemented actions
"create": SubcommunityInvitationCreateAction,
"submit": SubcommunityInvitationSubmitAction,
"accept": SubcommunityAcceptAction,
"accept": SubCommunityInvitationAcceptAction,
"decline": DeclineSubcommunity,
"expire": SubcommunityInvitationExpireAction,
}
Expand Down

0 comments on commit 193ddc6

Please sign in to comment.