mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 19:09:22 +02:00
DraftDomain
This commit is contained in:
parent
2f7ca1de65
commit
7303f8055f
2 changed files with 91 additions and 3 deletions
|
@ -1909,6 +1909,43 @@ class DraftDomainAdmin(ListHeaderAdmin):
|
|||
# in autocomplete_fields for user
|
||||
ordering = ["name"]
|
||||
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
Return empty perms dict thus hiding the model from admin index.
|
||||
"""
|
||||
superuser_perm = request.user.has_perm("registrar.full_access_permission")
|
||||
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
|
||||
if analyst_perm and not superuser_perm:
|
||||
return {}
|
||||
return super().get_model_perms(request)
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
"""
|
||||
Allow analysts to access the change form directly via URL.
|
||||
"""
|
||||
superuser_perm = request.user.has_perm("registrar.full_access_permission")
|
||||
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
|
||||
if analyst_perm and not superuser_perm:
|
||||
return True
|
||||
return super().has_change_permission(request, obj)
|
||||
|
||||
def response_change(self, request, obj):
|
||||
"""
|
||||
Override to redirect users back to the same page after saving.
|
||||
"""
|
||||
superuser_perm = request.user.has_perm("registrar.full_access_permission")
|
||||
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
|
||||
|
||||
# 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,))
|
||||
)
|
||||
return super().response_change(request, obj)
|
||||
|
||||
|
||||
class VerifiedByStaffAdmin(ListHeaderAdmin):
|
||||
list_display = ("email", "requestor", "truncated_notes", "created_at")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue