-
Notifications
You must be signed in to change notification settings - Fork 69
Author interface for ROR, CRediT, and ORCiD in submission workflow #4697
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
base: master
Are you sure you want to change the base?
Changes from all commits
17473d3
ae579d7
d8fe63a
c35c158
baf0ebd
2677b07
5c62de1
3d8ba00
d11f806
5713e3d
46a4fb8
b3bd84c
2be1964
a679161
56c586b
8fae7f0
a0053c0
afc615a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
from repository import models as repository_models | ||
from utils.models import RORImportError | ||
from submission import models as submission_models | ||
from utils.forms import clean_orcid_id | ||
from submission.models import CreditRecord | ||
from utils.logger import get_logger | ||
from utils import logic as utils_logic | ||
|
@@ -390,6 +391,13 @@ def password_policy_check(self, request, password): | |
def string_id(self): | ||
return str(self.id) | ||
|
||
@property | ||
def real_email(self): | ||
if not self.email.endswith(settings.DUMMY_EMAIL_DOMAIN): | ||
return self.email | ||
else: | ||
return '' | ||
|
||
def get_full_name(self): | ||
"""Deprecated in 1.5.2""" | ||
return self.full_name() | ||
|
@@ -692,9 +700,10 @@ def add_credit(self, credit_role_text, article): | |
""" | ||
Adds a CRediT role to the article for this user | ||
""" | ||
record, _ = ( | ||
submission_models.CreditRecord.objects.get_or_create( | ||
article=article, author=self, role=credit_role_text) | ||
record, _created = submission_models.CreditRecord.objects.get_or_create( | ||
article=article, | ||
author=self, | ||
role=credit_role_text, | ||
) | ||
|
||
return record | ||
|
@@ -710,6 +719,7 @@ def remove_credit(self, credit_role_text, article): | |
role=credit_role_text, | ||
) | ||
record.delete() | ||
return record | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this being returned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the view can use it in the message that's printed for the user. |
||
except submission_models.CreditRecord.DoesNotExist: | ||
pass | ||
|
||
|
@@ -2654,13 +2664,21 @@ def get_or_create_without_ror( | |
# entered without a ROR for this | ||
# account / frozen author / preprint author? | ||
try: | ||
organization = cls.objects.get( | ||
# If there is no `institution`, this method is being used to update | ||
# the department or country in isolation, so we want the primary | ||
# affiliation's org regardless of what its custom label is. | ||
query = models.Q( | ||
controlledaffiliation__is_primary=True, | ||
controlledaffiliation__account=account, | ||
controlledaffiliation__frozen_author=frozen_author, | ||
controlledaffiliation__preprint_author=preprint_author, | ||
ror_id__exact='', | ||
) | ||
# If there is an institution name, we should only match organizations | ||
# with that as a custom label. | ||
if institution: | ||
query &= models.Q(custom_label__value=institution) | ||
organization = cls.objects.get(query) | ||
except (cls.DoesNotExist, cls.MultipleObjectsReturned): | ||
# Otherwise, create a new, disconnected record. | ||
organization = cls.objects.create() | ||
|
@@ -2757,7 +2775,7 @@ class Meta: | |
['account', 'frozen_author', 'preprint_author'], | ||
) | ||
] | ||
ordering = ['is_primary', '-pk'] | ||
ordering = ['-is_primary', '-pk'] | ||
|
||
def title_department(self): | ||
elements = [ | ||
|
@@ -2836,10 +2854,12 @@ def get_or_create_without_ror( | |
cls, | ||
institution='', | ||
department='', | ||
title='', | ||
country='', | ||
account=None, | ||
frozen_author=None, | ||
preprint_author=None, | ||
defaults=None, | ||
): | ||
""" | ||
Backwards-compatible API for setting affiliation from unstructured text. | ||
|
@@ -2856,6 +2876,8 @@ def get_or_create_without_ror( | |
:type account: core.models.Account | ||
:type frozen_author: submission.models.FrozenAuthor | ||
:type preprint_author: repository.models.PreprintAuthor | ||
:param defaults: default dict passed to ControlledAffiliation.get_or_create: | ||
:type defaults: dict: | ||
""" | ||
organization, _created = Organization.get_or_create_without_ror( | ||
institution=institution, | ||
|
@@ -2864,12 +2886,16 @@ def get_or_create_without_ror( | |
frozen_author=frozen_author, | ||
preprint_author=preprint_author, | ||
) | ||
if not defaults: | ||
defaults = {} | ||
|
||
defaults = { | ||
defaults.update({ | ||
'organization': organization, | ||
} | ||
}) | ||
if department: | ||
defaults['department'] = department | ||
if title: | ||
defaults['title'] = title | ||
kwargs = { | ||
'is_primary': True, | ||
'account': account, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,25 @@ def setUpTestData(cls): | |
account=cls.user, | ||
organization=cls.organization_bbk, | ||
) | ||
cls.country_us = core_models.Country.objects.create( | ||
code='US', | ||
name='United States', | ||
) | ||
cls.location_oakland = core_models.Location.objects.create( | ||
name='Oakland', | ||
geonames_id=5378538, | ||
country=cls.country_us, | ||
) | ||
cls.organization_cdl = core_models.Organization.objects.create( | ||
ror_id='03yrm5c26', | ||
) | ||
cls.organization_cdl.locations.add(cls.location_oakland) | ||
cls.name_cdl = core_models.OrganizationName.objects.create( | ||
value='California Digital Library', | ||
language='en', | ||
ror_display_for=cls.organization_cdl, | ||
label_for=cls.organization_cdl, | ||
) | ||
|
||
# The raw unicode string of a 'next' URL | ||
cls.next_url_raw = '/target/page/?a=b&x=y' | ||
|
@@ -829,3 +848,30 @@ def test_affiliation_delete_post(self): | |
response = self.client.post(url, post_data, follow=True) | ||
with self.assertRaises(core_models.ControlledAffiliation.DoesNotExist): | ||
core_models.ControlledAffiliation.objects.get(pk=affil_id) | ||
|
||
@patch('utils.orcid.get_orcid_record') | ||
def test_affiliation_bulk_update_from_orcid(self, get_orcid_record): | ||
get_orcid_record.return_value = helpers.get_orcid_record_all_fields() | ||
self.client.force_login(self.user) | ||
get_data = {} | ||
affil_id = self.affiliation.pk | ||
url = f'/profile/affiliation/update-from-orcid/' | ||
response = self.client.get(url, get_data) | ||
self.assertEqual( | ||
response.context['new_affils'][0].__str__(), | ||
'California Digital Library, Oakland, United States' | ||
) | ||
|
||
@patch('utils.orcid.get_orcid_record') | ||
def test_affiliation_bulk_update_from_orcid_confirmed(self, get_orcid_record): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test name here is a dupe of the one above. |
||
get_orcid_record.return_value = helpers.get_orcid_record_all_fields() | ||
self.client.force_login(self.user) | ||
post_data = {} | ||
affil_id = self.affiliation.pk | ||
url = f'/profile/affiliation/update-from-orcid/' | ||
self.client.post(url, post_data, follow=True) | ||
self.user.refresh_from_db() | ||
self.assertEqual( | ||
self.user.primary_affiliation().__str__(), | ||
'California Digital Library, Oakland, United States' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to handle the case of explicit
None
like for the other cases? (e.g{'year': {'value': None}}
)