update: updated ticketing logic from gui
This commit is contained in:
parent
6e074482ab
commit
0cc496a40b
5 changed files with 46 additions and 99 deletions
0
gui/v2/actions/disable_profiles.py
Normal file → Executable file
0
gui/v2/actions/disable_profiles.py
Normal file → Executable file
|
|
@ -1,35 +0,0 @@
|
|||
def location_candidates(profile, preferred=None):
|
||||
candidates = []
|
||||
seen = set()
|
||||
|
||||
def add(val):
|
||||
if val is None:
|
||||
return
|
||||
s = str(val).strip().lower().replace(' ', '_')
|
||||
if s and s not in seen:
|
||||
seen.add(s)
|
||||
candidates.append(s)
|
||||
|
||||
if preferred:
|
||||
add(preferred)
|
||||
|
||||
sources = []
|
||||
try:
|
||||
if profile and profile.connection and profile.connection.location:
|
||||
sources.append(profile.connection.location)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if profile and profile.location:
|
||||
sources.append(profile.location)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for source in sources:
|
||||
add(getattr(source, 'id', None))
|
||||
add(getattr(source, 'country_name', None))
|
||||
add(getattr(source, 'name', None))
|
||||
add(getattr(source, 'code', None))
|
||||
add(getattr(source, 'country_code', None))
|
||||
|
||||
return candidates
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
from PyQt6.QtWidgets import QLabel, QListWidget, QListWidgetItem, QPushButton
|
||||
from PyQt6 import QtCore
|
||||
|
||||
from core.controllers.ProfileController import ProfileController
|
||||
from core.controllers.tickets.UseTicketController import get_unused_tickets
|
||||
|
||||
from gui.v2.actions.locations import location_candidates
|
||||
from gui.v2.infrastructure.setup_observers import ticket_observer
|
||||
from gui.v2.ui.pages.Page import Page
|
||||
|
||||
|
|
@ -91,20 +89,14 @@ class TicketOrBillingChoicePage(Page):
|
|||
self.status_label.setText("Pick a ticket from the list first.")
|
||||
return
|
||||
which_ticket = item.data(QtCore.Qt.ItemDataRole.UserRole)
|
||||
profile_id = self.update_status.current_profile_id
|
||||
try:
|
||||
profile = ProfileController.get(int(profile_id))
|
||||
except Exception:
|
||||
profile = None
|
||||
candidates = location_candidates(profile)
|
||||
if not candidates:
|
||||
self.status_label.setText("Could not determine profile location.")
|
||||
profile_id = int(self.update_status.current_profile_id)
|
||||
except (TypeError, ValueError):
|
||||
self.status_label.setText("Could not determine profile.")
|
||||
return
|
||||
profile_data = {
|
||||
'id': int(profile_id),
|
||||
'use_ticket': which_ticket,
|
||||
'ticket_location': candidates[0],
|
||||
'profile': profile
|
||||
'id': profile_id,
|
||||
'use_ticket': which_ticket
|
||||
}
|
||||
menu_page = self.custom_window.navigator.get_cached("menu")
|
||||
if menu_page:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ from core.controllers.tickets.FailedVerificationController import (
|
|||
evaluate_if_its_the_key,
|
||||
prepare_tickets_with_saved_blind_sigs,
|
||||
)
|
||||
from core.controllers.tickets.UseTicketController import use_ticket
|
||||
|
||||
from gui.v2.infrastructure.setup_observers import (
|
||||
connection_observer,
|
||||
|
|
@ -22,7 +21,6 @@ class TicketingWorkerThread(QThread):
|
|||
not_paid = pyqtSignal()
|
||||
paid_check_failed = pyqtSignal(str)
|
||||
prep_done = pyqtSignal(object)
|
||||
use_done = pyqtSignal(object)
|
||||
failed_verification_evaluated = pyqtSignal(object)
|
||||
saved_blind_prep_done = pyqtSignal(object)
|
||||
error = pyqtSignal(str)
|
||||
|
|
@ -71,14 +69,5 @@ class TicketingWorkerThread(QThread):
|
|||
elif self.action == 'PREPARE_SAVED_BLIND_SIGS':
|
||||
result = prepare_tickets_with_saved_blind_sigs(ticket_observer, connection_observer)
|
||||
self.saved_blind_prep_done.emit(result)
|
||||
elif self.action == 'USE_TICKET':
|
||||
result = use_ticket(
|
||||
which_ticket=self.params['which_ticket'],
|
||||
which_location=self.params['which_location'],
|
||||
ticket_observer=ticket_observer,
|
||||
connection_observer=connection_observer,
|
||||
profile=self.params['profile']
|
||||
)
|
||||
self.use_done.emit(result)
|
||||
except Exception as e:
|
||||
self.error.emit(str(e))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ from core.Errors import (
|
|||
UnsupportedApplicationVersionError,
|
||||
)
|
||||
|
||||
from gui.v2.actions.locations import location_candidates
|
||||
from gui.v2.actions.database_health import GuiStorageDatabaseError
|
||||
from gui.v2.infrastructure.screen_size import get_max_screensize
|
||||
from gui.v2.infrastructure.setup_observers import (
|
||||
|
|
@ -70,8 +69,7 @@ class Worker(QObject):
|
|||
|
||||
if 'use_ticket' in self.profile_data:
|
||||
ticket_billing_code = self._consume_ticket(
|
||||
self.profile_data['use_ticket'],
|
||||
self.profile_data.get('ticket_location'))
|
||||
self.profile_data['use_ticket'])
|
||||
if ticket_billing_code is None:
|
||||
return
|
||||
self.profile_data['billing_code'] = ticket_billing_code
|
||||
|
|
@ -170,9 +168,6 @@ class Worker(QObject):
|
|||
|
||||
return None
|
||||
|
||||
def _location_candidates(self, preferred=None):
|
||||
return location_candidates(self.profile, preferred)
|
||||
|
||||
def _profile_has_valid_subscription(self):
|
||||
try:
|
||||
sub = getattr(self.profile, 'subscription', None)
|
||||
|
|
@ -209,31 +204,43 @@ class Worker(QObject):
|
|||
return None
|
||||
if which_ticket is None or which_ticket == 'error':
|
||||
return None
|
||||
return self._consume_ticket(which_ticket, None)
|
||||
return self._consume_ticket(which_ticket)
|
||||
|
||||
def _consume_ticket(self, which_ticket, which_location):
|
||||
candidates = self._location_candidates(preferred=which_location)
|
||||
if not candidates:
|
||||
def _ticket_location_id(self):
|
||||
location = getattr(self.profile, 'location', None)
|
||||
location_id = getattr(location, 'id', None)
|
||||
if location_id is None:
|
||||
return None
|
||||
location_id = str(location_id).strip()
|
||||
if not location_id:
|
||||
return None
|
||||
return location_id
|
||||
|
||||
def _consume_ticket(self, which_ticket):
|
||||
which_location = self._ticket_location_id()
|
||||
if which_location is None:
|
||||
self._ticket_error_emitted = True
|
||||
self.change_page.emit('Could not determine profile location for ticket use.', True)
|
||||
return None
|
||||
|
||||
last_msg = None
|
||||
for cand in candidates:
|
||||
try:
|
||||
outcome = use_ticket(
|
||||
which_ticket=which_ticket,
|
||||
which_location=cand,
|
||||
which_location=which_location,
|
||||
ticket_observer=ticket_observer,
|
||||
connection_observer=connection_observer,
|
||||
profile=self.profile
|
||||
)
|
||||
except Exception as e:
|
||||
last_msg = str(e)
|
||||
continue
|
||||
self._ticket_error_emitted = True
|
||||
self.change_page.emit(f'Ticket use failed: {e}', True)
|
||||
return None
|
||||
|
||||
if not isinstance(outcome, dict):
|
||||
last_msg = 'invalid_response'
|
||||
continue
|
||||
self._ticket_error_emitted = True
|
||||
self.change_page.emit('Ticket use failed: invalid_response', True)
|
||||
return None
|
||||
|
||||
billing_code = outcome.get('billing_code')
|
||||
if outcome.get('valid') and billing_code:
|
||||
self._consumed_ticket = str(which_ticket)
|
||||
|
|
@ -241,15 +248,9 @@ class Worker(QObject):
|
|||
if billing_code:
|
||||
self._consumed_ticket = str(which_ticket)
|
||||
return billing_code
|
||||
msg = outcome.get('message', 'failed')
|
||||
last_msg = msg
|
||||
if msg != 'invalid_location':
|
||||
self._ticket_error_emitted = True
|
||||
self.change_page.emit(f'Ticket use failed: {msg}', True)
|
||||
return None
|
||||
|
||||
self._ticket_error_emitted = True
|
||||
self.change_page.emit(f'Ticket use failed: {last_msg or "no valid location"}', True)
|
||||
self.change_page.emit(f'Ticket use failed: {outcome.get("message", "failed")}', True)
|
||||
return None
|
||||
|
||||
def handle_profile_status(self, profile, is_enabled):
|
||||
|
|
|
|||
Loading…
Reference in a new issue