lint, clean up tests, clean up user displays in admin (remove is_staff and is_superuser and replace with group)

This commit is contained in:
Rachid Mrad 2023-09-29 16:54:29 -04:00
parent 8db5219986
commit 11c0186b09
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
2 changed files with 12 additions and 13 deletions

View file

@ -138,8 +138,8 @@ class MyUserAdmin(BaseUserAdmin):
"first_group", "first_group",
"status", "status",
) )
# First group (which should by theory be the only group) # First group (which should in theory be the ONLY group)
def first_group(self, obj): def first_group(self, obj):
return f"{obj.groups.first()}" return f"{obj.groups.first()}"
@ -195,8 +195,6 @@ class MyUserAdmin(BaseUserAdmin):
"email", "email",
"Permissions", "Permissions",
"is_active", "is_active",
"is_staff",
"is_superuser",
"groups", "groups",
"Important dates", "Important dates",
"last_login", "last_login",
@ -217,8 +215,7 @@ class MyUserAdmin(BaseUserAdmin):
"email", "email",
"first_name", "first_name",
"last_name", "last_name",
"is_staff", "first_group",
"is_superuser",
"status", "status",
) )
@ -840,7 +837,9 @@ class DomainAdmin(ListHeaderAdmin):
# Fixes a bug wherein users which are only is_staff # Fixes a bug wherein users which are only is_staff
# can access 'change' when GET, # can access 'change' when GET,
# but cannot access this page when it is a request of type POST. # but cannot access this page when it is a request of type POST.
if request.user.is_staff: if request.user.has_perm(
"registrar.full_access_permission"
) or request.user.has_perm("registrar.analyst_access_permission"):
return True return True
return super().has_change_permission(request, obj) return super().has_change_permission(request, obj)

View file

@ -18,6 +18,7 @@ from registrar.models import (
DomainInformation, DomainInformation,
User, User,
DomainInvitation, DomainInvitation,
UserGroup,
) )
from .common import ( from .common import (
completed_application, completed_application,
@ -51,7 +52,7 @@ class TestDomainAdmin(MockEppLib):
self.staffuser = create_user() self.staffuser = create_user()
super().setUp() super().setUp()
@skip("EPP sabotage") @skip("Why did this test stop working, and is is a good test")
def test_place_and_remove_hold(self): def test_place_and_remove_hold(self):
domain = create_ready_domain() domain = create_ready_domain()
# get admin page and assert Place Hold button # get admin page and assert Place Hold button
@ -61,7 +62,7 @@ class TestDomainAdmin(MockEppLib):
"/admin/registrar/domain/{}/change/".format(domain.pk), "/admin/registrar/domain/{}/change/".format(domain.pk),
follow=True, follow=True,
) )
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertContains(response, domain.name) self.assertContains(response, domain.name)
self.assertContains(response, "Place hold") self.assertContains(response, "Place hold")
self.assertNotContains(response, "Remove hold") self.assertNotContains(response, "Remove hold")
@ -786,8 +787,7 @@ class MyUserAdminTest(TestCase):
"email", "email",
"first_name", "first_name",
"last_name", "last_name",
"is_staff", "first_group",
"is_superuser",
"status", "status",
) )
@ -801,14 +801,14 @@ class MyUserAdminTest(TestCase):
expected_fieldsets = super(MyUserAdmin, self.admin).get_fieldsets(request) expected_fieldsets = super(MyUserAdmin, self.admin).get_fieldsets(request)
self.assertEqual(fieldsets, expected_fieldsets) self.assertEqual(fieldsets, expected_fieldsets)
def test_get_fieldsets_non_superuser(self): def test_get_fieldsets_cisa_analyst(self):
request = self.client.request().wsgi_request request = self.client.request().wsgi_request
request.user = create_user() request.user = create_user()
fieldsets = self.admin.get_fieldsets(request) fieldsets = self.admin.get_fieldsets(request)
expected_fieldsets = ( expected_fieldsets = (
(None, {"fields": ("password", "status")}), (None, {"fields": ("password", "status")}),
("Personal Info", {"fields": ("first_name", "last_name", "email")}), ("Personal Info", {"fields": ("first_name", "last_name", "email")}),
("Permissions", {"fields": ("is_active", "is_staff", "is_superuser")}), ("Permissions", {"fields": ("is_active", "groups")}),
("Important dates", {"fields": ("last_login", "date_joined")}), ("Important dates", {"fields": ("last_login", "date_joined")}),
) )
self.assertEqual(fieldsets, expected_fieldsets) self.assertEqual(fieldsets, expected_fieldsets)