diff --git a/site/zenodo_rdm/subcommunities/request.py b/site/zenodo_rdm/subcommunities/request.py index 66a33652..3ea80997 100644 --- a/site/zenodo_rdm/subcommunities/request.py +++ b/site/zenodo_rdm/subcommunities/request.py @@ -30,16 +30,33 @@ from marshmallow import fields -def _add_community_records(child, parent, uow): +def _add_community_records(child_id, parent_id, uow): """Add records from child to parent.""" records = current_community_records_service.search( - system_identity, community_id=child + system_identity, community_id=child_id ) current_rdm_records.record_communities_service.bulk_add( - system_identity, parent, (x["id"] for x in records), uow=uow + system_identity, parent_id, (x["id"] for x in records), uow=uow ) +def _update_subcommunity_funding(request, subcommunity, uow): + """Update the subcommunity funding metadata.""" + project_id = request.get("payload", {}).get("project_id") + if not project_id: + return + + funding = subcommunity.metadata.setdefault("funding", []) + if project_id in [f.get("award", {}).get("id") for f in funding]: + return subcommunity + + funder_id, _ = project_id.split("::", 1) + funding.append({"award": {"id": project_id}, "funder": {"id": funder_id}}) + uow.register(RecordCommitOp(subcommunity)) + + return subcommunity + + class SubcommunityAcceptAction(AcceptSubcommunity): """Represents an accept action used to accept a subcommunity. @@ -61,26 +78,11 @@ class SubcommunityCreateAction(actions.CreateAndSubmitAction): Zenodo re-implementation of the create action, to also create the system comment. """ - def _update_subcommunity_funding(self, subcommunity, uow): - """Update the subcommunity funding metadata.""" - project_id = self.request.get("payload", {}).get("project_id") - if not project_id: - return - - funding = subcommunity.metadata.setdefault("funding", []) - if project_id in [f.get("award", {}).get("id") for f in funding]: - return subcommunity - - funder_id, _ = project_id.split("::", 1) - funding.append({"award": {"id": project_id}, "funder": {"id": funder_id}}) - uow.register(RecordCommitOp(subcommunity)) - return subcommunity - def execute(self, identity, uow): """Execute create action.""" subcommunity = self.request.topic.resolve() - self._update_subcommunity_funding(subcommunity, uow) + _update_subcommunity_funding(self.request, subcommunity, uow) # Execute the default create action super().execute(identity, uow) @@ -137,14 +139,15 @@ def execute(self, identity, uow): # example: "May 11, 2024" expires_at = self.request.expires_at.strftime("%B %d, %Y") - NAME = self.request.get("payload", {}).get("community-name") - ACRONYM = self.request.get("payload", {}).get("project-acronym") + NAME = self.request.get("payload", {}).get("community_name") + ACRONYM = self.request.get("payload", {}).get("project_acronym") + _, ID = self.request.get("payload", {}).get("project_id").split("::") self.request["description"] = ( "

We would like to invite you to join the " "EU Open Research Repository because we have detected that your Zenodo community " "is likely related to an EU-funded project:

The EU Open " - "Research Repository is a Zenodo community dedicated to fostering open science " + f"{NAME}
  • EU-funded project: {ACRONYM}" + "
  • The EU Open Research Repository is a Zenodo community dedicated to fostering open science " "and enhancing the visibility and accessibility of research outputs funded by " "the European Union. The community is managed by CERN on behalf of the European " "Commission.

    What does it mean to join?