ubuntu-pro: add info about subscription in former services screen

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-07-05 10:34:50 +02:00
parent 746e559c47
commit acac7a8d5b
4 changed files with 45 additions and 31 deletions

View File

@ -16,7 +16,7 @@
import asyncio import asyncio
import logging import logging
from typing import Callable, List, Optional from typing import Callable, Optional
from urwid import Widget from urwid import Widget
@ -26,7 +26,7 @@ from subiquity.client.controller import SubiquityTuiController
from subiquity.common.types import ( from subiquity.common.types import (
UbuntuProInfo, UbuntuProInfo,
UbuntuProCheckTokenStatus as TokenStatus, UbuntuProCheckTokenStatus as TokenStatus,
UbuntuProService, UbuntuProSubscription,
) )
from subiquity.ui.views.ubuntu_pro import ( from subiquity.ui.views.ubuntu_pro import (
UbuntuProView, UbuntuProView,
@ -113,9 +113,9 @@ class UbuntuProController(SubiquityTuiController):
click(find_button_matching(view, TokenAddedWidget.done_label)) click(find_button_matching(view, TokenAddedWidget.done_label))
def run_services_screen() -> None: def run_subscription_screen() -> None:
click(find_button_matching(view._w, click(find_button_matching(view._w,
UbuntuProView.services_done_label)) UbuntuProView.subscription_done_label))
if not self.answers["token"]: if not self.answers["token"]:
run_yes_no_screen(skip=True) run_yes_no_screen(skip=True)
@ -124,10 +124,10 @@ class UbuntuProController(SubiquityTuiController):
run_yes_no_screen(skip=False) run_yes_no_screen(skip=False)
run_token_screen(self.answers["token"]) run_token_screen(self.answers["token"])
await run_token_added_overlay() await run_token_added_overlay()
run_services_screen() run_subscription_screen()
def check_token(self, token: str, def check_token(self, token: str,
on_success: Callable[[List[UbuntuProService]], None], on_success: Callable[[UbuntuProSubscription], None],
on_failure: Callable[[TokenStatus], None], on_failure: Callable[[TokenStatus], None],
) -> None: ) -> None:
""" Asynchronously check the token passed as an argument. """ """ Asynchronously check the token passed as an argument. """
@ -135,7 +135,7 @@ class UbuntuProController(SubiquityTuiController):
answer = await self.endpoint.check_token.GET(token) answer = await self.endpoint.check_token.GET(token)
if answer.status == TokenStatus.VALID_TOKEN: if answer.status == TokenStatus.VALID_TOKEN:
await self.endpoint.POST(UbuntuProInfo(token=token)) await self.endpoint.POST(UbuntuProInfo(token=token))
on_success(answer.subscription.services) on_success(answer.subscription)
else: else:
on_failure(answer.status) on_failure(answer.status)

View File

@ -475,6 +475,7 @@ class UbuntuProService:
class UbuntuProSubscription: class UbuntuProSubscription:
contract_name: str contract_name: str
account_name: str account_name: str
contract_token: str
services: List[UbuntuProService] services: List[UbuntuProService]

View File

@ -216,4 +216,5 @@ class UAInterface:
return UbuntuProSubscription( return UbuntuProSubscription(
account_name=info["account"]["name"], account_name=info["account"]["name"],
contract_name=info["contract"]["name"], contract_name=info["contract"]["name"],
contract_token=token,
services=activable_services) services=activable_services)

View File

@ -28,7 +28,7 @@ from urwid import (
from subiquity.common.types import ( from subiquity.common.types import (
UbuntuProCheckTokenStatus, UbuntuProCheckTokenStatus,
UbuntuProService, UbuntuProSubscription,
) )
from subiquitycore.view import BaseView from subiquitycore.view import BaseView
from subiquitycore.ui.buttons import ( from subiquitycore.ui.buttons import (
@ -200,7 +200,7 @@ class UbuntuProView(BaseView):
""" Represent the view of the Ubuntu Pro configuration. """ """ Represent the view of the Ubuntu Pro configuration. """
title = _("Upgrade to Ubuntu Pro") title = _("Upgrade to Ubuntu Pro")
services_done_label = _("Continue") subscription_done_label = _("Continue")
def __init__(self, controller, token: str): def __init__(self, controller, token: str):
""" Initialize the view with the default value for the token. """ """ Initialize the view with the default value for the token. """
@ -308,9 +308,14 @@ class UbuntuProView(BaseView):
excerpt=excerpt, excerpt=excerpt,
focus_buttons=True) focus_buttons=True)
def services_screen(self, services) -> Widget: def subscription_screen(self, subscription: UbuntuProSubscription) \
-> Widget:
""" """
+---------------------------------------------------------+ +---------------------------------------------------------+
| Account Connected: user@domain.com |
| Token: C1NWcZTHLteJXGVMM6YhvHDpGrhyy7 |
| Subscription: Ubuntu Pro - Physical 24/5 |
| |
| List of your enabled services: | | List of your enabled services: |
| | | |
| * ... | | * ... |
@ -331,26 +336,34 @@ class UbuntuProView(BaseView):
| [ Back ] | | [ Back ] |
+---------------------------------------------------------+ +---------------------------------------------------------+
""" """
services = subscription.services
auto_enabled = [svc for svc in services if svc.auto_enabled] auto_enabled = [svc for svc in services if svc.auto_enabled]
can_be_enabled = [svc for svc in services if not svc.auto_enabled] can_be_enabled = [svc for svc in services if not svc.auto_enabled]
svc_rows: List[Widget] = [] rows: List[Widget] = []
rows.extend([
Text(_("Account Connected") + ": " + subscription.account_name),
Text(_(" Token") + ": " + subscription.contract_token),
Text(_(" Subscription") + ": " + subscription.contract_name),
])
rows.append(Text(""))
if auto_enabled: if auto_enabled:
svc_rows.append(Text(_("List of your enabled services:"))) rows.append(Text(_("List of your enabled services:")))
svc_rows.append(Text("")) rows.append(Text(""))
svc_rows.extend( rows.extend(
[Text(f" * {svc.description}") for svc in auto_enabled]) [Text(f" * {svc.description}") for svc in auto_enabled])
if can_be_enabled: if can_be_enabled:
if auto_enabled: if auto_enabled:
# available here means activable # available here means activable
svc_rows.append(Text("")) rows.append(Text(""))
svc_rows.append(Text(_("Other available services:"))) rows.append(Text(_("Other available services:")))
else: else:
svc_rows.append(Text(_("Available services:"))) rows.append(Text(_("Available services:")))
svc_rows.append(Text("")) rows.append(Text(""))
svc_rows.extend( rows.extend(
[Text(f" * {svc.description}") for svc in can_be_enabled]) [Text(f" * {svc.description}") for svc in can_be_enabled])
def on_continue() -> None: def on_continue() -> None:
@ -363,12 +376,12 @@ class UbuntuProView(BaseView):
label=_("Back"), label=_("Back"),
on_press=lambda unused: on_back()) on_press=lambda unused: on_back())
continue_button = done_btn( continue_button = done_btn(
label=self.__class__.services_done_label, label=self.__class__.subscription_done_label,
on_press=lambda unused: on_continue()) on_press=lambda unused: on_continue())
widgets: List[Widget] = [ widgets: List[Widget] = [
Text(""), Text(""),
Pile(svc_rows), Pile(rows),
Text(""), Text(""),
Text(_("If you want to change the default enablements for your" Text(_("If you want to change the default enablements for your"
" token, you can do so via the ubuntu.com/pro web" " token, you can do so via the ubuntu.com/pro web"
@ -387,15 +400,15 @@ class UbuntuProView(BaseView):
def upgrade_mode_done(self, form: UpgradeModeForm) -> None: def upgrade_mode_done(self, form: UpgradeModeForm) -> None:
""" Open the loading dialog and asynchronously check if the token is """ Open the loading dialog and asynchronously check if the token is
valid. """ valid. """
def on_success(services: List[UbuntuProService]) -> None: def on_success(subscription: UbuntuProSubscription) -> None:
def show_services() -> None: def show_subscription() -> None:
self.remove_overlay() self.remove_overlay()
self.show_activable_services(services) self.show_subscription(subscription=subscription)
self.remove_overlay() self.remove_overlay()
widget = TokenAddedWidget( widget = TokenAddedWidget(
parent=self, parent=self,
on_continue=show_services) on_continue=show_subscription)
self.show_stretchy_overlay(widget) self.show_stretchy_overlay(widget)
def on_failure(status: UbuntuProCheckTokenStatus) -> None: def on_failure(status: UbuntuProCheckTokenStatus) -> None:
@ -463,12 +476,11 @@ class UbuntuProView(BaseView):
""" """
self.show_stretchy_overlay(ContinueAnywayWidget(self)) self.show_stretchy_overlay(ContinueAnywayWidget(self))
def show_activable_services(self, def show_subscription(self, subscription: UbuntuProSubscription) -> None:
services: List[UbuntuProService]) -> None: """ Display a screen with information about the subscription, including
""" Display a screen with the list of services that can be enabled the list of services that can be enabled. After the user confirms, we
via Ubuntu Pro subscription. After the user confirms, we will will quit the current view and move on. """
quit the current view and move on. """ self._w = self.subscription_screen(subscription=subscription)
self._w = self.services_screen(services)
class ExpiredTokenWidget(Stretchy): class ExpiredTokenWidget(Stretchy):