feat: allow openId to choose an unactive email if there are none active (#6041)

* feat: allow openId to choose an unactive email if there are no active ones

* chore: correct typo

* chore: rename unactive to inactive
This commit is contained in:
Robert Sparks 2023-07-25 12:15:39 -07:00 committed by GitHub
parent b24dd4427b
commit 593bdb465d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -223,7 +223,7 @@ def is_bofreq_editor(user, doc):
def openid_userinfo(claims, user):
# Populate claims dict.
person = get_object_or_404(Person, user=user)
email = person.email()
email = person.email_allowing_inactive()
if person.photo:
photo_url = person.cdn_photo_url()
else:

View file

@ -145,6 +145,14 @@ class Person(models.Model):
e = self.email_set.filter(active=True).order_by("-time").first()
self._cached_email = e
return self._cached_email
def email_allowing_inactive(self):
if not hasattr(self, "_cached_email_allowing_inactive"):
e = self.email()
if not e:
e = self.email_set.order_by("-time").first()
log.assertion(statement="e is not None", note=f"Person {self.pk} has no Email objects")
self._cached_email_allowing_inactive = e
return self._cached_email_allowing_inactive
def email_address(self):
e = self.email()
if e: