SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 2e7eaac6 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

feat: :goal: check that author matched profile duplicates are not fellows

parent a6d74210
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,9 @@ __copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.contrib import messages
from django.contrib.auth.decorators import login_required, user_passes_test
from django.db.models import Q
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse
......@@ -128,9 +130,24 @@ def _hx_author_profile_action(
)
if action == "match":
profile = get_object_or_404(Profile, pk=profile_id)
author_profile.profile = profile
# add Submission's topics to profile:
profile.topics.add(*submission.topics.all())
potential_duplicate_fellow = (
Profile.objects.potential_duplicates_of(profile)
.annotate(is_fellow=Q(contributor__fellowships__isnull=False))
.first()
)
if potential_duplicate_fellow:
messages.error(
request,
"This profile has potential duplicates which belong to Fellows. Please "
f'<a href="{reverse("profiles:duplicates", args=(profile.id, potential_duplicate_fellow.id))}">resolve the duplicates</a> '
"before matching. ",
)
author_profile.profile = None
else:
author_profile.profile = profile
# add Submission's topics to profile:
profile.topics.add(*submission.topics.all())
elif action == "unmatch":
author_profile.profile = None
author_profile.save()
......
......@@ -89,6 +89,24 @@ class ProfileQuerySet(QuerySet):
| Q(id__in=ids_of_duplicates_by_email)
).order_by("last_name", "first_name", "-id")
def potential_duplicates_of(self, profile: "Profile"):
"""
Returns only potential duplicate Profiles of the specified Profile.
"""
from profiles.models import ProfileNonDuplicates
profile_non_duplicates = ProfileNonDuplicates.objects.filter(
id__in=profile.profilenonduplicates_set.values("id")
).values_list("profiles", flat=True)
qs = self.filter(
Q(first_name__unaccent__icontains=profile.first_name)
& Q(last_name__unaccent__icontains=profile.last_name)
| Q(emails__email__in=profile.emails.values("email"))
).exclude(Q(id__in=profile_non_duplicates) | Q(id=profile.id))
return qs
def specialties_overlap(self, specialties_slug_list):
"""
Returns all Profiles whose specialties overlap with those specified in the slug list.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment