Skip to content

Commit 40dac6c

Browse files
authored
fix notable domain check (#11812)
## Ticket https://openscience.atlassian.net/browse/ENG-10340 ## Purpose Fix notable domains check ## Changes Use lower-case for comparisons
1 parent 6618441 commit 40dac6c

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

osf/external/spam/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
DOMAIN_REGEX = re.compile(r'\W*(?P<protocol>\w+://)?(?P<www>www\.)?(?P<domain>([\w-]+\.)+[a-zA-Z]+)(?P<path>[/\-\.\w]*)?\W*')
1919
REDIRECT_CODES = {301, 302, 303, 307, 308}
20-
NOTABLE_POST_NOMINALS = ['m.sc.', 'msc.', 'b.sc.', 'bsc.', 'd.sc.', 'dsc.', 'phd.', 'ph.d.', 'msc.pt', 'pt.', 'prof.', 'dr.', 'md.', 'jd.', 'esq.']
20+
NOTABLE_POST_NOMINALS = ['m.sc', 'm.sc.', 'msc.', 'b.sc.', 'bsc.', 'd.sc.', 'dsc.', 'phd.', 'ph.d.', 'msc.pt', 'pt.', 'prof.', 'dr.', 'md.', 'jd.', 'esq.']
2121

2222
@celery_app.task()
2323
def reclassify_domain_references(notable_domain_id, current_note, previous_note):

osf/models/validators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import waffle
33
from django.db.models import Q
4+
from django.db.models.functions import Lower
45
from jsonschema import ValidationError as JsonSchemaValidationError, SchemaError, Draft7Validator, validate, validators
56
from django.conf import settings
67
from django.core.validators import URLValidator, validate_email as django_validate_email
@@ -121,12 +122,13 @@ def has_domain_in_user_fields_for_names(fullname):
121122
Q(note=NotableDomain.Note.ASSUME_HAM_UNTIL_REPORTED) |
122123
Q(note=NotableDomain.Note.IGNORED)
123124
)
124-
.values_list('domain', flat=True)
125+
.annotate(domain_lower=Lower('domain'))
126+
.values_list('domain_lower', flat=True)
125127
.distinct()
126128
)
127129
for match in DOMAIN_REGEX.finditer(fullname):
128130
domain = match.group('domain')
129-
if domain in notable_domain_list:
131+
if domain.lower() in notable_domain_list:
130132
continue
131133
if looks_like_url(match):
132134
return True

osf_tests/test_validators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_validate_expand_subject_hierarchy():
5757
'fullname',
5858
[
5959
'Judith Sarah Preuss, M.Sc.',
60+
'Judith Sarah Preuss, M.Sc',
6061
'J.H. van Hateren',
6162
'Sami-Egil Ahonen',
6263
'Giovanni Luca Ciampaglia',

0 commit comments

Comments
 (0)