From 026cc2da671ba600c85b38fbe3e5f3e1b33899f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pavl=C3=AD=C4=8Dek?= <469355@mail.muni.cz> Date: Fri, 18 Oct 2024 18:31:03 +0200 Subject: [PATCH] fix: heuristic queries left outer join instead just left --- perun/proxygui/api/heuristic_api.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/perun/proxygui/api/heuristic_api.py b/perun/proxygui/api/heuristic_api.py index 4da2d7a1..831c38bc 100644 --- a/perun/proxygui/api/heuristic_api.py +++ b/perun/proxygui/api/heuristic_api.py @@ -81,6 +81,8 @@ class AuthEventLoggingQueries: # Basic checker if MFA was performed based on upstream_acrs value def upstream_acr_status(self, acr): + if not acr: + return None mfa_status = next((mfa for mfa in self.MFA_CONTEXTS if mfa in acr), None) return mfa_status is not None @@ -122,11 +124,18 @@ class AuthEventLoggingQueries: .join( requested_table, requested_table.c.id == auth_table.c.requested_acrs_id, + isouter=True, + ) + .join( + upstream_table, + upstream_table.c.id == auth_table.c.upstream_acrs_id, + isouter=True, ) .join( - upstream_table, upstream_table.c.id == auth_table.c.upstream_acrs_id + services_table, + services_table.c.id == auth_table.c.sp_id, + isouter=True, ) - .join(services_table, services_table.c.id == auth_table.c.sp_id) .where(auth_table.c.user_id == user_id) .distinct(auth_table.c.ip_address) ).alias("inner_query") @@ -146,7 +155,6 @@ class AuthEventLoggingQueries: ) .select_from(inner_query) .order_by(inner_query.c.day.desc()) - .limit(self.few_time_logs) ) response = cnxn.execute(outer_query).fetchall() @@ -175,9 +183,12 @@ class AuthEventLoggingQueries: .join( agents_raw_table, agents_raw_table.c.id == auth_table.c.user_agent_id, + isouter=True, ) .join( - upstream_table, upstream_table.c.id == auth_table.c.upstream_acrs_id + upstream_table, + upstream_table.c.id == auth_table.c.upstream_acrs_id, + isouter=True, ) .where(auth_table.c.user_id == user_id) .order_by(auth_table.c.day.desc()) -- GitLab