From 4afbcd02a7748978741478dd36fb0fa952277a08 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Thu, 5 Nov 2026 15:30:07 -0500 Subject: [PATCH] Provide core filters for GUI fast profile state to use --- .../controllers/profile_state/data_filters.py | 43 ++++++++++++++++++- ...lter_protocols.py => attribute_filters.py} | 10 +++++ 2 files changed, 52 insertions(+), 1 deletion(-) rename core/services/profiles/{filter_protocols.py => attribute_filters.py} (79%) diff --git a/core/controllers/profile_state/data_filters.py b/core/controllers/profile_state/data_filters.py index f88ac51..7fae995 100644 --- a/core/controllers/profile_state/data_filters.py +++ b/core/controllers/profile_state/data_filters.py @@ -2,7 +2,7 @@ from core.services.payment_phase.payment_state import PaymentData from core.models.BaseProfile import BaseProfile as Profile from core.models.orm_models.Plan import Plan from core.models.orm_calls.model_neutral_tools import get_all_for_model -from core.models.orm_calls.location_calls import get_profile_location_data +from core.models.orm_calls.location_calls import get_profile_location_data, get_profile_location_data_by_id from core.models.enum_models import ProtocolChoice, Currency from core.models.orm_models.Location import Location from core.errors.logger import logger @@ -106,3 +106,44 @@ def get_all_plans_by_protocol(chosen_protocol: ProtocolChoice) -> Result: PLANS_TO_RETURN[plan_format] = each_plan.id return Result(valid=True, data=PLANS_TO_RETURN) + + +def get_supported_protocols_by_location_id(location_id: int) -> Result: + """Get a list of valid protocols supported by a given location by id.""" + + if not location_id or not isinstance(location_id, int): + error_msg = f"This is a developer error. Invalid format for location id {location_id}" + logger.error(error_msg) + return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg) + + # this is doing sql: + location = get_profile_location_data_by_id(location_id=location_id) + + if not location: + error_msg = f"This is a developer error. No location data found for {location_id}" + logger.error(error_msg) + return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=error_msg) + + # this is NOT doing sql + supported_protocols = _get_supported_protocols_for_location(location=location, as_strings=True) + + return Result(valid=True, data=supported_protocols) + + +def protocol_is_supported_for_location(location_id: int, protocol_choice: ProtocolChoice) -> bool: + """Returns a boolean value for if a selected location is supported. Note: This does SQL""" + support_result = get_supported_protocols_by_location_id(location_id) + if not support_result.valid: + logger.error("Could not get a list of supported locations") + logger.error(support_result.message) + logger.error(support_result.error_type) + return False + + list_of_supported_protocols = support_result.data + + logger.info(f"Checking if protocol_choice {protocol_choice.value} is supported in the list of {list_of_supported_protocols}") + + if protocol_choice.value in list_of_supported_protocols: + return True + else: + return False diff --git a/core/services/profiles/filter_protocols.py b/core/services/profiles/attribute_filters.py similarity index 79% rename from core/services/profiles/filter_protocols.py rename to core/services/profiles/attribute_filters.py index 3f20fb0..966c56f 100644 --- a/core/services/profiles/filter_protocols.py +++ b/core/services/profiles/attribute_filters.py @@ -38,3 +38,13 @@ def protocol_matches_profile_type(protocol: ProtocolChoice, profile_type: Profil else: logger.error(f"Invalid protocol choice {protocol}") return False + + +def app_or_display_matches_profile_type(app_choice: int, profile_type: ProfileType) -> bool: + """Check that a browser/app or display is applicable for a given profile type.""" + if profile_type == ProfileType.SESSION: + return True + elif profile_type == ProfileType.SYSTEM: + return False + else: + return False