Provide core filters for GUI fast profile state to use

This commit is contained in:
SimplifiedPrivacy 2026-11-05 15:30:07 -05:00
parent 920ba56403
commit 4afbcd02a7
2 changed files with 52 additions and 1 deletions

View file

@ -2,7 +2,7 @@ from core.services.payment_phase.payment_state import PaymentData
from core.models.BaseProfile import BaseProfile as Profile from core.models.BaseProfile import BaseProfile as Profile
from core.models.orm_models.Plan import Plan 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.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.enum_models import ProtocolChoice, Currency
from core.models.orm_models.Location import Location from core.models.orm_models.Location import Location
from core.errors.logger import logger 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 PLANS_TO_RETURN[plan_format] = each_plan.id
return Result(valid=True, data=PLANS_TO_RETURN) 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

View file

@ -38,3 +38,13 @@ def protocol_matches_profile_type(protocol: ProtocolChoice, profile_type: Profil
else: else:
logger.error(f"Invalid protocol choice {protocol}") logger.error(f"Invalid protocol choice {protocol}")
return False 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