From 7c3a3579da2a28c4509a85d1c43b7a7f236fccdb Mon Sep 17 00:00:00 2001
From: David Barnes <barnesdavidj@gmail.com>
Date: Mon, 29 Aug 2022 16:15:08 -0400
Subject: [PATCH] Add hook to auth middleware to allow users to inherit and
 override the hook to add additional ways that a user can pass the login
 required criteria.

---
 adminlte2_pdq/middleware.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/adminlte2_pdq/middleware.py b/adminlte2_pdq/middleware.py
index 0463a6f..89292c6 100644
--- a/adminlte2_pdq/middleware.py
+++ b/adminlte2_pdq/middleware.py
@@ -80,14 +80,17 @@ class AuthMiddleware:
         app_name = resolver.app_name
         current_url_name = resolver.url_name
         fully_qualified_url_name = f"{app_name}:{current_url_name}"
-        if (
+        return (
             current_url_name in LOGIN_EXEMPT_WHITELIST
             or fully_qualified_url_name in LOGIN_EXEMPT_WHITELIST
             or path in LOGIN_EXEMPT_WHITELIST
-        ):
-            return True
+            or self.login_required_hook(request)
+        )
+
 
-        # Failed all tests, return False
+    def login_required_hook(self, request):
+        """Hook that can be overridden in subclasses to add additional ways
+        to pass the login required criteria. Should return either True or False."""
         return False
 
 
-- 
GitLab