Skip to content
Merged
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
46 changes: 46 additions & 0 deletions osf/migrations/0038_remove_orcid_from_social.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from django.db import migrations, transaction


def remove_orcid_from_social(apps, schema_editor):
from osf.models import OSFUser

user_ids = []
batch = []
CHUNK_SIZE = 1000

for user in OSFUser.objects.filter(social__has_key='orcid').iterator(chunk_size=CHUNK_SIZE):
user.social.pop('orcid', None)
batch.append(user)
user_ids.append(user.id)
if len(batch) >= 1000:
OSFUser.objects.bulk_update(batch, ['social'])
batch.clear()

if batch:
OSFUser.objects.bulk_update(batch, ['social'])

def reindex():
for start in range(0, len(user_ids), CHUNK_SIZE):
chunked_ids = user_ids[start:start + CHUNK_SIZE]
for user in OSFUser.objects.filter(id__in=chunked_ids):
user.update_search()

if user_ids:
# if update is successfully saved in database reindex share and elastic too
transaction.on_commit(reindex)


def reverse(apps, schema_editor):
"""
This is a no-op since we can't restore deleted records.
"""


class Migration(migrations.Migration):
dependencies = [
('osf', '0037_notification_refactor_post_release'),
]

operations = [
migrations.RunPython(remove_orcid_from_social, reverse),
]
1 change: 0 additions & 1 deletion osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class OSFUser(DirtyFieldsMixin, GuidMixin, BaseModel, AbstractBaseUser, Permissi
# search update for all nodes to which the user is a contributor.

SOCIAL_FIELDS = {
'orcid': 'http://orcid.org/{}',
'github': 'http://github.com/{}',
'scholar': 'http://scholar.google.com/citations?user={}',
'twitter': 'http://twitter.com/{}',
Expand Down
10 changes: 0 additions & 10 deletions osf_tests/test_elastic_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,16 +1099,6 @@ def test_search_partial_special_character(self):
contribs = search.search_contributor(self.name4.split(' ')[0][:-1])
assert len(contribs['users']) == 0

def test_search_profile(self):
orcid = '123456'
user = factories.UserFactory()
user.social['orcid'] = orcid
user.save()
contribs = search.search_contributor(orcid)
assert len(contribs['users']) == 1
assert len(contribs['users'][0]['social']) == 1
assert contribs['users'][0]['social']['orcid'] == user.social_links['orcid']


@pytest.mark.enable_search
@pytest.mark.enable_enqueue_task
Expand Down
2 changes: 0 additions & 2 deletions osf_tests/test_search_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def test_search_views(self):

user_two.social = {
'profileWebsites': [f'http://me.com/{user_two.given_name}'],
'orcid': user_two.given_name,
'linkedIn': user_two.given_name,
'scholar': user_two.given_name,
'impactStory': user_two.given_name,
Expand Down Expand Up @@ -207,7 +206,6 @@ def test_search_views(self):
assert 'ssrn' not in res.json['results'][0]['social']
assert res.json['results'][0]['social']['profileWebsites'][0] == f'http://me.com/{user_two.given_name}'
assert res.json['results'][0]['social']['impactStory'] == f'https://impactstory.org/u/{user_two.given_name}'
assert res.json['results'][0]['social']['orcid'] == f'http://orcid.org/{user_two.given_name}'
assert res.json['results'][0]['social']['baiduScholar'] == f'http://xueshu.baidu.com/scholarID/{user_two.given_name}'
assert res.json['results'][0]['social']['linkedIn'] == f'https://www.linkedin.com/{user_two.given_name}'
assert res.json['results'][0]['social']['scholar'] == f'http://scholar.google.com/citations?user={user_two.given_name}'
Expand Down
14 changes: 0 additions & 14 deletions tests/identifiers/test_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,6 @@ def test_metadata_contributor_orcid(self, crossref_client, preprint):
assert contributors.find('.//{%s}ORCID' % crossref.CROSSREF_NAMESPACE).text == f'https://orcid.org/{ORCID}'
assert contributors.find('.//{%s}ORCID' % crossref.CROSSREF_NAMESPACE).attrib == {'authenticated': 'true'}

# unverified (only in profile)
contributor.external_identity = {}
contributor.social = {
'orcid': ORCID
}
contributor.save()

crossref_xml = crossref_client.build_metadata(preprint)
root = lxml.etree.fromstring(crossref_xml)
contributors = root.find('.//{%s}contributors' % crossref.CROSSREF_NAMESPACE)

# Do not send unverified ORCID to crossref
assert contributors.find('.//{%s}ORCID' % crossref.CROSSREF_NAMESPACE) is None

def test_metadata_none_license_update(self, crossref_client, preprint):
crossref_xml = crossref_client.build_metadata(preprint)
root = lxml.etree.fromstring(crossref_xml)
Expand Down
Loading