Skip to content

Commit

Permalink
Merge pull request #4092 from GSA-TTS/main
Browse files Browse the repository at this point in the history
  • Loading branch information
jadudm authored Jul 16, 2024
2 parents c7b2c54 + 29eb254 commit d58b70a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
24 changes: 23 additions & 1 deletion backend/audit/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
validate_auditee_certification_json,
validate_auditor_certification_json,
)
from django.contrib.admin import SimpleListFilter
from django.utils.translation import gettext_lazy as _


class SACAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -93,6 +95,26 @@ class SubmissionEventAdmin(admin.ModelAdmin):
search_fields = ("sac__report_id", "user__username")


class WaiverTypesFilter(SimpleListFilter):
title = _("Waiver Types")
parameter_name = "waiver_types"

def lookups(self, request, model_admin):
waiver_types = set(
[
waiver_type
for waiver in SacValidationWaiver.objects.all()
for waiver_type in waiver.waiver_types
]
)
return [(waiver_type, waiver_type) for waiver_type in waiver_types]

def queryset(self, request, queryset):
if self.value():
return queryset.filter(waiver_types__contains=[self.value()])
return queryset


class SacValidationWaiverAdmin(admin.ModelAdmin):
form = SacValidationWaiverForm
list_display = (
Expand All @@ -101,7 +123,7 @@ class SacValidationWaiverAdmin(admin.ModelAdmin):
"approver_email",
"requester_email",
)
list_filter = ("timestamp", "waiver_types")
list_filter = ("timestamp", WaiverTypesFilter)
search_fields = (
"report_id__report_id",
"approver_email",
Expand Down
17 changes: 17 additions & 0 deletions backend/config/db_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.core.exceptions import ImproperlyConfigured


def get_db_url_from_vcap_services(
vcap,
):
database_url = None
for db_service in vcap.get("aws-rds", []):
if db_service.get("instance_name") == "fac-db":
database_url = db_service["credentials"]["uri"]
break

if not database_url:
raise ImproperlyConfigured(
"Database URL is not properly configured. Expected 'fac-db' URL."
)
return database_url
7 changes: 6 additions & 1 deletion backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
import sys
import logging
import json
from .db_url import get_db_url_from_vcap_services
import environs
from cfenv import AppEnv
from audit.get_agency_names import get_agency_names, get_audit_info_lists

import dj_database_url
import newrelic.agent

newrelic.agent.initialize()
Expand Down Expand Up @@ -284,6 +285,10 @@
STATICFILES_STORAGE = "storages.backends.s3boto3.S3ManifestStaticStorage"
DEFAULT_FILE_STORAGE = "report_submission.storages.S3PrivateStorage"
vcap = json.loads(env.str("VCAP_SERVICES"))

DB_URL = get_db_url_from_vcap_services(vcap)
DATABASES = {"default": dj_database_url.parse(DB_URL)}

for service in vcap["s3"]:
if service["instance_name"] == "fac-public-s3":
# Public AWS S3 bucket for the app
Expand Down

0 comments on commit d58b70a

Please sign in to comment.