Add requester

This commit is contained in:
zandercymatics 2023-12-14 12:02:15 -07:00
parent 7b2badac05
commit 66a5af08eb
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7

View file

@ -653,15 +653,25 @@ class DomainAddUserView(DomainFormBaseView):
# created a new invitation in the database, so send an email # created a new invitation in the database, so send an email
domainInfoResults = DomainInformation.objects.filter(domain=self.object) domainInfoResults = DomainInformation.objects.filter(domain=self.object)
domainInfo = domainInfoResults.first() domainInfo = domainInfoResults.first()
first = "" first: str = ""
last = "" last: str = ""
if requester is not None: if requester is not None:
first = requester.first_name first = requester.first_name
last = requester.last_name last = requester.last_name
elif domainInfo is not None: elif domainInfo is not None:
first = domainInfo.creator.first_name first = domainInfo.creator.first_name
last = domainInfo.creator.last_name last = domainInfo.creator.last_name
else:
# This edgecase would be unusual if encountered. We don't want to handle this here. Rather, we would
# want to fix this upstream where it is happening.
raise ValueError("Can't send email. The given DomainInformation object has no requestor or creator.")
if first and last:
full_name = f"{first} {last}" full_name = f"{first} {last}"
else:
# This edgecase would be unusual if encountered. We don't want to handle this here. Rather, we would
# want to fix this upstream where it is happening.
raise ValueError("Can't send email. First and last names are none.")
try: try:
send_templated_email( send_templated_email(
@ -702,7 +712,7 @@ class DomainAddUserView(DomainFormBaseView):
def form_valid(self, form): def form_valid(self, form):
"""Add the specified user on this domain.""" """Add the specified user on this domain."""
requested_email = form.cleaned_data["email"] requested_email = form.cleaned_data["email"]
requester = None requester = self.request.user
# look up a user with that email # look up a user with that email
try: try:
requested_user = User.objects.get(email=requested_email) requested_user = User.objects.get(email=requested_email)