gaard-client 0.2.8__tar.gz → 0.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {gaard_client-0.2.8 → gaard_client-0.2.9}/PKG-INFO +2 -2
  2. {gaard_client-0.2.8 → gaard_client-0.2.9}/pyproject.toml +2 -2
  3. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/client-web/assets/main.js +114 -8
  4. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/client-web/assets/styles.css +6 -2
  5. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/main.py +104 -2
  6. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/PKG-INFO +2 -2
  7. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/requires.txt +1 -1
  8. {gaard_client-0.2.8 → gaard_client-0.2.9}/tests/test_client_app.py +83 -0
  9. {gaard_client-0.2.8 → gaard_client-0.2.9}/README.md +0 -0
  10. {gaard_client-0.2.8 → gaard_client-0.2.9}/setup.cfg +0 -0
  11. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/__init__.py +0 -0
  12. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/cli.py +0 -0
  13. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/cli_commands.py +0 -0
  14. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/client-web/assets/getgaard.svg +0 -0
  15. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client/client-web/index.html +0 -0
  16. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/SOURCES.txt +0 -0
  17. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/dependency_links.txt +0 -0
  18. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/entry_points.txt +0 -0
  19. {gaard_client-0.2.8 → gaard_client-0.2.9}/src/gaard_client.egg-info/top_level.txt +0 -0
  20. {gaard_client-0.2.8 → gaard_client-0.2.9}/tests/test_cli.py +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gaard-client
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: GAARD frontend web services providing client interface
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
7
- Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.8
7
+ Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.9
8
8
  Requires-Dist: fastapi>=0.111.0
9
9
  Requires-Dist: uvicorn[standard]>=0.30.0
10
10
  Requires-Dist: pydantic>=2.7.0
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gaard-client"
7
- version = "0.2.8"
7
+ version = "0.2.9"
8
8
  description = "GAARD frontend web services providing client interface"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
11
11
 
12
12
  dependencies = [
13
- "gaard-plugin-api>=0.2.8,<0.3.0",
13
+ "gaard-plugin-api>=0.2.9,<0.3.0",
14
14
  "fastapi>=0.111.0",
15
15
  "uvicorn[standard]>=0.30.0",
16
16
  "pydantic>=2.7.0",
@@ -5,12 +5,17 @@ var configuredBackendUrl = (params.get("backendUrl") || params.get("apiUrl") ||
5
5
  var storedToken = localStorage.getItem("gaard_client_token") || "";
6
6
  var storedUsername = localStorage.getItem("gaard_client_username") || "";
7
7
  var storedRole = localStorage.getItem("gaard_client_role") || "";
8
+ var storedMustChangePassword = localStorage.getItem("gaard_client_must_change_password") === "true";
9
+ var storedEnterpriseAccess = localStorage.getItem("gaard_client_enterprise_access") === "true";
8
10
  var storedActiveView = localStorage.getItem("gaard_client_active_view") || "";
9
11
  var state = {
10
12
  backendUrl: configuredBackendUrl,
11
13
  token: storedToken,
12
14
  username: storedUsername,
13
15
  role: storedRole,
16
+ enterpriseAccess: storedEnterpriseAccess,
17
+ mustChangePassword: storedMustChangePassword,
18
+ passwordChangeError: "",
14
19
  activeView: normalizeView(params.get("view") || storedActiveView),
15
20
  queryMode: normalizeQueryMode(params.get("mode")),
16
21
  messages: [],
@@ -27,6 +32,7 @@ var state = {
27
32
  datasourcesLoading: false,
28
33
  datasourceError: "",
29
34
  datasourceUploadPending: false,
35
+ excelUploadAllowed: false,
30
36
  datasourceSelectionPending: false,
31
37
  selectedDatasourceIds: [],
32
38
  multipleDatasourceSelectionAllowed: false,
@@ -298,7 +304,9 @@ function renderErrorIcon() {
298
304
  </svg>`;
299
305
  }
300
306
  function renderSidebar() {
301
- const items = [
307
+ const items = state.token && !state.enterpriseAccess ? [
308
+ ["analysis", "Dashboards", "Your saved dashboards"]
309
+ ] : [
302
310
  ["home", "Home", "Ask your data"],
303
311
  ["analysis", "Analysis", "Dashboards"],
304
312
  ["metrics", "Metrics", "Dashboard widgets"],
@@ -535,7 +543,7 @@ function renderAnalysisView() {
535
543
  ${state.dashboardLayoutSaving ? "disabled" : ""}
536
544
  >
537
545
  ${state.dashboardLayoutSaving ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span>` : renderIcon("edit")}
538
- <span>${state.dashboardLayoutSaving ? "Saving..." : state.dashboardEditMode ? "Finish editing" : "Edit layout"}</span>
546
+ ${state.dashboardLayoutSaving ? `<span>Saving...</span>` : ""}
539
547
  </button>` : ""}
540
548
  ${dashboard && state.token && state.dashboardEditMode ? `
541
549
  <button class="dashboard-add-widget-button" type="button" data-open-widget-dialog aria-label="Add widget" title="Add widget">
@@ -1101,15 +1109,18 @@ function renderSavedMetricCard(metric) {
1101
1109
  }
1102
1110
  function renderDatasourcesView() {
1103
1111
  const visibleSources = state.datasources.filter((item) => item.connector_key !== "metadata-db");
1112
+ const uploadAllowed = Boolean(state.token && state.excelUploadAllowed);
1104
1113
  const uploadLabel = state.datasourceUploadPending
1105
1114
  ? "Uploading..."
1106
- : state.token
1115
+ : uploadAllowed
1107
1116
  ? "Upload .xlsx workbook"
1108
- : "Log in to upload .xlsx workbook";
1117
+ : state.token
1118
+ ? "Enterprise access required"
1119
+ : "Log in to upload .xlsx workbook";
1109
1120
  return `
1110
1121
  <section class="datasources-view placeholder-view">
1111
1122
  <div class="datasource-actions-grid">
1112
- <button class="placeholder-item datasource-upload-card" type="button" data-add-source ${state.datasourceUploadPending ? "disabled" : ""}>
1123
+ <button class="placeholder-item datasource-upload-card" type="button" data-add-source ${state.datasourceUploadPending || !uploadAllowed ? "disabled" : ""}>
1113
1124
  ${renderIcon("plus")}
1114
1125
  <span><strong>Excel workbooks</strong><small>${escapeHtml(uploadLabel)}</small></span>
1115
1126
  </button>
@@ -1192,6 +1203,7 @@ function render(options = {}) {
1192
1203
  </section>
1193
1204
  <input id="excel-source-input" type="file" accept=".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" hidden />
1194
1205
  ${state.loginOpen ? renderLoginDialog() : ""}
1206
+ ${state.mustChangePassword ? renderPasswordChangeDialog() : ""}
1195
1207
  ${state.dashboardCreateOpen ? renderDashboardCreateDialog() : ""}
1196
1208
  ${state.dashboardWidgetDialogOpen ? renderDashboardWidgetDialog() : ""}
1197
1209
  ${state.saveWidgetDialogOpen ? renderSaveWidgetDialog() : ""}
@@ -1250,6 +1262,7 @@ function render(options = {}) {
1250
1262
  });
1251
1263
  document.querySelector("#excel-source-input")?.addEventListener("change", uploadSelectedSource);
1252
1264
  document.querySelector("#login-form")?.addEventListener("submit", login);
1265
+ document.querySelector("#password-change-form")?.addEventListener("submit", changePassword);
1253
1266
  document.querySelectorAll('input[name="mode"]').forEach((input2) => {
1254
1267
  input2.addEventListener("change", handleModeChange);
1255
1268
  });
@@ -1340,7 +1353,7 @@ function formatApiResponseError(response, message) {
1340
1353
  return detail === "Request failed." ? `${prefix}: Request failed.` : `${prefix}: ${detail}`;
1341
1354
  }
1342
1355
  function maybeLoadDatasourcesForActiveView() {
1343
- if (["home", "datasources", "metrics"].includes(state.activeView) && state.token && !state.datasourcesLoaded && !state.datasourcesLoading) {
1356
+ if (state.enterpriseAccess && ["home", "datasources", "metrics"].includes(state.activeView) && state.token && !state.datasourcesLoaded && !state.datasourcesLoading) {
1344
1357
  void loadDatasources();
1345
1358
  }
1346
1359
  }
@@ -2056,7 +2069,7 @@ function setDashboardLayoutSaving(saving) {
2056
2069
  button.setAttribute("title", saving ? "Saving..." : "Finish editing");
2057
2070
  button.innerHTML = saving
2058
2071
  ? `<span class="dashboard-edit-saving-spinner" aria-hidden="true"></span><span>Saving...</span>`
2059
- : `${renderIcon("edit")}<span>Finish editing</span>`;
2072
+ : renderIcon("edit");
2060
2073
  }
2061
2074
  function collectDashboardLayout() {
2062
2075
  return Array.from(document.querySelectorAll(".dashboard-grid .grid-stack-item")).map((element) => {
@@ -2079,6 +2092,7 @@ function openSourcePicker() {
2079
2092
  openLogin();
2080
2093
  return;
2081
2094
  }
2095
+ if (!state.excelUploadAllowed) return;
2082
2096
  const input = document.querySelector("#excel-source-input");
2083
2097
  if (!input) return;
2084
2098
  input.value = "";
@@ -2120,6 +2134,7 @@ async function loadDatasources(options = {}) {
2120
2134
  const availableDatasourceIds = new Set(items.map((item) => item.connector_key));
2121
2135
  state.selectedDatasourceIds = (payload.selected_datasource_ids || []).filter((id) => availableDatasourceIds.has(id));
2122
2136
  state.multipleDatasourceSelectionAllowed = Boolean(payload.multiple_selection_allowed);
2137
+ state.excelUploadAllowed = Boolean(payload.excel_upload_allowed);
2123
2138
  state.datasourcesLoaded = true;
2124
2139
  } catch (error) {
2125
2140
  state.datasourceError = error.message || "Could not load data sources.";
@@ -2147,7 +2162,7 @@ async function uploadSelectedSource(event) {
2147
2162
  try {
2148
2163
  const params = new URLSearchParams({
2149
2164
  backend_url: state.backendUrl,
2150
- active: "false"
2165
+ active: "true"
2151
2166
  });
2152
2167
  const response = await fetch(`/api/datasources/excel?${params.toString()}`, {
2153
2168
  method: "POST",
@@ -2545,6 +2560,23 @@ function renderLoginDialog() {
2545
2560
  </section>
2546
2561
  </div>`;
2547
2562
  }
2563
+ function renderPasswordChangeDialog() {
2564
+ return `
2565
+ <div class="login-overlay" role="presentation">
2566
+ <section class="login-panel" role="dialog" aria-modal="true" aria-labelledby="password-change-title">
2567
+ <img class="login-logo" src="/assets/getgaard.svg" alt="" />
2568
+ <h1 id="password-change-title">Set a new password</h1>
2569
+ <p>Your temporary password can only be used to sign in once.</p>
2570
+ <form id="password-change-form" class="form-grid">
2571
+ <label>Temporary password<input name="current_password" type="password" autocomplete="current-password" required /></label>
2572
+ <label>New password<input name="new_password" type="password" minlength="8" autocomplete="new-password" required /></label>
2573
+ <label>Confirm new password<input name="confirm_password" type="password" minlength="8" autocomplete="new-password" required /></label>
2574
+ ${state.passwordChangeError ? `<div class="error" role="alert">${escapeHtml(state.passwordChangeError)}</div>` : ""}
2575
+ <div class="form-actions"><button class="primary" type="submit">Save password</button></div>
2576
+ </form>
2577
+ </section>
2578
+ </div>`;
2579
+ }
2548
2580
  function renderLogin() {
2549
2581
  state.loginOpen = true;
2550
2582
  render();
@@ -3004,14 +3036,23 @@ async function login(event) {
3004
3036
  state.token = payload.token || "";
3005
3037
  state.username = payload.username || "";
3006
3038
  state.role = payload.role || "";
3039
+ state.enterpriseAccess = payload.enterprise_access === true;
3040
+ state.mustChangePassword = payload.must_change_password === true;
3041
+ state.passwordChangeError = "";
3007
3042
  state.loginOpen = false;
3008
3043
  state.dashboards = [];
3009
3044
  state.dashboardsLoaded = false;
3010
3045
  state.activeDashboardId = "";
3011
3046
  state.dashboardEditMode = false;
3047
+ if (!state.enterpriseAccess) {
3048
+ state.activeView = "analysis";
3049
+ rememberActiveView(state.activeView);
3050
+ }
3012
3051
  localStorage.setItem("gaard_client_token", state.token);
3013
3052
  localStorage.setItem("gaard_client_username", state.username);
3014
3053
  localStorage.setItem("gaard_client_role", state.role);
3054
+ localStorage.setItem("gaard_client_enterprise_access", String(state.enterpriseAccess));
3055
+ localStorage.setItem("gaard_client_must_change_password", String(state.mustChangePassword));
3015
3056
  render();
3016
3057
  } catch (error) {
3017
3058
  state.error = error.message || "Login failed.";
@@ -3019,13 +3060,75 @@ async function login(event) {
3019
3060
  renderLogin();
3020
3061
  }
3021
3062
  }
3063
+ async function changePassword(event) {
3064
+ event.preventDefault();
3065
+ const form = new FormData(event.currentTarget);
3066
+ const newPassword = String(form.get("new_password") || "");
3067
+ if (newPassword !== String(form.get("confirm_password") || "")) {
3068
+ state.passwordChangeError = "New passwords do not match.";
3069
+ render();
3070
+ return;
3071
+ }
3072
+ try {
3073
+ const response = await fetch("/api/auth/change-password", {
3074
+ method: "POST",
3075
+ headers: { "Content-Type": "application/json", ...authHeaders() },
3076
+ body: JSON.stringify({
3077
+ current_password: String(form.get("current_password") || ""),
3078
+ new_password: newPassword,
3079
+ backend_url: state.backendUrl
3080
+ })
3081
+ });
3082
+ const payload = await response.json().catch(() => ({}));
3083
+ if (!response.ok) throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
3084
+ state.mustChangePassword = false;
3085
+ state.passwordChangeError = "";
3086
+ localStorage.setItem("gaard_client_must_change_password", "false");
3087
+ render();
3088
+ } catch (error) {
3089
+ state.passwordChangeError = error.message || "Password could not be changed.";
3090
+ render();
3091
+ }
3092
+ }
3093
+ async function refreshPasswordChangeRequirement() {
3094
+ if (!state.token) return;
3095
+ try {
3096
+ const response = await fetch(`/api/auth/me?backend_url=${encodeURIComponent(state.backendUrl)}`, {
3097
+ headers: authHeaders()
3098
+ });
3099
+ const payload = await response.json().catch(() => ({}));
3100
+ if (!response.ok) throw new Error(formatApiResponseError(response, extractErrorMessage(payload)));
3101
+ state.mustChangePassword = payload.must_change_password === true;
3102
+ state.enterpriseAccess = payload.enterprise_access === true;
3103
+ if (!state.enterpriseAccess) {
3104
+ state.activeView = "analysis";
3105
+ rememberActiveView(state.activeView);
3106
+ }
3107
+ localStorage.setItem("gaard_client_must_change_password", String(state.mustChangePassword));
3108
+ localStorage.setItem("gaard_client_enterprise_access", String(state.enterpriseAccess));
3109
+ render();
3110
+ } catch (error) {
3111
+ if (error.message?.includes("401")) await logout();
3112
+ }
3113
+ }
3022
3114
  async function logout() {
3023
3115
  if (state.dashboardEditMode) {
3024
3116
  await flushPendingDashboardLayoutSave();
3025
3117
  }
3118
+ const token = state.token;
3119
+ if (token) {
3120
+ void fetch(`/api/auth/logout?backend_url=${encodeURIComponent(state.backendUrl)}`, {
3121
+ method: "POST",
3122
+ headers: { "Authorization": `Bearer ${token}` },
3123
+ keepalive: true,
3124
+ });
3125
+ }
3026
3126
  state.token = "";
3027
3127
  state.username = "";
3028
3128
  state.role = "";
3129
+ state.enterpriseAccess = false;
3130
+ state.mustChangePassword = false;
3131
+ state.passwordChangeError = "";
3029
3132
  state.messages = [];
3030
3133
  state.conversationId = "";
3031
3134
  state.datasources = [];
@@ -3061,6 +3164,8 @@ async function logout() {
3061
3164
  localStorage.removeItem("gaard_client_token");
3062
3165
  localStorage.removeItem("gaard_client_username");
3063
3166
  localStorage.removeItem("gaard_client_role");
3167
+ localStorage.removeItem("gaard_client_enterprise_access");
3168
+ localStorage.removeItem("gaard_client_must_change_password");
3064
3169
  render();
3065
3170
  }
3066
3171
  function buildWidgetLabel(question) {
@@ -3582,3 +3687,4 @@ function scrollToLatest() {
3582
3687
  });
3583
3688
  }
3584
3689
  render();
3690
+ void refreshPasswordChangeRequirement();
@@ -970,8 +970,7 @@ label {
970
970
  }
971
971
 
972
972
  .data-table-wrap {
973
- max-width: calc(100% - 44px);
974
- margin-left: 44px;
973
+ max-width: 100%;
975
974
  overflow: auto;
976
975
  border: 1px solid var(--line);
977
976
  border-radius: 8px;
@@ -1786,6 +1785,11 @@ button.primary {
1786
1785
  cursor: pointer;
1787
1786
  }
1788
1787
 
1788
+ .dashboard-edit-mode-button:not(.saving) {
1789
+ width: 36px;
1790
+ padding: 0;
1791
+ }
1792
+
1789
1793
  .dashboard-edit-mode-button:hover,
1790
1794
  .dashboard-edit-mode-button:focus-visible {
1791
1795
  border-color: var(--accent);
@@ -23,7 +23,7 @@ DEFAULT_BACKEND_URL = "http://localhost:8000"
23
23
 
24
24
  app = FastAPI(
25
25
  title="GAARD Client",
26
- version="0.2.8",
26
+ version="0.2.9",
27
27
  description="Community client for asking governed natural-language questions.",
28
28
  )
29
29
 
@@ -50,6 +50,12 @@ class ClientLoginRequest(BaseModel):
50
50
  backend_url: str | None = None
51
51
 
52
52
 
53
+ class ClientChangePasswordRequest(BaseModel):
54
+ current_password: str = Field(min_length=1)
55
+ new_password: str = Field(min_length=8)
56
+ backend_url: str | None = None
57
+
58
+
53
59
  class ClientAnalysisMessageRequest(BaseModel):
54
60
  message: str = Field(min_length=1)
55
61
  backend_url: str | None = None
@@ -324,6 +330,102 @@ async def login_backend(request: ClientLoginRequest) -> dict[str, Any]:
324
330
  return cast(dict[str, Any], response.json())
325
331
 
326
332
 
333
+ @app.post("/api/auth/change-password")
334
+ async def change_password_backend(
335
+ request: ClientChangePasswordRequest,
336
+ authorization: str | None = Header(default=None),
337
+ ) -> dict[str, Any]:
338
+ backend_url = normalize_backend_url(request.backend_url or get_default_backend_url())
339
+ change_password_url = f"{backend_url}/api/v1/admin/auth/change-password"
340
+
341
+ try:
342
+ async with httpx.AsyncClient(timeout=30.0) as client:
343
+ response = await client.post(
344
+ change_password_url,
345
+ **backend_request_kwargs(authorization, {
346
+ "current_password": request.current_password,
347
+ "new_password": request.new_password,
348
+ }),
349
+ )
350
+ except httpx.HTTPError as exc:
351
+ raise HTTPException(
352
+ status_code=502,
353
+ detail=f"Backend request failed: {exc}",
354
+ ) from exc
355
+
356
+ if response.status_code >= 400:
357
+ raise HTTPException(
358
+ status_code=response.status_code,
359
+ detail=response.json()
360
+ if response.headers.get("content-type", "").startswith("application/json")
361
+ else response.text,
362
+ )
363
+
364
+ return cast(dict[str, Any], response.json())
365
+
366
+
367
+ @app.post("/api/auth/logout")
368
+ async def logout_backend(
369
+ backend_url: str | None = None,
370
+ authorization: str | None = Header(default=None),
371
+ ) -> dict[str, Any]:
372
+ resolved_backend_url = normalize_backend_url(backend_url or get_default_backend_url())
373
+ logout_url = f"{resolved_backend_url}/api/v1/admin/auth/logout"
374
+
375
+ try:
376
+ async with httpx.AsyncClient(timeout=30.0) as client:
377
+ response = await client.post(
378
+ logout_url,
379
+ headers={"Authorization": authorization} if authorization else {},
380
+ )
381
+ except httpx.HTTPError as exc:
382
+ raise HTTPException(
383
+ status_code=502,
384
+ detail=f"Backend request failed: {exc}",
385
+ ) from exc
386
+
387
+ if response.status_code >= 400:
388
+ raise HTTPException(
389
+ status_code=response.status_code,
390
+ detail=response.json()
391
+ if response.headers.get("content-type", "").startswith("application/json")
392
+ else response.text,
393
+ )
394
+
395
+ return cast(dict[str, Any], response.json())
396
+
397
+
398
+ @app.get("/api/auth/me")
399
+ async def get_current_user_backend(
400
+ backend_url: str | None = None,
401
+ authorization: str | None = Header(default=None),
402
+ ) -> dict[str, Any]:
403
+ resolved_backend_url = normalize_backend_url(backend_url or get_default_backend_url())
404
+ me_url = f"{resolved_backend_url}/api/v1/admin/me"
405
+
406
+ try:
407
+ async with httpx.AsyncClient(timeout=30.0) as client:
408
+ response = await client.get(
409
+ me_url,
410
+ headers={"Authorization": authorization} if authorization else {},
411
+ )
412
+ except httpx.HTTPError as exc:
413
+ raise HTTPException(
414
+ status_code=502,
415
+ detail=f"Backend request failed: {exc}",
416
+ ) from exc
417
+
418
+ if response.status_code >= 400:
419
+ raise HTTPException(
420
+ status_code=response.status_code,
421
+ detail=response.json()
422
+ if response.headers.get("content-type", "").startswith("application/json")
423
+ else response.text,
424
+ )
425
+
426
+ return cast(dict[str, Any], response.json())
427
+
428
+
327
429
  @app.post("/api/widgets/title-suggestion")
328
430
  async def suggest_widget_title(
329
431
  request: ClientWidgetTitleSuggestionRequest,
@@ -461,7 +563,7 @@ async def update_datasource_selection(
461
563
  @app.post("/api/datasources/excel")
462
564
  async def upload_excel_datasource(
463
565
  file: UploadFile = File(...),
464
- active: bool = False,
566
+ active: bool = True,
465
567
  backend_url: str | None = None,
466
568
  authorization: str | None = Header(default=None),
467
569
  ) -> dict[str, Any]:
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gaard-client
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: GAARD frontend web services providing client interface
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
7
- Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.8
7
+ Requires-Dist: gaard-plugin-api<0.3.0,>=0.2.9
8
8
  Requires-Dist: fastapi>=0.111.0
9
9
  Requires-Dist: uvicorn[standard]>=0.30.0
10
10
  Requires-Dist: pydantic>=2.7.0
@@ -1,4 +1,4 @@
1
- gaard-plugin-api<0.3.0,>=0.2.8
1
+ gaard-plugin-api<0.3.0,>=0.2.9
2
2
  fastapi>=0.111.0
3
3
  uvicorn[standard]>=0.30.0
4
4
  pydantic>=2.7.0
@@ -193,6 +193,89 @@ def test_client_app_proxies_query(monkeypatch) -> None:
193
193
  }
194
194
 
195
195
 
196
+ def test_client_app_proxies_password_change(monkeypatch) -> None:
197
+ captured = {}
198
+
199
+ class FakeAsyncClient:
200
+ def __init__(self, *args, **kwargs) -> None:
201
+ pass
202
+
203
+ async def __aenter__(self):
204
+ return self
205
+
206
+ async def __aexit__(self, exc_type, exc, traceback) -> None:
207
+ pass
208
+
209
+ async def post(self, url, json, headers):
210
+ captured["url"] = url
211
+ captured["json"] = json
212
+ captured["headers"] = headers
213
+ request = httpx.Request("POST", url)
214
+ return httpx.Response(
215
+ status_code=200,
216
+ request=request,
217
+ json={"username": "ada", "must_change_password": False, "role": "user"},
218
+ )
219
+
220
+ monkeypatch.setattr(httpx, "AsyncClient", FakeAsyncClient)
221
+ client = TestClient(app)
222
+
223
+ response = client.post(
224
+ "/api/auth/change-password",
225
+ headers={"Authorization": "Bearer token"},
226
+ json={
227
+ "current_password": "temporary-password",
228
+ "new_password": "new-user-password",
229
+ "backend_url": "http://backend.example/",
230
+ },
231
+ )
232
+
233
+ assert response.status_code == 200
234
+ assert captured["url"] == "http://backend.example/api/v1/admin/auth/change-password"
235
+ assert captured["headers"] == {"Authorization": "Bearer token"}
236
+ assert captured["json"] == {
237
+ "current_password": "temporary-password",
238
+ "new_password": "new-user-password",
239
+ }
240
+
241
+
242
+ def test_client_app_proxies_current_user(monkeypatch) -> None:
243
+ captured = {}
244
+
245
+ class FakeAsyncClient:
246
+ def __init__(self, *args, **kwargs) -> None:
247
+ pass
248
+
249
+ async def __aenter__(self):
250
+ return self
251
+
252
+ async def __aexit__(self, exc_type, exc, traceback) -> None:
253
+ pass
254
+
255
+ async def get(self, url, headers):
256
+ captured["url"] = url
257
+ captured["headers"] = headers
258
+ request = httpx.Request("GET", url)
259
+ return httpx.Response(
260
+ status_code=200,
261
+ request=request,
262
+ json={"username": "ada", "must_change_password": True, "role": "user"},
263
+ )
264
+
265
+ monkeypatch.setattr(httpx, "AsyncClient", FakeAsyncClient)
266
+ client = TestClient(app)
267
+
268
+ response = client.get(
269
+ "/api/auth/me?backend_url=http://backend.example/",
270
+ headers={"Authorization": "Bearer token"},
271
+ )
272
+
273
+ assert response.status_code == 200
274
+ assert response.json()["must_change_password"] is True
275
+ assert captured["url"] == "http://backend.example/api/v1/admin/me"
276
+ assert captured["headers"] == {"Authorization": "Bearer token"}
277
+
278
+
196
279
  def test_client_app_proxies_query_conversation_id(monkeypatch) -> None:
197
280
  captured = {}
198
281
 
File without changes
File without changes