mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 17:28:31 +02:00
Add requester
This commit is contained in:
parent
b657db8821
commit
7b2badac05
1 changed files with 10 additions and 6 deletions
|
@ -644,7 +644,7 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
"""Get an absolute URL for this domain."""
|
||||
return self.request.build_absolute_uri(reverse("domain", kwargs={"pk": self.object.id}))
|
||||
|
||||
def _send_domain_invitation_email(self, email: str, add_success=True):
|
||||
def _send_domain_invitation_email(self, email: str, requester: User, add_success=True):
|
||||
"""Performs the sending of the domain invitation email,
|
||||
does not make a domain information object
|
||||
email: string- email to send to
|
||||
|
@ -655,7 +655,10 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
domainInfo = domainInfoResults.first()
|
||||
first = ""
|
||||
last = ""
|
||||
if domainInfo is not None:
|
||||
if requester is not None:
|
||||
first = requester.first_name
|
||||
last = requester.last_name
|
||||
elif domainInfo is not None:
|
||||
first = domainInfo.creator.first_name
|
||||
last = domainInfo.creator.last_name
|
||||
full_name = f"{first} {last}"
|
||||
|
@ -683,7 +686,7 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
if add_success:
|
||||
messages.success(self.request, f"Invited {email} to this domain.")
|
||||
|
||||
def _make_invitation(self, email_address: str):
|
||||
def _make_invitation(self, email_address: str, requester: User):
|
||||
"""Make a Domain invitation for this email and redirect with a message."""
|
||||
invitation, created = DomainInvitation.objects.get_or_create(email=email_address, domain=self.object)
|
||||
if not created:
|
||||
|
@ -693,21 +696,22 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
f"{email_address} has already been invited to this domain.",
|
||||
)
|
||||
else:
|
||||
self._send_domain_invitation_email(email=email_address)
|
||||
self._send_domain_invitation_email(email=email_address, requester=requester)
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Add the specified user on this domain."""
|
||||
requested_email = form.cleaned_data["email"]
|
||||
requester = None
|
||||
# look up a user with that email
|
||||
try:
|
||||
requested_user = User.objects.get(email=requested_email)
|
||||
except User.DoesNotExist:
|
||||
# no matching user, go make an invitation
|
||||
return self._make_invitation(requested_email)
|
||||
return self._make_invitation(requested_email, requester)
|
||||
else:
|
||||
# if user already exists then just send an email
|
||||
self._send_domain_invitation_email(requested_email, add_success=False)
|
||||
self._send_domain_invitation_email(requested_email, requester, add_success=False)
|
||||
|
||||
try:
|
||||
UserDomainRole.objects.create(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue