From b396695721dab8e054f2624fca34e23b1f3549ca Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Sun, 8 Nov 2026 18:40:33 -0500 Subject: [PATCH] Edit warnings and respawn --- core/services/config_tools/config_manager.py | 1 + core/services/payment_phase/ticket_cycle.py | 32 ++++++++++++++++++++ core/services/profiles/create_objects.py | 10 ++++-- core/services/profiles/model_manipulator.py | 3 ++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/core/services/config_tools/config_manager.py b/core/services/config_tools/config_manager.py index b3f55fa..7e0438b 100644 --- a/core/services/config_tools/config_manager.py +++ b/core/services/config_tools/config_manager.py @@ -1,3 +1,4 @@ +from core.services.config_tools.manage_sudo_configs import remove_sudo_config from core.services.WebServiceApiService import WebServiceApiService from core.observers.ConnectionObserver import ConnectionObserver from core.controllers.ConnectionController import ConnectionController diff --git a/core/services/payment_phase/ticket_cycle.py b/core/services/payment_phase/ticket_cycle.py index 85601d5..a6179bc 100644 --- a/core/services/payment_phase/ticket_cycle.py +++ b/core/services/payment_phase/ticket_cycle.py @@ -1,3 +1,4 @@ +from core.controllers.ProfileController import ProfileController from core.services.subscriptions.subscriptions_by_protocol import wipe_billing_cycle from core.services.payment_phase.payment_state import OverallPaymentCycle, TicketPaymentData from core.controllers.ConfigurationController import ConfigurationController @@ -41,3 +42,34 @@ def wipe_ticket_cycle() -> Result: return Result(valid=True) else: return Result(valid=False, error_type=ResultError.FILE_SYSTEM, message="Unable to wipe ticket billing cycle.") + + +def profile_can_respawn(profile_id: int) -> Result: + """Check if a given profile can respawn""" + + # Get profile object: + profile = ProfileController.get(profile_id) + + logger.info(f"profile is {profile}") + + if not profile: + error_msg = f"Invalid profile id of {profile_id}" + logger.error(error_msg) + return Result(valid=False, message=error_msg, error_type=ResultError.INVALID_INPUT) + + if not profile.subscription: + error_msg = "This profile can not respawn, it lacks a subscription" + logger.info(error_msg) + return Result(valid=False, message=error_msg, error_type=ResultError.SUBSCRIPTION) + + if not ConfigurationController.are_tickets_setup(): + error_msg = "Tickets are not setup yet." + logger.info(error_msg) + return Result(valid=False, message=error_msg, error_type=ResultError.TICKET_SETUP) + + if not profile.ticket: + error_msg = f"This profile can not respawn, it lacks a ticket. ticket is {profile.ticket}" + logger.info(error_msg) + return Result(valid=False, message=error_msg, error_type=ResultError.NO_TICKET) + + return Result(valid=True) \ No newline at end of file diff --git a/core/services/profiles/create_objects.py b/core/services/profiles/create_objects.py index 6d35266..e7b6cda 100644 --- a/core/services/profiles/create_objects.py +++ b/core/services/profiles/create_objects.py @@ -41,6 +41,7 @@ def create_session_object( protocol: ProtocolChoice, location: Location, name: str, + ticket: int|None, application: Optional[ApplicationVersion] = None, subscription: Optional[Subscription] = None ) -> Result: @@ -63,6 +64,7 @@ def create_session_object( id=profile_id, name=name, subscription=subscription, + ticket=ticket, type=ProfileType.SESSION, location=location, protocol=protocol, @@ -80,6 +82,7 @@ def create_system_object( protocol: ProtocolChoice, location: Location, name: str, + ticket: int|None, subscription: Optional[Subscription] = None ) -> Result: """Return a SessionProfile object""" @@ -90,6 +93,7 @@ def create_system_object( type=ProfileType.SYSTEM, protocol=protocol, subscription=subscription, + ticket=ticket, location=location, connection=connection ) @@ -105,7 +109,7 @@ def create_new_profile_object(profile_id: int, potential_data: dict) -> Result: #--------------------------- profile_type = potential_data.get('type', None) protocol = potential_data.get('protocol', None) - + ticket = potential_data.get('ticket', None) raw_location = potential_data.get('location', None) # already a location id: @@ -137,13 +141,13 @@ def create_new_profile_object(profile_id: int, potential_data: dict) -> Result: # SESSION #--------------------------- if profile_type == ProfileType.SESSION: - return create_session_object(profile_id=profile_id, potential_data=potential_data, protocol=protocol, location=location, name=name) + return create_session_object(profile_id=profile_id, potential_data=potential_data, protocol=protocol, location=location, name=name, ticket=ticket) #--------------------------- # SYSTEM #--------------------------- elif profile_type == ProfileType.SYSTEM: - return create_system_object(profile_id=profile_id, potential_data=potential_data, protocol=protocol, location=location, name=name) + return create_system_object(profile_id=profile_id, potential_data=potential_data, protocol=protocol, location=location, name=name, ticket=ticket) #--------------------------- # OTHER diff --git a/core/services/profiles/model_manipulator.py b/core/services/profiles/model_manipulator.py index 78b1d91..36366e9 100644 --- a/core/services/profiles/model_manipulator.py +++ b/core/services/profiles/model_manipulator.py @@ -159,6 +159,7 @@ def create_profile_object_from_disk(profile_id: int) -> Result: # SUBSCRIPTION #======================================================== subscription = make_subscription_from_config(config_contents) + ticket = config_contents.get("ticket", None) #======================================================== # PROFILE TYPE @@ -179,6 +180,7 @@ def create_profile_object_from_disk(profile_id: int) -> Result: protocol=protocol, location=location, name=name, + ticket=ticket, subscription=subscription ) @@ -196,6 +198,7 @@ def create_profile_object_from_disk(profile_id: int) -> Result: protocol=protocol, location=location, name=name, + ticket=ticket, application=application, subscription=subscription )