mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-27 21:16:28 +02:00
in django admin, new domain invitations are auto retrieved when user exists
This commit is contained in:
parent
1e12459c10
commit
08efc6629e
2 changed files with 78 additions and 9 deletions
|
@ -1434,6 +1434,26 @@ class DomainInvitationAdmin(ListHeaderAdmin):
|
|||
# Get the filtered values
|
||||
return super().changelist_view(request, extra_context=extra_context)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
"""
|
||||
Override the save_model method.
|
||||
|
||||
On creation of a new domain invitation, attempt to retrieve the invitation,
|
||||
which will be successful if a user exists for that email; otherwise, will
|
||||
raise a RuntimeError, and in this case can continue to create the invitation.
|
||||
"""
|
||||
# NOTE: is a future ticket accounting for a 'not member of this org' scenario
|
||||
# to mirror the logic in DomainAddUser view?
|
||||
if not change: # Domain Invitation creation
|
||||
try:
|
||||
User.objects.get(email=obj.email)
|
||||
obj.retrieve()
|
||||
except User.DoesNotExist:
|
||||
# Proceed with invitation as new as exception indicates user does not exist
|
||||
pass
|
||||
# Call the parent save method to save the object
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
|
||||
class PortfolioInvitationAdmin(ListHeaderAdmin):
|
||||
"""Custom portfolio invitation admin class."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue