From c7544dabe2f1edddfc7651ca3e96bf82fd96b430 Mon Sep 17 00:00:00 2001 From: Rachid Mrad Date: Thu, 20 Jun 2024 12:55:42 -0400 Subject: [PATCH] Unit tests and cleanup --- src/registrar/registrar_middleware.py | 15 ++-- .../includes/domain_requests_table.html | 8 +- .../templates/includes/domains_table.html | 8 +- .../{organizations.html => organization.html} | 27 +------ .../templates/organization_domains.html | 8 ++ .../templates/organization_requests.html | 21 +++++ .../templates/organization_sidebar.html | 4 +- src/registrar/tests/test_views.py | 76 ++++++++++++++++++- src/registrar/views/index.py | 2 +- src/registrar/views/organizations.py | 12 +-- 10 files changed, 131 insertions(+), 50 deletions(-) rename src/registrar/templates/{organizations.html => organization.html} (60%) create mode 100644 src/registrar/templates/organization_domains.html create mode 100644 src/registrar/templates/organization_requests.html diff --git a/src/registrar/registrar_middleware.py b/src/registrar/registrar_middleware.py index 30137ee63..79a728310 100644 --- a/src/registrar/registrar_middleware.py +++ b/src/registrar/registrar_middleware.py @@ -14,6 +14,7 @@ from registrar.models.utility.generic_helper import replace_url_queryparams logger = logging.getLogger(__name__) + class NoCacheMiddleware: """ Middleware to add Cache-control: no-cache to every response. @@ -122,9 +123,12 @@ class CheckUserProfileMiddleware: else: # Process the view as normal return None - + + class CheckOrganizationMiddleware: """ + Checks if the current user has a portfolio + If they do, redirect them to the org homepage when they navigate to home. """ def __init__(self, get_response): @@ -137,10 +141,8 @@ class CheckOrganizationMiddleware: def process_view(self, request, view_func, view_args, view_kwargs): current_path = request.path - logger.debug(f"Current path: {current_path}") has_organization_feature_flag = flag_is_active(request, "organization_feature") - logger.debug(f"Flag is active: {has_organization_feature_flag}") if current_path == self.home: if has_organization_feature_flag: @@ -148,9 +150,10 @@ class CheckOrganizationMiddleware: user_portfolios = Portfolio.objects.filter(creator=request.user) if user_portfolios.exists(): first_portfolio = user_portfolios.first() - home_organization_with_portfolio = reverse("organization-domains", kwargs={'portfolio_id': first_portfolio.id}) - + home_organization_with_portfolio = reverse( + "organization-domains", kwargs={"portfolio_id": first_portfolio.id} + ) + if current_path != home_organization_with_portfolio: - logger.debug(f"User has portfolios, redirecting to {home_organization_with_portfolio}") return HttpResponseRedirect(home_organization_with_portfolio) return None diff --git a/src/registrar/templates/includes/domain_requests_table.html b/src/registrar/templates/includes/domain_requests_table.html index 377f49d02..e760687b6 100644 --- a/src/registrar/templates/includes/domain_requests_table.html +++ b/src/registrar/templates/includes/domain_requests_table.html @@ -2,9 +2,11 @@
-
-

Domain requests

-
+ {% if portfolio is None %} +
+

Domain requests

+
+ {% endif %}