fix(user): trust an admin-saved email only while the user still holds it

Saving an unchanged email as an admin wrote email_trusted=True by id alone,
so a user who changed their email between the admin's read and that write
had the new address trusted. The trust now goes through a conditional
UPDATE matching the address the admin submitted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-11-16 21:13:33 -05:00
parent 2d6a937d4a
commit ceedecea5b
3 changed files with 54 additions and 2 deletions

View File

@@ -130,6 +130,22 @@ class DBUsersHandler(DBBaseHandler):
)
return session.scalars(select(User).filter_by(id=id)).one()
@begin_session
def trust_email(
self,
id: int,
email: str,
session: Session = INJECTED_SESSION,
) -> bool:
"""Mark the user's email trusted only if it is still `email`."""
query = self.filter(update(User), ids=[id], emails=[email])
result = session.execute(
query.values(email_trusted=True).execution_options(
synchronize_session=False
)
)
return affected_rows(result) > 0
@begin_session
def set_ra_progression(
self,