Skip to content

Commit

Permalink
[ENG-6314] Set private title instead of an empty string when sync wit…
Browse files Browse the repository at this point in the history
…h CrossRef (#10969)

## Purpose

CrossRef fails silently when a status of preprint is not public. In this case we should pass a specific string instead of an empty string

## Notes

1. Matt's comment: "The XML file that we send has an empty <title>, which causes CrossRef to (silently) not accept it. If preprint spam_status is.SPAM, title should be REMOVED DUE TO POLICY VIOLATIONS, otherwise WITHDRAWN."
2. Import is not moved at the top of the file because of circular imports

## Ticket

https://openscience.atlassian.net/browse/ENG-6314
  • Loading branch information
ihorsokhanexoft authored Feb 10, 2025
1 parent 82491f8 commit 1855d55
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 23 additions & 2 deletions tests/identifiers/test_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def test_metadata_for_deleted_node(self, crossref_client, preprint):
assert not root.find('.//{%s}contributors' % crossref.CROSSREF_NAMESPACE)

assert root.find('.//{%s}group_title' % crossref.CROSSREF_NAMESPACE).text == preprint.provider.name
assert not root.find('.//{%s}title' % crossref.CROSSREF_NAMESPACE).text
assert not root.find('.//{%s}abstract/' % crossref.JATS_NAMESPACE)
assert not root.find('.//{%s}license_ref' % crossref.CROSSREF_ACCESS_INDICATORS)

Expand Down Expand Up @@ -348,4 +347,26 @@ def test_metadata_for_affiliated_institutions(self, crossref_client, preprint):
root = lxml.etree.fromstring(crossref_xml)
contributors = root.find('.//{%s}contributors' % crossref.CROSSREF_NAMESPACE)
assert contributors.find('.//{%s}institution_name' % crossref.CROSSREF_NAMESPACE).text == institution.name
assert contributors.find('.//{%s}institution_id' % crossref.CROSSREF_NAMESPACE).text == institution.ror_uri
assert contributors.find('.//{%s}institution_id' % crossref.CROSSREF_NAMESPACE).text == institution.ror_uri

def test_public_preprint_title_is_composed_correctly(self, crossref_client, preprint):
preprint.title = 'My Title'
preprint.save()

xml = crossref_client.build_metadata(preprint)
assert '<titles><title>My Title</title></titles>' in str(xml)

def test_private_preprint_title_is_composed_correctly(self, crossref_client, preprint):
preprint.title = 'My Title'
preprint.is_public = False
preprint.save()
xml = crossref_client.build_metadata(preprint)
assert '<titles><title>WITHDRAWN</title></titles>' in str(xml)

def test_spam_preprint_title_is_composed_correctly(self, crossref_client, preprint):
preprint.title = 'My Title'
preprint.save()

preprint.confirm_spam(save=True)
xml = crossref_client.build_metadata(preprint)
assert '<titles><title>REMOVED DUE TO POLICY VIOLATIONS</title></titles>' in str(xml)
5 changes: 4 additions & 1 deletion website/identifiers/clients/crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def build_posted_content(self, preprint, element, include_relation):
preprint - preprint to build posted_content for
element - namespace element to use when building parts of the XML structure
"""
from osf.models import SpamStatus

posted_content = element.posted_content(
element.group_title(preprint.provider.name),
type='preprint'
Expand All @@ -94,7 +96,8 @@ def build_posted_content(self, preprint, element, include_relation):
if status == 'public':
posted_content.append(element.contributors(*self._crossref_format_contributors(element, preprint)))

title = element.title(remove_control_characters(preprint.title)) if status == 'public' else element.title('')
private_title = 'REMOVED DUE TO POLICY VIOLATIONS' if preprint.spam_status == SpamStatus.SPAM else 'WITHDRAWN'
title = element.title(remove_control_characters(preprint.title)) if status == 'public' else element.title(private_title)
posted_content.append(element.titles(title))

posted_content.append(element.posted_date(*self._crossref_format_date(element, preprint.date_published)))
Expand Down

0 comments on commit 1855d55

Please sign in to comment.