Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-07-04 | MAIN --> PROD | DEV (414f993) --> STAGING #4056

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion backend/audit/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.contrib import admin
from django.conf import settings
from django.contrib import admin, messages
from audit.forms import SacValidationWaiverForm
from audit.models import (
Access,
DeletedAccess,
ExcelFile,
SingleAuditChecklist,
SingleAuditReportFile,
SubmissionEvent,
SacValidationWaiver,
)
from audit.validators import (
validate_auditee_certification_json,
validate_auditor_certification_json,
)


Expand Down Expand Up @@ -86,9 +93,116 @@ class SubmissionEventAdmin(admin.ModelAdmin):
search_fields = ("sac__report_id", "user__username")


class SacValidationWaiverAdmin(admin.ModelAdmin):
form = SacValidationWaiverForm
list_display = (
"report_id",
"timestamp",
"approver_email",
"requester_email",
)
list_filter = ("timestamp", "waiver_types")
search_fields = (
"report_id__report_id",
"approver_email",
"requester_email",
)
autocomplete_fields = ["report_id"]

def save_model(self, request, obj, form, change):
try:
sac = SingleAuditChecklist.objects.get(report_id=obj.report_id_id)
if sac.submission_status in [
SingleAuditChecklist.STATUS.READY_FOR_CERTIFICATION,
SingleAuditChecklist.STATUS.AUDITOR_CERTIFIED,
]:
self.handle_auditor_certification(request, obj, sac)
self.handle_auditee_certification(request, obj, sac)
else:
messages.set_level(request, messages.WARNING)
messages.warning(
request,
f"Cannot apply waiver to SAC with status {sac.submission_status}. Expected status to be one of {SingleAuditChecklist.STATUS.READY_FOR_CERTIFICATION}, {SingleAuditChecklist.STATUS.AUDITOR_CERTIFIED}",
)

super().save_model(request, obj, form, change)

except Exception as e:
messages.set_level(request, messages.ERROR)
messages.error(request, str(e))

def handle_auditor_certification(self, request, obj, sac):
if SacValidationWaiver.TYPES.AUDITOR_CERTIFYING_OFFICIAL in obj.waiver_types:
auditor_certification = sac.auditor_certification or {}
auditor_certification.update(
{
"auditor_certification": {
"is_OMB_limited": True,
"is_auditee_responsible": True,
"has_used_auditors_report": True,
"has_no_auditee_procedures": True,
"is_accurate_and_complete": True,
"is_FAC_releasable": True,
},
"auditor_signature": {
"auditor_name": settings.GSA_FAC_WAIVER,
"auditor_title": settings.GSA_FAC_WAIVER,
"auditor_certification_date_signed": obj.timestamp.strftime(
"%Y-%m-%d"
),
},
}
)
if (
sac.submission_status
== SingleAuditChecklist.STATUS.READY_FOR_CERTIFICATION
):
validated = validate_auditor_certification_json(auditor_certification)
sac.auditor_certification = validated
sac.transition_to_auditor_certified()
sac.save(
event_user=request.user,
event_type=SubmissionEvent.EventType.AUDITOR_CERTIFICATION_COMPLETED,
)

def handle_auditee_certification(self, request, obj, sac):
if SacValidationWaiver.TYPES.AUDITEE_CERTIFYING_OFFICIAL in obj.waiver_types:
auditee_certification = sac.auditee_certification or {}
auditee_certification.update(
{
"auditee_certification": {
"has_no_PII": True,
"has_no_BII": True,
"meets_2CFR_specifications": True,
"is_2CFR_compliant": True,
"is_complete_and_accurate": True,
"has_engaged_auditor": True,
"is_issued_and_signed": True,
"is_FAC_releasable": True,
},
"auditee_signature": {
"auditee_name": settings.GSA_FAC_WAIVER,
"auditee_title": settings.GSA_FAC_WAIVER,
"auditee_certification_date_signed": obj.timestamp.strftime(
"%Y-%m-%d"
),
},
}
)
if sac.submission_status == SingleAuditChecklist.STATUS.AUDITOR_CERTIFIED:
validated = validate_auditee_certification_json(auditee_certification)
sac.auditee_certification = validated
sac.transition_to_auditee_certified()
sac.save(
event_user=request.user,
event_type=SubmissionEvent.EventType.AUDITEE_CERTIFICATION_COMPLETED,
)


admin.site.register(Access, AccessAdmin)
admin.site.register(DeletedAccess, DeletedAccessAdmin)
admin.site.register(ExcelFile, ExcelFileAdmin)
admin.site.register(SingleAuditChecklist, SACAdmin)
admin.site.register(SingleAuditReportFile, AuditReportAdmin)
admin.site.register(SubmissionEvent, SubmissionEventAdmin)
admin.site.register(SacValidationWaiver, SacValidationWaiverAdmin)
20 changes: 20 additions & 0 deletions backend/audit/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django import forms
from django.contrib.postgres.forms import SimpleArrayField
from audit.models import SacValidationWaiver
from config.settings import (
AGENCY_NAMES,
GAAP_RESULTS,
Expand Down Expand Up @@ -126,3 +128,21 @@ def clean_booleans(self):

class UnlockAfterCertificationForm(forms.Form):
unlock_after_certification = forms.BooleanField()


class SacValidationWaiverForm(forms.ModelForm):
class MultiSelectArrayWidget(forms.SelectMultiple):
def __init__(self, *args, **kwargs):
choices = kwargs.pop("choices", [])
super().__init__(*args, **kwargs)
self.choices = choices

waiver_types = SimpleArrayField(
forms.ChoiceField(choices=SacValidationWaiver.WAIVER_CHOICES),
delimiter=",",
widget=MultiSelectArrayWidget(choices=SacValidationWaiver.WAIVER_CHOICES),
)

class Meta:
model = SacValidationWaiver
fields = "__all__"
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Generated by Django 5.0.4 on 2024-07-02 02:13

import django.contrib.postgres.fields
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("audit", "0008_alter_submissionevent_event"),
]

operations = [
migrations.CreateModel(
name="UeiValidationWaiver",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("uei", models.TextField(unique=True, verbose_name="UEI")),
(
"approver_email",
models.TextField(
verbose_name="Email address of FAC staff member approving the waiver"
),
),
(
"approver_name",
models.TextField(
verbose_name="Name of FAC staff member approving the waiver"
),
),
(
"requester_email",
models.TextField(
verbose_name="Email address of NSAC/KSAML requesting the waiver"
),
),
(
"requester_name",
models.TextField(
verbose_name="Name of NSAC/KSAML requesting the waiver"
),
),
(
"justification",
models.TextField(
verbose_name="Brief plain-text justification for the waiver"
),
),
],
),
migrations.CreateModel(
name="SacValidationWaiver",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"timestamp",
models.DateTimeField(
default=django.utils.timezone.now,
verbose_name="When the waiver was created",
),
),
(
"approver_email",
models.TextField(
verbose_name="Email address of FAC staff member approving the waiver"
),
),
(
"approver_name",
models.TextField(
verbose_name="Name of FAC staff member approving the waiver"
),
),
(
"requester_email",
models.TextField(
verbose_name="Email address of NSAC/KSAML requesting the waiver"
),
),
(
"requester_name",
models.TextField(
verbose_name="Name of NSAC/KSAML requesting the waiver"
),
),
(
"justification",
models.TextField(
verbose_name="Brief plain-text justification for the waiver"
),
),
(
"waiver_types",
django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(
choices=[
(
"auditee_certifying_official",
"No auditee certifying official is available",
),
(
"auditor_certifying_official",
"No auditor certifying official is available",
),
],
max_length=50,
),
default=list,
size=None,
verbose_name="The waiver type",
),
),
(
"report_id",
models.ForeignKey(
db_column="report_id",
help_text="The report that the waiver applies to",
on_delete=django.db.models.deletion.CASCADE,
to="audit.singleauditchecklist",
to_field="report_id",
),
),
],
),
]
2 changes: 2 additions & 0 deletions backend/audit/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SingleAuditChecklist,
SingleAuditChecklistManager,
SingleAuditReportFile,
SacValidationWaiver,
User,
excel_file_path,
generate_sac_report_id,
Expand All @@ -26,6 +27,7 @@
SingleAuditChecklist,
SingleAuditChecklistManager,
SingleAuditReportFile,
SacValidationWaiver,
User,
]
_functions = [
Expand Down
54 changes: 54 additions & 0 deletions backend/audit/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.contrib.postgres.fields import ArrayField

from django.utils.translation import gettext_lazy as _
from django.utils import timezone as django_timezone

from django_fsm import FSMField, RETURN_VALUE, transition

Expand Down Expand Up @@ -724,3 +725,56 @@ class UeiValidationWaiver(models.Model):
justification = models.TextField(
"Brief plain-text justification for the waiver",
)


class SacValidationWaiver(models.Model):
"""Records of reports that have had a requirement waived."""

class TYPES:
AUDITEE_CERTIFYING_OFFICIAL = "auditee_certifying_official"
AUDITOR_CERTIFYING_OFFICIAL = "auditor_certifying_official"

WAIVER_CHOICES = [
(
TYPES.AUDITEE_CERTIFYING_OFFICIAL,
"No auditee certifying official is available",
),
(
TYPES.AUDITOR_CERTIFYING_OFFICIAL,
"No auditor certifying official is available",
),
]
report_id = models.ForeignKey(
"SingleAuditChecklist",
help_text="The report that the waiver applies to",
on_delete=models.CASCADE,
to_field="report_id",
db_column="report_id",
)
timestamp = models.DateTimeField(
"When the waiver was created",
default=django_timezone.now,
)
approver_email = models.TextField(
"Email address of FAC staff member approving the waiver",
)
approver_name = models.TextField(
"Name of FAC staff member approving the waiver",
)
requester_email = models.TextField(
"Email address of NSAC/KSAML requesting the waiver",
)
requester_name = models.TextField(
"Name of NSAC/KSAML requesting the waiver",
)
justification = models.TextField(
"Brief plain-text justification for the waiver",
)
waiver_types = ArrayField(
models.CharField(
max_length=50,
choices=WAIVER_CHOICES,
),
verbose_name="The waiver type",
default=list,
)
Loading
Loading