Fix contact filtering and compact workspace alerts
This commit is contained in:
@@ -12,7 +12,7 @@ import unicodedata
|
||||
import urllib.parse
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import and_, false, func, or_
|
||||
from sqlalchemy import and_, exists, false, func, or_
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
from govoplan_core.auth import ApiPrincipal
|
||||
@@ -3256,21 +3256,26 @@ def _filtered_contact_query(
|
||||
)
|
||||
if address_book_id and address_list.address_book_id != address_book_id:
|
||||
raise AddressBookError("Address list does not belong to the selected address book.")
|
||||
contact_query = contact_query.join(
|
||||
AddressListEntry,
|
||||
AddressListEntry.contact_id == Contact.id,
|
||||
).filter(AddressListEntry.address_list_id == address_list_id)
|
||||
contact_query = contact_query.filter(
|
||||
exists().where(
|
||||
AddressListEntry.contact_id == Contact.id,
|
||||
AddressListEntry.address_list_id == address_list_id,
|
||||
)
|
||||
)
|
||||
normalized_query = _trim(query)
|
||||
if normalized_query:
|
||||
pattern = f"%{normalized_query.lower()}%"
|
||||
contact_query = contact_query.outerjoin(ContactEmail).filter(
|
||||
contact_query = contact_query.filter(
|
||||
or_(
|
||||
func.lower(Contact.display_name).like(pattern),
|
||||
func.lower(Contact.organization).like(pattern),
|
||||
func.lower(ContactEmail.email).like(pattern),
|
||||
exists().where(
|
||||
ContactEmail.contact_id == Contact.id,
|
||||
func.lower(ContactEmail.email).like(pattern),
|
||||
),
|
||||
)
|
||||
)
|
||||
return contact_query.distinct()
|
||||
return contact_query
|
||||
|
||||
|
||||
def get_visible_contact(session: Session, principal: ApiPrincipal, contact_id: str, *, include_deleted: bool = False) -> Contact:
|
||||
|
||||
Reference in New Issue
Block a user