Skip to content

checks: run rules on inclusion #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app_data/vocabularies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ licenses:
data-file: vocabularies/licenses.csv
descriptiontypes:
pid-type: dty
data-file: vocabularies/description_types.yaml
data-file: vocabularies/description_types.yaml
funders:
pid-type: fun
data-file: vocabularies/funders.yaml
awards:
pid-type: awa
data-file: vocabularies/awards.yaml
60 changes: 60 additions & 0 deletions app_data/vocabularies/awards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
- id: "00k4n6c32::101122956"
number: "101122956"
acronym: HORIZON-ZEN
title:
en: EU research programme beneficiary depositing solution in Zenodo
funder:
id: 00k4n6c32
program: HORIZON.1.3
identifiers:
- identifier: https://cordis.europa.eu/project/id/101122956
scheme: url
end_date: "2025-05-31"
start_date: "2023-06-01"
organizations:
- id: "999988133"
scheme: pic
organization: ORGANISATION EUROPEENNE POUR LA RECHERCHE NUCLEAIRE
- id: "00k4n6c32::101057264"
number: "101057264"
acronym: FAIRCORE4EOSC
title:
en: Core Components Supporting a FAIR EOSC
funder:
id: 00k4n6c32
program: HORIZON.1.3
identifiers:
- identifier: https://cordis.europa.eu/project/id/101057264
scheme: url
end_date: "2025-05-31"
start_date: "2022-06-01"
# TODO: Add EuroSciVoc subjects
# subjects:
# - id: euroscivoc:307
# - id: euroscivoc:31
# - id: euroscivoc:51
# - id: euroscivoc:30055
# - id: euroscivoc:29
- id: "00k4n6c32::101129744"
number: "101129744"
title:
en: European Virtual Institute for Research Software Excellence
funder:
id: 00k4n6c32
acronym: EVERSE
program: HORIZON.1.3
start_date: "2024-03-01"
end_date: "2027-02-28"
identifiers:
- identifier: https://cordis.europa.eu/project/id/101129744
scheme: url

- id: "01cwqze88::1OT2DB000013-01"
number: "1OT2DB000013-01"
title:
en: Zenodo and the Generalist Repository Ecosystem Initiative (GREI)
funder:
id: "01cwqze88"
program: OFFICE_OF_THE_DIRECTOR,_NATIONAL_INSTITUTES_OF_HEALTH
start_date: "2022-09-12"
end_date: "2026-05-31"
40 changes: 40 additions & 0 deletions app_data/vocabularies/funders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
- id: 00k4n6c32
name: European Commission
title:
en: European Commission
acronym: EC
identifiers:
- scheme: ror
identifier: 00k4n6c32
- scheme: doi
identifier: 10.13039/501100000780
- scheme: grid
identifier: grid.270680.b
types:
- government
- funder
country: BE
country_name: Belgium
location_name: Brussels
status: active
- id: 01cwqze88
name: National Institutes of Health
title:
en: National Institutes of Health
acronym: NIH
identifiers:
- scheme: ror
identifier: 01cwqze88
- scheme: doi
identifier: 10.13039/100000002
- scheme: grid
identifier: grid.94365.3d
- scheme: isni
identifier: 0000 0001 2297 5165
country: US
country_name: United States
location_name: Bethesda
types:
- government
- funder
status: active
4 changes: 4 additions & 0 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ from invenio_vocabularies.services.custom_fields import (
from zenodo_rdm import facets as zenodo_community_facets
from zenodo_rdm import providers as zenodo_providers
from zenodo_rdm.api import ZenodoRDMDraft, ZenodoRDMRecord
from zenodo_rdm.communities import CommunityInclusion, CommunitySubmission
from zenodo_rdm.communities_ui.views.communities import communities_home
from zenodo_rdm.custom_fields import (
CUSTOM_FIELDS,
Expand Down Expand Up @@ -838,6 +839,9 @@ RDM_COMMUNITY_CONTENT_MODERATION_HANDLERS = [
]
"""Community content moderation handlers."""

RDM_COMMUNITY_SUBMISSION_REQUEST_CLS = CommunitySubmission
RDM_COMMUNITY_INCLUSION_REQUEST_CLS = CommunityInclusion

RDM_SEARCH_SORT_BY_VERIFIED = True
"""Enable the sorting of records by verified."""

Expand Down
4 changes: 2 additions & 2 deletions scripts/ec_create_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def create_eu_checks():
)
db.session.add(check_config)
db.session.commit()
print("EU checks created/updated successfully.")
print("EU Open Research Repository community checks created/updated successfully.")

sub_communities = community_service._search(
"search",
Expand Down Expand Up @@ -590,7 +590,7 @@ def create_eu_checks():
)
db.session.add(check_config)
db.session.commit()
print("EU checks created/updated successfully.")
print("EU subcommunity checks created/updated successfully.")


if __name__ == "__main__":
Expand Down
14 changes: 14 additions & 0 deletions site/zenodo_rdm/communities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2025 CERN.
#
# Zenodo-RDM is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
"""Communities customizations."""

from .requests import CommunityInclusion, CommunitySubmission

__all__ = (
"CommunityInclusion",
"CommunitySubmission",
)
134 changes: 134 additions & 0 deletions site/zenodo_rdm/communities/requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 202% CERN.
#
# Zenodo-RDM is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
"""Communities requests."""

from datetime import datetime

from invenio_checks.models import CheckConfig, CheckRun, CheckRunStatus
from invenio_checks.proxies import current_checks_registry
from invenio_rdm_records.proxies import current_rdm_records_service as service
from invenio_rdm_records.requests import (
community_inclusion,
community_submission,
)
from invenio_records_resources.services.uow import ModelCommitOp
from invenio_requests.customizations import actions


class SubmissionSubmitAction(actions.SubmitAction):
"""Submit action."""

def execute(self, identity, uow):
"""Execute the submit action."""
draft = self.request.topic.resolve()
service._validate_draft(identity, draft)
# Set the record's title as the request title.
self.request["title"] = draft.metadata["title"]

# TODO: Run checks on record or draft

super().execute(identity, uow)


class CommunitySubmission(community_submission.CommunitySubmission):
"""Request to add a subcommunity to a Zenodo community."""

available_actions = {
"create": actions.CreateAction,
"submit": SubmissionSubmitAction,
"delete": actions.DeleteAction,
"accept": community_submission.AcceptAction,
"decline": community_submission.DeclineAction,
"cancel": community_submission.CancelAction,
"expire": community_submission.ExpireAction,
}


class InclusionSubmitAction(actions.SubmitAction):
"""Submit action."""

def execute(self, identity, uow):
"""Execute the submit action."""
record = self.request.topic.resolve()
# Set the record's title as the request title.
self.request["title"] = record.metadata["title"]

# Run checks on record or draft
if record.has_draft:
draft = service.draft_cls.pid.resolve(
record.pid.pid_value, registered_only=False
)
# Use the draft for checks
record = draft

# FIXME: This has been copied from the checks component
community_ids = set()
community = self.request.receiver.resolve()
community_ids.add(str(community.id))
if community.parent:
community_ids.add(str(community.parent.id))

checks = CheckConfig.query.filter(
CheckConfig.community_id.in_(community_ids)
).all()

for check in checks:
try:
check_cls = current_checks_registry.get(check.check_id)
start_time = datetime.utcnow()
res = check_cls().run(record, check.params)
if not res.sync:
continue

latest_check = (
CheckRun.query.filter(
CheckRun.config_id == check.id,
CheckRun.record_id == record.id,
)
# We prefer the latest non-draft check
.order_by(CheckRun.is_draft.desc()).first()
)

if not latest_check:
latest_check = CheckRun(
config_id=check.id,
record_id=record.id,
is_draft=record.is_draft,
revision_id=record.revision_id,
start_time=start_time,
end_time=datetime.utcnow(),
status=CheckRunStatus.COMPLETED,
state="",
result=res.to_dict(),
)
else:
latest_check.is_draft = record.is_draft
latest_check.revision_id = record.revision_id
latest_check.start_time = start_time
latest_check.end_time = datetime.utcnow()
latest_check.result = res.to_dict()

# Create/update the check run to the database
uow.register(ModelCommitOp(latest_check))
except Exception:
continue

super().execute(identity, uow)


class CommunityInclusion(community_inclusion.CommunityInclusion):
"""Request for a published record to be included in a community."""

available_actions = {
"create": actions.CreateAction,
"submit": InclusionSubmitAction,
"delete": actions.DeleteAction,
"accept": community_inclusion.AcceptAction,
"decline": actions.DeclineAction,
"cancel": actions.CancelAction,
"expire": actions.ExpireAction,
}
Loading
Loading