## Purpose Allows a user to find more easily the other users they search, with the following order of priority: - users they already share documents with (more recent first) - users that share the same full email domain - ~~users that share the same partial email domain (last two parts)~~ - ~~other users~~ Edit: We need to ilter out other users in order to not reveal email addresses from members of other organisations. It's still possible to invite them by email. Solves #1521 ## Proposal - [x] Add a new function in `core/utils.py`: `users_sharing_documents_with()` - [x] Use it as a key to sort the results of a basic user search - [x] Filter user results to avoid reveal of users (and email addresses) of other orgs or that have not been interacted with. - [x] User research through "full" email address (contains the '@') is left unaffected. --------- Co-authored-by: Anthony LC <anthony.le-courric@mail.numerique.gouv.fr>
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""
|
|
Declare and configure the signals for the impress core application
|
|
"""
|
|
|
|
from functools import partial
|
|
|
|
from django.core.cache import cache
|
|
from django.db import transaction
|
|
from django.db.models import signals
|
|
from django.dispatch import receiver
|
|
|
|
from core import models
|
|
from core.tasks.search import trigger_batch_document_indexer
|
|
from core.utils import get_users_sharing_documents_with_cache_key
|
|
|
|
|
|
@receiver(signals.post_save, sender=models.Document)
|
|
def document_post_save(sender, instance, **kwargs): # pylint: disable=unused-argument
|
|
"""
|
|
Asynchronous call to the document indexer at the end of the transaction.
|
|
Note : Within the transaction we can have an empty content and a serialization
|
|
error.
|
|
"""
|
|
transaction.on_commit(partial(trigger_batch_document_indexer, instance))
|
|
|
|
|
|
@receiver(signals.post_save, sender=models.DocumentAccess)
|
|
def document_access_post_save(sender, instance, created, **kwargs): # pylint: disable=unused-argument
|
|
"""
|
|
Asynchronous call to the document indexer at the end of the transaction.
|
|
Clear cache for the affected user.
|
|
"""
|
|
if not created:
|
|
transaction.on_commit(
|
|
partial(trigger_batch_document_indexer, instance.document)
|
|
)
|
|
|
|
# Invalidate cache for the user
|
|
if instance.user:
|
|
cache_key = get_users_sharing_documents_with_cache_key(instance.user)
|
|
cache.delete(cache_key)
|
|
|
|
|
|
@receiver(signals.post_delete, sender=models.DocumentAccess)
|
|
def document_access_post_delete(sender, instance, **kwargs): # pylint: disable=unused-argument
|
|
"""
|
|
Clear cache for the affected user when document access is deleted.
|
|
"""
|
|
if instance.user:
|
|
cache_key = get_users_sharing_documents_with_cache_key(instance.user)
|
|
cache.delete(cache_key)
|