Skip to content

Commit 176c128

Browse files
authored
fix: edit profile button opens new tab (#286)
1 parent 6b8656f commit 176c128

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/aignostics/gui/_frame.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import platform
55
import sys
6+
import webbrowser
67
from collections.abc import Generator
78
from contextlib import contextmanager
89
from importlib.util import find_spec
@@ -20,8 +21,6 @@
2021
HEALTH_UPDATE_INTERVAL = 30
2122
USERINFO_UPDATE_INTERVAL = 60 * 60
2223

23-
PROFILE_EDIT_URL = "https://platform.aignostics.com/dashboard/account/profile"
24-
2524

2625
@contextmanager
2726
def frame( # noqa: C901, PLR0915
@@ -46,7 +45,7 @@ def frame( # noqa: C901, PLR0915
4645
from nicegui import app, background_tasks, context, run, ui # noqa: PLC0415
4746

4847
from aignostics.platform import Service as PlatformService # noqa: PLC0415
49-
from aignostics.platform import UserInfo # noqa: PLC0415
48+
from aignostics.platform import UserInfo, settings # noqa: PLC0415
5049
from aignostics.system import Service as SystemService # noqa: PLC0415
5150

5251
theme()
@@ -84,7 +83,7 @@ def _user_info_ui() -> None:
8483
ui.button(
8584
"Edit Profile",
8685
icon="edit",
87-
on_click=lambda _: ui.navigate.to(PROFILE_EDIT_URL, new_tab=True),
86+
on_click=lambda: webbrowser.open(settings().profile_edit_url),
8887
)
8988

9089
async def _user_info_ui_load() -> None:

src/aignostics/platform/_settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ def issuer(self) -> str:
225225
)
226226
return self.authorization_base_url.rsplit("/", 1)[0] + "/"
227227

228+
@computed_field # type: ignore[prop-decorator]
229+
@property
230+
def profile_edit_url(self) -> str:
231+
"""Get the profile edit URL based on the API root.
232+
233+
Returns:
234+
str: Full URL to the profile editor page
235+
"""
236+
return f"{self.api_root}/dashboard/account/profile"
237+
228238
token_url: Annotated[str, BeforeValidator(_validate_url), Field(description="OAuth token endpoint URL")]
229239
redirect_uri: Annotated[
230240
str, BeforeValidator(_validate_url), Field(description="OAuth redirect URI for authorization code flow")

tests/aignostics/platform/settings_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,39 @@ def test_issuer_computed_field_dev(record_property, mock_env_vars) -> None:
314314
assert settings.issuer == expected_issuer
315315

316316

317+
@pytest.mark.unit
318+
def test_profile_edit_url_computed_field_production(record_property, mock_env_vars) -> None:
319+
"""Test profile_edit_url computed field with production API root."""
320+
record_property("tested-item-id", "SPEC-PLATFORM-SERVICE")
321+
settings = Settings(
322+
api_root=API_ROOT_PRODUCTION,
323+
)
324+
expected_url = f"{API_ROOT_PRODUCTION}/dashboard/account/profile"
325+
assert settings.profile_edit_url == expected_url
326+
327+
328+
@pytest.mark.unit
329+
def test_profile_edit_url_computed_field_staging(record_property, mock_env_vars) -> None:
330+
"""Test profile_edit_url computed field with staging API root."""
331+
record_property("tested-item-id", "SPEC-PLATFORM-SERVICE")
332+
settings = Settings(
333+
api_root=API_ROOT_STAGING,
334+
)
335+
expected_url = f"{API_ROOT_STAGING}/dashboard/account/profile"
336+
assert settings.profile_edit_url == expected_url
337+
338+
339+
@pytest.mark.unit
340+
def test_profile_edit_url_computed_field_dev(record_property, mock_env_vars) -> None:
341+
"""Test profile_edit_url computed field with dev API root."""
342+
record_property("tested-item-id", "SPEC-PLATFORM-SERVICE")
343+
settings = Settings(
344+
api_root=API_ROOT_DEV,
345+
)
346+
expected_url = f"{API_ROOT_DEV}/dashboard/account/profile"
347+
assert settings.profile_edit_url == expected_url
348+
349+
317350
@pytest.mark.unit
318351
def test_issuer_computed_field_custom_url(record_property, mock_env_vars) -> None:
319352
"""Test issuer computed field with custom authorization base URL."""

0 commit comments

Comments
 (0)