Fix minor bug

This commit is contained in:
zandercymatics 2024-04-11 16:05:42 -06:00
parent 1d6c06208d
commit 61b71c298e
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 12 additions and 10 deletions

View file

@ -801,7 +801,7 @@ class WebsiteAdmin(ListHeaderAdmin):
def response_change(self, request, obj):
"""
Override to redirect users back to the same page after saving.
Override to redirect users back to the previous page after saving.
"""
superuser_perm = request.user.has_perm("registrar.full_access_permission")
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
@ -1956,19 +1956,17 @@ class DraftDomainAdmin(ListHeaderAdmin):
def response_change(self, request, obj):
"""
Override to redirect users back to the same page after saving.
Override to redirect users back to the previous page after saving.
"""
superuser_perm = request.user.has_perm("registrar.full_access_permission")
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
return_path = request.GET.get('return_path')
# Don't redirect to the website page on save if the user is an analyst.
# Rather, just redirect back to the same change page.
if analyst_perm and not superuser_perm:
opts = obj._meta
pk_value = obj._get_pk_val()
return HttpResponseRedirect(
reverse("admin:%s_%s_change" % (opts.app_label, opts.model_name), args=(pk_value,))
)
# Rather, just redirect back to the originating page.
if (analyst_perm and not superuser_perm) and return_path:
# Redirect to the return path if it exists
return HttpResponseRedirect(return_path)
return super().response_change(request, obj)