Add fixtures for Analysts, add domains to analyts dashboard )with search)

This commit is contained in:
rachidatecs 2023-06-27 15:47:53 -04:00
parent 100af4fd1c
commit d506e5a8e8
No known key found for this signature in database
GPG key ID: 3CEBBFA7325E5525
2 changed files with 37 additions and 7 deletions

View file

@ -56,6 +56,8 @@ class DomainAdmin(AuditedAdmin):
"""Custom domain admin class to add extra buttons.""" """Custom domain admin class to add extra buttons."""
search_fields = ["name"]
search_help_text = "Search by domain name."
change_form_template = "django/admin/domain_change_form.html" change_form_template = "django/admin/domain_change_form.html"
readonly_fields = ["state"] readonly_fields = ["state"]
@ -85,7 +87,6 @@ class ContactAdmin(AuditedAdmin):
"""Custom contact admin class to add search.""" """Custom contact admin class to add search."""
search_fields = ["email", "first_name", "last_name"] search_fields = ["email", "first_name", "last_name"]
search_help_text = "Search by firstname, lastname or email." search_help_text = "Search by firstname, lastname or email."
@ -94,13 +95,9 @@ class DomainApplicationAdmin(AuditedAdmin):
"""Customize the applications listing view.""" """Customize the applications listing view."""
list_display = ["requested_domain", "status", "organization_type", "created_at", "submitter", "investigator"] list_display = ["requested_domain", "status", "organization_type", "created_at", "submitter", "investigator"]
list_filter = ('status', "organization_type", "investigator") list_filter = ('status', "organization_type", "investigator")
search_fields = ["requested_domain__name", "submitter__email", "submitter__first_name", "submitter__last_name"] search_fields = ["requested_domain__name", "submitter__email", "submitter__first_name", "submitter__last_name"]
search_help_text = "Search by domain or submitter." search_help_text = "Search by domain or submitter."
fieldsets = [ fieldsets = [
(None, {"fields": ["status", "investigator", "creator"]}), (None, {"fields": ["status", "investigator", "creator"]}),
("Type of organization", {"fields": ["organization_type", "federally_recognized_tribe", "state_recognized_tribe", "tribe_name", "federal_agency", "federal_type", "is_election_board", "type_of_work", "more_organization_information"]}), ("Type of organization", {"fields": ["organization_type", "federally_recognized_tribe", "state_recognized_tribe", "tribe_name", "federal_agency", "federal_type", "is_election_board", "type_of_work", "more_organization_information"]}),
@ -115,6 +112,7 @@ class DomainApplicationAdmin(AuditedAdmin):
("Anything else we should know?", {"fields": ["anything_else"]}), ("Anything else we should know?", {"fields": ["anything_else"]}),
("Requirements for operating .gov domains", {"fields": ["is_policy_acknowledged"]}), ("Requirements for operating .gov domains", {"fields": ["is_policy_acknowledged"]}),
] ]
readonly_fields = ["creator", "type_of_work", "more_organization_information", "address_line1", "address_line2", "zipcode", "requested_domain", "alternative_domains", "purpose", "submitter", "no_other_contacts_rationale", "anything_else", "is_policy_acknowledged"]
# Trigger action when a fieldset is changed # Trigger action when a fieldset is changed
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
@ -135,8 +133,6 @@ class DomainApplicationAdmin(AuditedAdmin):
super().save_model(request, obj, form, change) super().save_model(request, obj, form, change)
readonly_fields = ["creator", "type_of_work", "more_organization_information", "address_line1", "address_line2", "zipcode", "requested_domain", "alternative_domains", "purpose", "submitter", "no_other_contacts_rationale", "anything_else", "is_policy_acknowledged"]
def get_readonly_fields(self, request, obj=None): def get_readonly_fields(self, request, obj=None):
if request.user.is_superuser: if request.user.is_superuser:
# Superusers have full access, no fields are read-only # Superusers have full access, no fields are read-only

View file

@ -10,6 +10,8 @@ from registrar.models import (
Website, Website,
) )
from django.contrib.auth.models import Permission
fake = Faker() fake = Faker()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -51,6 +53,14 @@ class UserFixture:
}, },
] ]
STAFF = [
{
"username": "319c490d-453b-43d9-bc4d-7d6cd8ff6844",
"first_name": "Rachid-Analyst",
"last_name": "Mrad-Analyst",
},
]
@classmethod @classmethod
def load(cls): def load(cls):
logger.info("Going to load %s users" % str(len(cls.ADMINS))) logger.info("Going to load %s users" % str(len(cls.ADMINS)))
@ -68,6 +78,30 @@ class UserFixture:
logger.debug("User object created for %s" % admin["first_name"]) logger.debug("User object created for %s" % admin["first_name"])
except Exception as e: except Exception as e:
logger.warning(e) logger.warning(e)
for staff in cls.STAFF:
try:
user, _ = User.objects.get_or_create(
username=staff["username"],
)
user.is_superuser = False
user.first_name = admin["first_name"]
user.last_name = admin["last_name"]
user.is_staff = True
user.is_active = True
# CISA ANALYST permissions
# id 24 = codename view_logentry (auditlog)
# id 32 = codename view_contact
# id 38 = codename change_domainapplication
# id 44 = codename view_domain
permission_ids = [24, 32, 38, 44] # List of permission IDs to assign
# Retrieve the corresponding permission objects
permissions = Permission.objects.filter(id__in=permission_ids)
# Add the permissions to the user
user.user_permissions.add(*permissions)
user.save()
logger.debug("User object created for %s" % admin["first_name"])
except Exception as e:
logger.warning(e)
logger.debug("All users loaded.") logger.debug("All users loaded.")