manager: search deleted users by email (#51808)

This commit is contained in:
Benjamin Dauvergne 2021-03-09 23:02:23 +01:00
parent e77c98b57b
commit 5e29c79224
2 changed files with 12 additions and 3 deletions

View File

@ -19,15 +19,17 @@ import uuid
from django import forms
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied, ValidationError
from django.core.validators import EmailValidator
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from authentic2.apps.journal.forms import JournalForm
from authentic2.apps.journal.models import EventType
from authentic2.apps.journal.models import EventType, n_2_pairing
from authentic2.apps.journal.search_engine import JournalSearchEngine
from authentic2.apps.journal.views import JournalView
from authentic2.custom_user.models import DeletedUser
from . import views
@ -71,6 +73,13 @@ to user whose UUID is <tt>1234</tt>.'''
users = User.objects.find_duplicates(fullname=fullname)
return self.query_for_users(users)
def search_by_email(self, email):
yield from super().search_by_email(email)
pks = list(DeletedUser.objects.filter(old_email=email).values_list('old_user_id', flat=True))
yield Q(user_id__in=pks)
user_ct = ContentType.objects.get_for_model(User)
yield Q(reference_ids__contains=[n_2_pairing(user_ct.id, pk) for pk in pks])
EVENT_TYPE_CHOICES = (
('', _('All')),

View File

@ -993,14 +993,14 @@ def test_search(app, superuser, events):
response.form.set('search', 'email:jane@example.com')
response = response.form.submit()
assert (
text_content(response.pyquery('tbody tr td.journal-list--message-column')[0]).strip()
text_content(response.pyquery('tbody tr td.journal-list--message-column')[12]).strip()
== 'email change of user "Johnny doe" for email address "jane@example.com"'
)
response.form.set('search', 'jane@example.com')
response = response.form.submit()
assert (
text_content(response.pyquery('tbody tr td.journal-list--message-column')[0]).strip()
text_content(response.pyquery('tbody tr td.journal-list--message-column')[12]).strip()
== 'email change of user "Johnny doe" for email address "jane@example.com"'
)