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-09-24 | MAIN --> PROD | DEV (79e34a5) --> STAGING #4314

Merged
merged 2 commits into from
Sep 24, 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
76 changes: 76 additions & 0 deletions backend/audit/management/commands/delete_blank_access_entries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from audit.models import (
Access,
DeletedAccess,
delete_access_and_create_record,
)

from django.core.management.base import BaseCommand

import logging
import sys


logger = logging.getLogger(__name__)


class Command(BaseCommand):
"""
Django management command for deleting Access entries with blank email
fields. A DeletedAccess entry is created for each deleted Access entry by
using audit.models.delete_access_and_create_record.
"""

def add_arguments(self, parser):
parser.add_argument(
"--count",
action="store_true",
help="Only logs the blank Access entries count without deleting",
)
parser.add_argument(
"--limit",
type=int,
help="Limits the number of blank Access entries to delete",
default=None,
)

def handle(self, *args, **options):
access_start_count = len(Access.objects.all())
logger.info(f"Access count: {access_start_count}")

deleted_access_start_count = len(DeletedAccess.objects.all())
logger.info(f"DeletedAccess count: {deleted_access_start_count}")

blank_accesses = Access.objects.filter(email="")
logger.info(f"Blank Access count: {len(blank_accesses)}")

if options.get("count"):
sys.exit(0)

limit = options.get("limit")
if limit is not None:
logger.info(f"Deletion limit: {limit}")

deleted_count = 0

for blank_access in blank_accesses:
if deleted_count == limit:
logger.info("Deletion limit reached")
break

logger.info(
f"Deleting blank Access for {blank_access.sac.report_id}, {blank_access.fullname}"
)

_, deletion_record = delete_access_and_create_record(blank_access)

logger.info(f"Created DeletedAccess {deletion_record.id}")

deleted_count += 1

logger.info(f"Deleted {deleted_count} blank Access entries")

access_finish_count = len(Access.objects.all())
logger.info(f"Final Access count: {access_finish_count}")

deleted_access_finish_count = len(DeletedAccess.objects.all())
logger.info(f"Final DeletedAccess count: {deleted_access_finish_count}")
7 changes: 6 additions & 1 deletion backend/audit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from .access import Access, remove_email_from_submission_access
from .access import (
Access,
delete_access_and_create_record,
remove_email_from_submission_access,
)
from .deleted_access import DeletedAccess
from .access_roles import ACCESS_ROLES
from .models import (
Expand Down Expand Up @@ -33,6 +37,7 @@
User,
]
_functions = [
delete_access_and_create_record,
excel_file_path,
generate_sac_report_id,
remove_email_from_submission_access,
Expand Down
2 changes: 1 addition & 1 deletion backend/cypress/e2e/accessibility.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('A11y Testing on search pages', () => {
before(() => {
cy.visit('/dissemination/search/');
cy.get('label').contains('All years').click();
cy.get('[id="search-form"]').submit();
cy.get('[id="audit-search-form"]').submit();
cy.get('tbody > :nth-child(1) > td > a')
.invoke('attr', 'href')
.as('summary_url');
Expand Down
15 changes: 10 additions & 5 deletions backend/dissemination/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
<div class="grid-col-auto audit-search-form">
<h3>Filters</h3>
<form class="usa-form"
id="search-form"
id="audit-search-form"
enctype='multipart/form-data'
method="post">
{% csrf_token %}
{% comment %} Submission {% endcomment %}
<div class="search-submit">
<input class="usa-button" type="submit" value="Search" />
<input class="usa-button"
type="submit"
value="Search"
form="audit-search-form" />
<input class="usa-button usa-button--unstyled"
type="reset"
value="Reset Search" />
Expand Down Expand Up @@ -54,7 +57,10 @@ <h3>Filters</h3>

{% comment %} Submission {% endcomment %}
<div class="search-submit">
<input class="usa-button" type="submit" value="Search" />
<input class="usa-button"
type="submit"
value="Search"
form="audit-search-form" />
<input class="usa-button usa-button--unstyled"
type="reset"
value="Reset Search" />
Expand Down Expand Up @@ -98,8 +104,7 @@ <h1 class="font-sans-2xl">Search single audit reports</h1>
{% if results_count <= summary_report_download_limit %}
<button class="usa-button display-flex"
formaction="{% url 'dissemination:MultipleSummaryReportDownload' %}"
form="search-form"
value="Search">
form="audit-search-form">
<svg class="usa-icon margin-right-1 flex-align-self-center"
aria-hidden="true"
role="img">
Expand Down
4 changes: 2 additions & 2 deletions backend/static/js/search-results.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var FORM = document.getElementById('search-form');
var FORM = document.getElementById('audit-search-form');
const pagination_links = document.querySelectorAll('[aria-label^="Page"]');
const next_page_link = document.querySelectorAll('[aria-label="Next page"]');
const search_submit_buttons = document.querySelectorAll('[type="submit"]');
Expand Down Expand Up @@ -120,7 +120,7 @@ function attachEventHandlersSorting() {
i. In this case, we wipe both the order_by and order_direction fields. Or, it will maintain the values and sort anyway.
In any case, we want to reset the page number to one.
*/
var FORM = document.getElementById('search-form');
var FORM = document.getElementById('audit-search-form');
var table_headers = document.querySelectorAll('th[id]');

table_headers.forEach((header) => {
Expand Down
Loading