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-16 | MAIN --> PROD | DEV (29eb254) --> STAGING #4092

Merged
merged 2 commits into from
Jul 16, 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
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
Loading