fix: person_detail prefers user with person_id link over name match
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Prevents showing gmail account when inpi.pl account exists. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c91dfb5736
commit
b045cede3d
@ -371,24 +371,30 @@ def person_detail(person_id):
|
||||
Company.name
|
||||
).all()
|
||||
|
||||
# Try to find matching user account by name (for portal data)
|
||||
# This is a simple match - in production might need more sophisticated matching
|
||||
portal_user = None
|
||||
name_parts = person.full_name().upper().split()
|
||||
if len(name_parts) >= 2:
|
||||
# Try to find user where first/last name matches
|
||||
potential_users = db.query(User).filter(
|
||||
User.name.isnot(None)
|
||||
).all()
|
||||
for u in potential_users:
|
||||
if u.name:
|
||||
user_name_parts = u.name.upper().split()
|
||||
# Check if at least first and last name match
|
||||
if len(user_name_parts) >= 2:
|
||||
if (user_name_parts[-1] in name_parts and # Last name match
|
||||
any(part in user_name_parts for part in name_parts[:-1])): # First name match
|
||||
portal_user = u
|
||||
break
|
||||
# Find matching user account - prefer direct person_id link, then name match
|
||||
portal_user = db.query(User).filter(
|
||||
User.person_id == person_id
|
||||
).first()
|
||||
|
||||
if not portal_user:
|
||||
name_parts = person.full_name().upper().split()
|
||||
if len(name_parts) >= 2:
|
||||
candidates = []
|
||||
for u in db.query(User).filter(User.name.isnot(None)).all():
|
||||
if u.name:
|
||||
user_name_parts = u.name.upper().split()
|
||||
if len(user_name_parts) >= 2:
|
||||
if (user_name_parts[-1] in name_parts and
|
||||
any(part in user_name_parts for part in name_parts[:-1])):
|
||||
candidates.append(u)
|
||||
if candidates:
|
||||
# Prefer user with person_id set, then non-gmail accounts
|
||||
candidates.sort(key=lambda u: (
|
||||
0 if u.person_id else 1,
|
||||
0 if not u.email.endswith('@gmail.com') else 1,
|
||||
u.id,
|
||||
))
|
||||
portal_user = candidates[0]
|
||||
|
||||
return render_template('person_detail.html',
|
||||
person=person,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user