diff --git a/invenio.cfg b/invenio.cfg index 90e1f799..b9732f52 100644 --- a/invenio.cfg +++ b/invenio.cfg @@ -83,7 +83,7 @@ from invenio_app_rdm.config import \ from invenio_app_rdm.config import \ VOCABULARIES_DATASTREAM_WRITERS as DEFAULT_VOCABULARIES_DATASTREAM_WRITERS from cds_rdm.clc_sync.services.components import ClcSyncComponent -from cds_rdm.components import CDSResourcePublication, CommitteeApprovalComponent, MintAlternateIdentifierComponent, PublicationInclusionComponent, SubjectsValidationComponent +from cds_rdm.components import CDSResourcePublication, CommitteeApprovalComponent, MintAlternateIdentifierComponent, SubjectsValidationComponent # PublicationInclusionComponent temporarily disabled from cds_rdm.pids import validate_optional_doi_transitions from cds_rdm.views import frontpage_view_function, inspire_link_render from cds_rdm.reviews.policy import CDSRecordVersionReviewPolicy @@ -761,7 +761,7 @@ RDM_RECORDS_SERVICE_COMPONENTS = [ CDSResourcePublication, ClcSyncComponent, MintAlternateIdentifierComponent, - PublicationInclusionComponent, + # PublicationInclusionComponent, # temporarily disabled VCSComponent, ] diff --git a/site/cds_rdm/components.py b/site/cds_rdm/components.py index 1e20008e..f9c04c04 100644 --- a/site/cds_rdm/components.py +++ b/site/cds_rdm/components.py @@ -21,7 +21,9 @@ from invenio_records_resources.services.uow import TaskOp from marshmallow import ValidationError -from .tasks import submit_community_inclusion_request, sync_alternate_identifiers +from .tasks import ( + sync_alternate_identifiers, # submit_community_inclusion_request temporarily disabled +) def is_record_public(record): @@ -356,57 +358,58 @@ def publish(self, identity, draft=None, record=None): ) -class PublicationInclusionComponent(ServiceComponent): - """Auto-submit a community inclusion request to the CERN Scientific Community. - - Triggers on publish for public records whose resource type is listed in - `CDS_CERN_SCIENTIFIC_RESOURCE_TYPES`. The request is created asynchronously - after the publish transaction commits. - """ - - def _is_eligible(self, draft, record): - """Return True when the record should be auto-submitted for community inclusion.""" - if not is_record_public(draft): - return False - - resource_type = draft["metadata"]["resource_type"]["id"] - research_resource_types = current_app.config.get( - "CDS_CERN_SCIENTIFIC_RESOURCE_TYPES", set() - ) - if resource_type not in research_resource_types: - return False - - # Skip if the record is in the Scientific Community or the Related Research Community already - # IMPORTANT: - # 1. For thesis, we have the component CDSResourcePublication to validate the community selection - # 2. For other resource types, it is highly unlikely that the record is NOT eligible for inclusion - # in the CERN Research Community, since these works typically belong to CERN - # On the off chance if there is a rare case, it will be dealt via support on case by case basis - communities_to_skip = [ - current_app.config["CDS_CERN_SCIENTIFIC_COMMUNITY_ID"], - current_app.config["CDS_CERN_RELATED_RESEARCH_COMMUNITY_ID"], - ] - for community_id in communities_to_skip: - if not community_id: - current_app.logger.error( - f"Scientific Community IDs are not configured; " - "skipping auto community inclusion for record %s.", - record.pid.pid_value, - ) - return False - if community_id in record.parent.communities.ids: - return False - - return True - - def publish(self, identity, draft=None, record=None, **kwargs): - """Schedule community inclusion request after the record is published.""" - if not self._is_eligible(draft, record): - return - - self.uow.register( - TaskOp( - submit_community_inclusion_request, - record_id=record.pid.pid_value, - ) - ) +# PublicationInclusionComponent temporarily disabled +# class PublicationInclusionComponent(ServiceComponent): +# """Auto-submit a community inclusion request to the CERN Scientific Community. +# +# Triggers on publish for public records whose resource type is listed in +# `CDS_CERN_SCIENTIFIC_RESOURCE_TYPES`. The request is created asynchronously +# after the publish transaction commits. +# """ +# +# def _is_eligible(self, draft, record): +# """Return True when the record should be auto-submitted for community inclusion.""" +# if not is_record_public(draft): +# return False +# +# resource_type = draft["metadata"]["resource_type"]["id"] +# research_resource_types = current_app.config.get( +# "CDS_CERN_SCIENTIFIC_RESOURCE_TYPES", set() +# ) +# if resource_type not in research_resource_types: +# return False +# +# # Skip if the record is in the Scientific Community or the Related Research Community already +# # IMPORTANT: +# # 1. For thesis, we have the component CDSResourcePublication to validate the community selection +# # 2. For other resource types, it is highly unlikely that the record is NOT eligible for inclusion +# # in the CERN Research Community, since these works typically belong to CERN +# # On the off chance if there is a rare case, it will be dealt via support on case by case basis +# communities_to_skip = [ +# current_app.config["CDS_CERN_SCIENTIFIC_COMMUNITY_ID"], +# current_app.config["CDS_CERN_RELATED_RESEARCH_COMMUNITY_ID"], +# ] +# for community_id in communities_to_skip: +# if not community_id: +# current_app.logger.error( +# f"Scientific Community IDs are not configured; " +# "skipping auto community inclusion for record %s.", +# record.pid.pid_value, +# ) +# return False +# if community_id in record.parent.communities.ids: +# return False +# +# return True +# +# def publish(self, identity, draft=None, record=None, **kwargs): +# """Schedule community inclusion request after the record is published.""" +# if not self._is_eligible(draft, record): +# return +# +# self.uow.register( +# TaskOp( +# submit_community_inclusion_request, +# record_id=record.pid.pid_value, +# ) +# ) diff --git a/site/tests/test_components.py b/site/tests/test_components.py index 32af6571..bbfec251 100644 --- a/site/tests/test_components.py +++ b/site/tests/test_components.py @@ -25,9 +25,8 @@ from invenio_search.engine import dsl from marshmallow import ValidationError -from cds_rdm.components import ( +from cds_rdm.components import ( # temporarily disabled PublicationInclusionComponent, MintAlternateIdentifierComponent, - PublicationInclusionComponent, SubjectsValidationComponent, ) from cds_rdm.tasks import submit_community_inclusion_request @@ -439,136 +438,136 @@ def test_mint_alternate_identifier_component( service.publish(uploader.identity, id_=draft14.id) -def test_publication_inclusion_component( - minimal_restricted_record, - uploader, - client, - monkeypatch, - scientific_community, - related_research_community, - community, - record_community, - db, -): - """Test for the publication inclusion component. - - Tests all scenarios: - 1. Eligible public research record creates a CSC inclusion request on publish - 2. Restricted record does not create a request - 3. Non-research resource type does not create a request - 4. Record already in the scientific community does not create a request - 5. Duplicate submission does not create duplicate requests - 6. Missing scientific community config throws an error - """ - client = uploader.login(client) - service = current_rdm_records.records_service - - monkeypatch.setitem( - current_app.config, - "RDM_RECORDS_SERVICE_COMPONENTS", - [*DefaultRecordsComponents, PublicationInclusionComponent], - ) - - monkeypatch.setitem( - current_app.config, - "CDS_CERN_SCIENTIFIC_RESOURCE_TYPES", - {"publication-article", "publication-dissertation"}, - ) - - def _count_open_inclusion_requests(record_pid): - Request.index.refresh() - results = current_requests_service.search( - system_identity, - extra_filter=dsl.query.Bool( - "must", - must=[ - dsl.Q("term", **{"type": CommunityInclusion.type_id}), - dsl.Q("term", **{"topic.record": record_pid}), - dsl.Q( - "term", - **{"receiver.community": str(scientific_community.id)}, - ), - dsl.Q("term", **{"is_open": True}), - ], - ), - ) - return results.total - - # 1. Eligible public research record creates a CSC inclusion request - eligible_record = deepcopy(minimal_restricted_record) - eligible_record["access"]["record"] = "public" - eligible_record["metadata"]["resource_type"] = {"id": "publication-article"} - - published_record = record_community.create_record( - uploader=uploader, record_dict=eligible_record, community=community - ) - record_pid = published_record.pid.pid_value - - assert str(scientific_community.id) not in published_record.parent.communities.ids - assert _count_open_inclusion_requests(record_pid) == 1 - - # 2. Restricted record does not create a request - restricted_record = deepcopy(minimal_restricted_record) - restricted_record["access"]["record"] = "restricted" - restricted_record["metadata"]["resource_type"] = {"id": "publication-article"} - - published_restricted_record = record_community.create_record( - uploader=uploader, record_dict=restricted_record, community=community - ) - assert ( - _count_open_inclusion_requests(published_restricted_record.pid.pid_value) == 0 - ) - - # 3. Non-research resource type does not create a request - non_research_record = deepcopy(minimal_restricted_record) - non_research_record["access"]["record"] = "public" - non_research_record["metadata"]["resource_type"] = {"id": "image-photo"} - - published_non_research_record = record_community.create_record( - uploader=uploader, record_dict=non_research_record, community=community - ) - assert ( - _count_open_inclusion_requests(published_non_research_record.pid.pid_value) - == 0 - ) - - # 4. Record already in the scientific community does not create a request - already_in_csc_record = deepcopy(minimal_restricted_record) - already_in_csc_record["access"]["record"] = "public" - already_in_csc_record["metadata"]["resource_type"] = {"id": "publication-article"} - - published_in_csc_record = record_community.create_record( - uploader=uploader, record_dict=already_in_csc_record, community=scientific_community - ) - assert ( - str(scientific_community.id) in published_in_csc_record.parent.communities.ids - ) - assert _count_open_inclusion_requests(published_in_csc_record.pid.pid_value) == 0 - - # 5. If the record is accepted to CERN Related Research Community, it should not create a request - related_research_record = deepcopy(minimal_restricted_record) - related_research_record["access"]["record"] = "public" - related_research_record["metadata"]["resource_type"] = {"id": "publication-article"} - published_related_research_record = record_community.create_record( - uploader=uploader, record_dict=related_research_record, community=related_research_community - ) - assert _count_open_inclusion_requests(published_related_research_record.pid.pid_value) == 0 - - # 6. Duplicate submission does not create duplicate requests - submit_community_inclusion_request(record_pid) - submit_community_inclusion_request(record_pid) - assert _count_open_inclusion_requests(record_pid) == 1 - - # 7. Missing scientific community config throws an error - monkeypatch.setitem(current_app.config, "CDS_CERN_SCIENTIFIC_COMMUNITY_ID", None) - - no_config_record = deepcopy(minimal_restricted_record) - no_config_record["access"]["record"] = "public" - no_config_record["metadata"]["resource_type"] = {"id": "publication-article"} - - published_no_config_record = record_community.create_record( - uploader=uploader, record_dict=no_config_record, community=community - ) - assert ( - _count_open_inclusion_requests(published_no_config_record.pid.pid_value) == 0 - ) +# def test_publication_inclusion_component( +# minimal_restricted_record, +# uploader, +# client, +# monkeypatch, +# scientific_community, +# related_research_community, +# community, +# record_community, +# db, +# ): +# """Test for the publication inclusion component. + +# Tests all scenarios: +# 1. Eligible public research record creates a CSC inclusion request on publish +# 2. Restricted record does not create a request +# 3. Non-research resource type does not create a request +# 4. Record already in the scientific community does not create a request +# 5. Duplicate submission does not create duplicate requests +# 6. Missing scientific community config throws an error +# """ +# client = uploader.login(client) +# service = current_rdm_records.records_service + +# monkeypatch.setitem( +# current_app.config, +# "RDM_RECORDS_SERVICE_COMPONENTS", +# [*DefaultRecordsComponents, PublicationInclusionComponent], +# ) + +# monkeypatch.setitem( +# current_app.config, +# "CDS_CERN_SCIENTIFIC_RESOURCE_TYPES", +# {"publication-article", "publication-dissertation"}, +# ) + +# def _count_open_inclusion_requests(record_pid): +# Request.index.refresh() +# results = current_requests_service.search( +# system_identity, +# extra_filter=dsl.query.Bool( +# "must", +# must=[ +# dsl.Q("term", **{"type": CommunityInclusion.type_id}), +# dsl.Q("term", **{"topic.record": record_pid}), +# dsl.Q( +# "term", +# **{"receiver.community": str(scientific_community.id)}, +# ), +# dsl.Q("term", **{"is_open": True}), +# ], +# ), +# ) +# return results.total + +# # 1. Eligible public research record creates a CSC inclusion request +# eligible_record = deepcopy(minimal_restricted_record) +# eligible_record["access"]["record"] = "public" +# eligible_record["metadata"]["resource_type"] = {"id": "publication-article"} + +# published_record = record_community.create_record( +# uploader=uploader, record_dict=eligible_record, community=community +# ) +# record_pid = published_record.pid.pid_value + +# assert str(scientific_community.id) not in published_record.parent.communities.ids +# assert _count_open_inclusion_requests(record_pid) == 1 + +# # 2. Restricted record does not create a request +# restricted_record = deepcopy(minimal_restricted_record) +# restricted_record["access"]["record"] = "restricted" +# restricted_record["metadata"]["resource_type"] = {"id": "publication-article"} + +# published_restricted_record = record_community.create_record( +# uploader=uploader, record_dict=restricted_record, community=community +# ) +# assert ( +# _count_open_inclusion_requests(published_restricted_record.pid.pid_value) == 0 +# ) + +# # 3. Non-research resource type does not create a request +# non_research_record = deepcopy(minimal_restricted_record) +# non_research_record["access"]["record"] = "public" +# non_research_record["metadata"]["resource_type"] = {"id": "image-photo"} + +# published_non_research_record = record_community.create_record( +# uploader=uploader, record_dict=non_research_record, community=community +# ) +# assert ( +# _count_open_inclusion_requests(published_non_research_record.pid.pid_value) +# == 0 +# ) + +# # 4. Record already in the scientific community does not create a request +# already_in_csc_record = deepcopy(minimal_restricted_record) +# already_in_csc_record["access"]["record"] = "public" +# already_in_csc_record["metadata"]["resource_type"] = {"id": "publication-article"} + +# published_in_csc_record = record_community.create_record( +# uploader=uploader, record_dict=already_in_csc_record, community=scientific_community +# ) +# assert ( +# str(scientific_community.id) in published_in_csc_record.parent.communities.ids +# ) +# assert _count_open_inclusion_requests(published_in_csc_record.pid.pid_value) == 0 + +# # 5. If the record is accepted to CERN Related Research Community, it should not create a request +# related_research_record = deepcopy(minimal_restricted_record) +# related_research_record["access"]["record"] = "public" +# related_research_record["metadata"]["resource_type"] = {"id": "publication-article"} +# published_related_research_record = record_community.create_record( +# uploader=uploader, record_dict=related_research_record, community=related_research_community +# ) +# assert _count_open_inclusion_requests(published_related_research_record.pid.pid_value) == 0 + +# # 6. Duplicate submission does not create duplicate requests +# submit_community_inclusion_request(record_pid) +# submit_community_inclusion_request(record_pid) +# assert _count_open_inclusion_requests(record_pid) == 1 + +# # 7. Missing scientific community config throws an error +# monkeypatch.setitem(current_app.config, "CDS_CERN_SCIENTIFIC_COMMUNITY_ID", None) + +# no_config_record = deepcopy(minimal_restricted_record) +# no_config_record["access"]["record"] = "public" +# no_config_record["metadata"]["resource_type"] = {"id": "publication-article"} + +# published_no_config_record = record_community.create_record( +# uploader=uploader, record_dict=no_config_record, community=community +# ) +# assert ( +# _count_open_inclusion_requests(published_no_config_record.pid.pid_value) == 0 +# )