forked from Support/sp-hydra-veil-gui
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.QtWidgets import QLabel, QListWidget, QListWidgetItem, QPushButton
|
||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
|
|
||||||
from core.controllers.ProfileController import ProfileController
|
|
||||||
from core.controllers.tickets.UseTicketController import get_unused_tickets
|
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.infrastructure.setup_observers import ticket_observer
|
||||||
from gui.v2.ui.pages.Page import Page
|
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.")
|
self.status_label.setText("Pick a ticket from the list first.")
|
||||||
return
|
return
|
||||||
which_ticket = item.data(QtCore.Qt.ItemDataRole.UserRole)
|
which_ticket = item.data(QtCore.Qt.ItemDataRole.UserRole)
|
||||||
profile_id = self.update_status.current_profile_id
|
|
||||||
try:
|
try:
|
||||||
profile = ProfileController.get(int(profile_id))
|
profile_id = int(self.update_status.current_profile_id)
|
||||||
except Exception:
|
except (TypeError, ValueError):
|
||||||
profile = None
|
self.status_label.setText("Could not determine profile.")
|
||||||
candidates = location_candidates(profile)
|
|
||||||
if not candidates:
|
|
||||||
self.status_label.setText("Could not determine profile location.")
|
|
||||||
return
|
return
|
||||||
profile_data = {
|
profile_data = {
|
||||||
'id': int(profile_id),
|
'id': profile_id,
|
||||||
'use_ticket': which_ticket,
|
'use_ticket': which_ticket
|
||||||
'ticket_location': candidates[0],
|
|
||||||
'profile': profile
|
|
||||||
}
|
}
|
||||||
menu_page = self.custom_window.navigator.get_cached("menu")
|
menu_page = self.custom_window.navigator.get_cached("menu")
|
||||||
if menu_page:
|
if menu_page:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from core.controllers.tickets.FailedVerificationController import (
|
||||||
evaluate_if_its_the_key,
|
evaluate_if_its_the_key,
|
||||||
prepare_tickets_with_saved_blind_sigs,
|
prepare_tickets_with_saved_blind_sigs,
|
||||||
)
|
)
|
||||||
from core.controllers.tickets.UseTicketController import use_ticket
|
|
||||||
|
|
||||||
from gui.v2.infrastructure.setup_observers import (
|
from gui.v2.infrastructure.setup_observers import (
|
||||||
connection_observer,
|
connection_observer,
|
||||||
|
|
@ -22,7 +21,6 @@ class TicketingWorkerThread(QThread):
|
||||||
not_paid = pyqtSignal()
|
not_paid = pyqtSignal()
|
||||||
paid_check_failed = pyqtSignal(str)
|
paid_check_failed = pyqtSignal(str)
|
||||||
prep_done = pyqtSignal(object)
|
prep_done = pyqtSignal(object)
|
||||||
use_done = pyqtSignal(object)
|
|
||||||
failed_verification_evaluated = pyqtSignal(object)
|
failed_verification_evaluated = pyqtSignal(object)
|
||||||
saved_blind_prep_done = pyqtSignal(object)
|
saved_blind_prep_done = pyqtSignal(object)
|
||||||
error = pyqtSignal(str)
|
error = pyqtSignal(str)
|
||||||
|
|
@ -71,14 +69,5 @@ class TicketingWorkerThread(QThread):
|
||||||
elif self.action == 'PREPARE_SAVED_BLIND_SIGS':
|
elif self.action == 'PREPARE_SAVED_BLIND_SIGS':
|
||||||
result = prepare_tickets_with_saved_blind_sigs(ticket_observer, connection_observer)
|
result = prepare_tickets_with_saved_blind_sigs(ticket_observer, connection_observer)
|
||||||
self.saved_blind_prep_done.emit(result)
|
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:
|
except Exception as e:
|
||||||
self.error.emit(str(e))
|
self.error.emit(str(e))
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ from core.Errors import (
|
||||||
UnsupportedApplicationVersionError,
|
UnsupportedApplicationVersionError,
|
||||||
)
|
)
|
||||||
|
|
||||||
from gui.v2.actions.locations import location_candidates
|
|
||||||
from gui.v2.actions.database_health import GuiStorageDatabaseError
|
from gui.v2.actions.database_health import GuiStorageDatabaseError
|
||||||
from gui.v2.infrastructure.screen_size import get_max_screensize
|
from gui.v2.infrastructure.screen_size import get_max_screensize
|
||||||
from gui.v2.infrastructure.setup_observers import (
|
from gui.v2.infrastructure.setup_observers import (
|
||||||
|
|
@ -70,8 +69,7 @@ class Worker(QObject):
|
||||||
|
|
||||||
if 'use_ticket' in self.profile_data:
|
if 'use_ticket' in self.profile_data:
|
||||||
ticket_billing_code = self._consume_ticket(
|
ticket_billing_code = self._consume_ticket(
|
||||||
self.profile_data['use_ticket'],
|
self.profile_data['use_ticket'])
|
||||||
self.profile_data.get('ticket_location'))
|
|
||||||
if ticket_billing_code is None:
|
if ticket_billing_code is None:
|
||||||
return
|
return
|
||||||
self.profile_data['billing_code'] = ticket_billing_code
|
self.profile_data['billing_code'] = ticket_billing_code
|
||||||
|
|
@ -170,9 +168,6 @@ class Worker(QObject):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _location_candidates(self, preferred=None):
|
|
||||||
return location_candidates(self.profile, preferred)
|
|
||||||
|
|
||||||
def _profile_has_valid_subscription(self):
|
def _profile_has_valid_subscription(self):
|
||||||
try:
|
try:
|
||||||
sub = getattr(self.profile, 'subscription', None)
|
sub = getattr(self.profile, 'subscription', None)
|
||||||
|
|
@ -209,31 +204,43 @@ class Worker(QObject):
|
||||||
return None
|
return None
|
||||||
if which_ticket is None or which_ticket == 'error':
|
if which_ticket is None or which_ticket == 'error':
|
||||||
return None
|
return None
|
||||||
return self._consume_ticket(which_ticket, None)
|
return self._consume_ticket(which_ticket)
|
||||||
|
|
||||||
def _consume_ticket(self, which_ticket, which_location):
|
def _ticket_location_id(self):
|
||||||
candidates = self._location_candidates(preferred=which_location)
|
location = getattr(self.profile, 'location', None)
|
||||||
if not candidates:
|
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._ticket_error_emitted = True
|
||||||
self.change_page.emit('Could not determine profile location for ticket use.', True)
|
self.change_page.emit('Could not determine profile location for ticket use.', True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
last_msg = None
|
|
||||||
for cand in candidates:
|
|
||||||
try:
|
try:
|
||||||
outcome = use_ticket(
|
outcome = use_ticket(
|
||||||
which_ticket=which_ticket,
|
which_ticket=which_ticket,
|
||||||
which_location=cand,
|
which_location=which_location,
|
||||||
ticket_observer=ticket_observer,
|
ticket_observer=ticket_observer,
|
||||||
connection_observer=connection_observer,
|
connection_observer=connection_observer,
|
||||||
profile=self.profile
|
profile=self.profile
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
last_msg = str(e)
|
self._ticket_error_emitted = True
|
||||||
continue
|
self.change_page.emit(f'Ticket use failed: {e}', True)
|
||||||
|
return None
|
||||||
|
|
||||||
if not isinstance(outcome, dict):
|
if not isinstance(outcome, dict):
|
||||||
last_msg = 'invalid_response'
|
self._ticket_error_emitted = True
|
||||||
continue
|
self.change_page.emit('Ticket use failed: invalid_response', True)
|
||||||
|
return None
|
||||||
|
|
||||||
billing_code = outcome.get('billing_code')
|
billing_code = outcome.get('billing_code')
|
||||||
if outcome.get('valid') and billing_code:
|
if outcome.get('valid') and billing_code:
|
||||||
self._consumed_ticket = str(which_ticket)
|
self._consumed_ticket = str(which_ticket)
|
||||||
|
|
@ -241,15 +248,9 @@ class Worker(QObject):
|
||||||
if billing_code:
|
if billing_code:
|
||||||
self._consumed_ticket = str(which_ticket)
|
self._consumed_ticket = str(which_ticket)
|
||||||
return billing_code
|
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._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
|
return None
|
||||||
|
|
||||||
def handle_profile_status(self, profile, is_enabled):
|
def handle_profile_status(self, profile, is_enabled):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue