diff --git a/discord_link.py b/discord_link.py index 236ce17..b48bee9 100644 --- a/discord_link.py +++ b/discord_link.py @@ -101,6 +101,15 @@ def _account_redirect(status: str) -> RedirectResponse: # --- routes ------------------------------------------------------------------ +@router.get("/discord/config") +async def discord_config(): + """Whether Discord account-linking is configured on this server. The account + menu uses it to show the "Link Discord" entry only when linking will actually + work — so an unconfigured server surfaces no dead-end Discord UI, and enabling + it later (setting the OAuth env vars) makes the entry appear on its own.""" + return {"enabled": enabled()} + + @router.get("/discord/link/start") async def link_start(request: Request, user=Depends(current_active_user)): if not enabled(): diff --git a/tests/test_discord_link.py b/tests/test_discord_link.py index 66efb8f..e75e599 100644 --- a/tests/test_discord_link.py +++ b/tests/test_discord_link.py @@ -46,6 +46,17 @@ def test_state_is_secret_dependent(monkeypatch): # --- routes ------------------------------------------------------------------ +def test_config_reports_enabled_state(monkeypatch): + c = TestClient(appmod.app) + monkeypatch.setattr(dl, "CLIENT_ID", "") + monkeypatch.setattr(dl, "CLIENT_SECRET", "") + r = c.get(f"{V2}/discord/config") # no auth required + assert r.status_code == 200 and r.json() == {"enabled": False} + monkeypatch.setattr(dl, "CLIENT_ID", "app123") + monkeypatch.setattr(dl, "CLIENT_SECRET", "secret456") + assert c.get(f"{V2}/discord/config").json() == {"enabled": True} + + def test_link_requires_auth(): c = TestClient(appmod.app) assert c.get(f"{V2}/discord/link/start", follow_redirects=False).status_code == 401