From 072bb3e62b48e5268e6a3ed2e476bb3b67a11b90 Mon Sep 17 00:00:00 2001 From: Bohdan Odintsov Date: Thu, 16 Jul 2026 11:55:16 +0300 Subject: [PATCH] fix notable domain check --- osf/external/spam/tasks.py | 2 +- osf/models/validators.py | 6 ++++-- osf_tests/test_validators.py | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osf/external/spam/tasks.py b/osf/external/spam/tasks.py index 8c175831254..56f7f16aa2d 100644 --- a/osf/external/spam/tasks.py +++ b/osf/external/spam/tasks.py @@ -17,7 +17,7 @@ DOMAIN_REGEX = re.compile(r'\W*(?P\w+://)?(?Pwww\.)?(?P([\w-]+\.)+[a-zA-Z]+)(?P[/\-\.\w]*)?\W*') REDIRECT_CODES = {301, 302, 303, 307, 308} -NOTABLE_POST_NOMINALS = ['m.sc.', 'msc.', 'b.sc.', 'bsc.', 'd.sc.', 'dsc.', 'phd.', 'ph.d.', 'msc.pt', 'pt.', 'prof.', 'dr.', 'md.', 'jd.', 'esq.'] +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.'] @celery_app.task() def reclassify_domain_references(notable_domain_id, current_note, previous_note): diff --git a/osf/models/validators.py b/osf/models/validators.py index 8411731d788..63c1afdac07 100644 --- a/osf/models/validators.py +++ b/osf/models/validators.py @@ -1,6 +1,7 @@ import re import waffle from django.db.models import Q +from django.db.models.functions import Lower from jsonschema import ValidationError as JsonSchemaValidationError, SchemaError, Draft7Validator, validate, validators from django.conf import settings 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): Q(note=NotableDomain.Note.ASSUME_HAM_UNTIL_REPORTED) | Q(note=NotableDomain.Note.IGNORED) ) - .values_list('domain', flat=True) + .annotate(domain_lower=Lower('domain')) + .values_list('domain_lower', flat=True) .distinct() ) for match in DOMAIN_REGEX.finditer(fullname): domain = match.group('domain') - if domain in notable_domain_list: + if domain.lower() in notable_domain_list: continue if looks_like_url(match): return True diff --git a/osf_tests/test_validators.py b/osf_tests/test_validators.py index 7e9baa86d72..deca8f1d293 100644 --- a/osf_tests/test_validators.py +++ b/osf_tests/test_validators.py @@ -57,6 +57,7 @@ def test_validate_expand_subject_hierarchy(): 'fullname', [ 'Judith Sarah Preuss, M.Sc.', + 'Judith Sarah Preuss, M.Sc', 'J.H. van Hateren', 'Sami-Egil Ahonen', 'Giovanni Luca Ciampaglia',