fix(identity): Auth/Me 补 endpoint / tdsEndpoint(上游前端真的在读)
- 上游 IdentityManage 的 connIdentity 就是 me,表单预填从 me.endpoint / me.tdsEndpoint 取 - 两值取自 tdc_identity.f_endpoint / f_tds_endpoint,可为 null - 与上游的一处有意差异:上游在 endpoint 为空时回退 tdc-report.base-url, 本仓无该配置且无「平台回连」场景,不做回退(错的预填比空字段危险) - me 的键集合 13 → 15(精确集合断言同步) Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
1 parent
c29e12184b
commit
aea73ab040
1 file changed
+70
-6
+70
-6
@@ -284,6 +284,15 @@ pub async fn login(State(state): State<AppState>, payload: Option<Json<Value>>)
|
||||
/// 🔴 上游完整前端的登录页判 `me.accessAllowed` 决定放不放行(`Login.vue`):
|
||||
/// `accessAllowed === false` ⇒ 前端 `logout()` 并提示「账号无权访问本连接器」。
|
||||
/// 本连接器是**单体部署**(无平台侧归属校验)⇒ 任一已登录主体都放行。
|
||||
///
|
||||
/// ⚠️ **与上游的一处有意差异:`endpoint` 不做回退。**
|
||||
/// 上游 `AuthController.java:159-176` 在 `endpoint` 为空时回退到本端配置的
|
||||
/// `tdc-report.base-url`(平台回连地址)。本仓**没有**这个配置、也**没有**「平台回连」
|
||||
/// 这个真实场景 ⇒ **不加任何回退、不加新环境变量/配置字段**;
|
||||
/// 库里 `f_endpoint` / `f_tds_endpoint` 是 NULL 就返回 `null`
|
||||
/// (塞空串或编造 `http://127.0.0.1:{port}` 都会**预填进身份表单** ⇒ 错的预填比空字段危险)。
|
||||
/// 真实闭环:用户在身份表单里填了 `endpoint` / `tdsEndpoint`
|
||||
/// ⇒ 落进 `tdc_identity.f_endpoint` / `f_tds_endpoint` ⇒ 之后 `me` 就带出来 ⇒ 编辑时自动回填 ✓
|
||||
pub async fn me(State(state): State<AppState>, p: Option<Extension<Principal>>) -> Response {
|
||||
let (access_allowed, account) = match p.as_ref().map(|e| &e.0) {
|
||||
Some(Principal::Account { account, .. }) => (true, account.clone()),
|
||||
@@ -296,7 +305,8 @@ pub async fn me(State(state): State<AppState>, p: Option<Extension<Principal>>)
|
||||
None => return ActionResult::fail("连接器身份不存在").into_response(),
|
||||
};
|
||||
let sql = "SELECT f_id, f_identity_code, f_name, f_subject_id, f_subject_name, f_capability, \
|
||||
f_status, f_register_status, f_tds_space_id, f_tds_space_name \
|
||||
f_status, f_register_status, f_tds_space_id, f_tds_space_name, \
|
||||
f_endpoint, f_tds_endpoint \
|
||||
FROM tdc_identity WHERE f_id = $1 AND f_delete_mark IS NULL LIMIT 1";
|
||||
let rows = {
|
||||
let _g = state.db_lock.lock().await;
|
||||
@@ -313,8 +323,16 @@ pub async fn me(State(state): State<AppState>, p: Option<Extension<Principal>>)
|
||||
Some(r) => r,
|
||||
None => return ActionResult::fail("连接器身份不存在").into_response(),
|
||||
};
|
||||
ActionResult::ok(me_payload(row, access_allowed, &account)).into_response()
|
||||
}
|
||||
|
||||
/// `Auth/Me` 的 `data` 组装(纯函数 ⇒ 可单测)。
|
||||
///
|
||||
/// 键集合是**前端逐字读的契约**(`Login.vue` / `IdentityManage.vue` / `ProductManage.vue` /
|
||||
/// `ContractView.vue`)⇒ 只加键、不删键、不改既有键名。
|
||||
pub fn me_payload(row: &Value, access_allowed: bool, account: &str) -> Value {
|
||||
let pick = |k: &str| row.get(k).cloned().unwrap_or(Value::Null);
|
||||
ActionResult::ok(json!({
|
||||
json!({
|
||||
"accessAllowed": access_allowed,
|
||||
// `reason`:上游 `Auth/Me` 的拒因字段。登录页 `Login.vue` 的失败分支
|
||||
// 读 `me?.reason || '账号无权访问本连接器'` ⇒ 本连接器单体部署、永不拒 ⇒ 恒 null。
|
||||
@@ -332,8 +350,12 @@ pub async fn me(State(state): State<AppState>, p: Option<Extension<Principal>>)
|
||||
// 用来给「目标空间」列预选默认值 ⇒ 必须返回,不能只给 `tdsSpaceName`。
|
||||
"tdsSpaceId": pick("f_tds_space_id"),
|
||||
"tdsSpaceName": pick("f_tds_space_name"),
|
||||
}))
|
||||
.into_response()
|
||||
// 🔴 `endpoint` / `tdsEndpoint` 前端真的读(`IdentityManage.vue:102-103`:
|
||||
// `connIdentity` 就是 `me`,表单预填从 `me.endpoint` / `me.tdsEndpoint` 取)。
|
||||
// 两列在库里**可能为 NULL** ⇒ 值就是 null(不回退、不塞空串、不编造默认地址)。
|
||||
"endpoint": pick("f_endpoint"),
|
||||
"tdsEndpoint": pick("f_tds_endpoint"),
|
||||
})
|
||||
}
|
||||
|
||||
/// 连接器可用空间列表:`GET /api/ssw/tdc/Auth/Spaces`。
|
||||
@@ -442,7 +464,7 @@ mod tests {
|
||||
/// 🔴 `me` 的 `data` 形状是前端逐字读的 ⇒ 键名集合不得漂移。
|
||||
#[test]
|
||||
fn me_payload_key_set_is_stable() {
|
||||
// 与 `me` handler 里 json! 的键一一对应(这里只锁「键名集合」)。
|
||||
// 与 `me_payload` 里 json! 的键一一对应(这里只锁「键名集合」)。
|
||||
let keys = [
|
||||
"accessAllowed",
|
||||
"reason",
|
||||
@@ -457,9 +479,51 @@ mod tests {
|
||||
"registerStatus",
|
||||
"tdsSpaceId",
|
||||
"tdsSpaceName",
|
||||
"endpoint",
|
||||
"tdsEndpoint",
|
||||
];
|
||||
assert_eq!(keys.len(), 13, "me 的字段数(brief 正文写 12,实为 13)");
|
||||
assert_eq!(keys.len(), 15, "me 的字段数(13 + endpoint/tdsEndpoint)");
|
||||
assert!(!keys.contains(&"secretKey"), "不得回显密钥");
|
||||
assert!(!keys.contains(&"f_secret_key"), "不得回显密钥列");
|
||||
}
|
||||
|
||||
/// 🔴 `endpoint` / `tdsEndpoint` 在库里为 NULL 时,键**仍然存在**、值是 `null`
|
||||
/// (不是缺键、不是空串)—— 上游回退 `tdc-report.base-url` 的行为本仓**刻意不做**。
|
||||
#[test]
|
||||
fn me_payload_keeps_null_endpoint_keys_when_columns_are_null() {
|
||||
let row = json!({
|
||||
"f_id": "id-1",
|
||||
"f_identity_code": "LOCAL-CONNECTOR",
|
||||
"f_name": "本地连接器",
|
||||
"f_subject_id": Value::Null,
|
||||
"f_subject_name": Value::Null,
|
||||
"f_capability": Value::Null,
|
||||
"f_status": "ONLINE",
|
||||
"f_register_status": "REGISTERED",
|
||||
"f_tds_space_id": Value::Null,
|
||||
"f_tds_space_name": Value::Null,
|
||||
"f_endpoint": Value::Null,
|
||||
"f_tds_endpoint": Value::Null,
|
||||
});
|
||||
let payload = me_payload(&row, true, "LOCAL-CONNECTOR");
|
||||
assert!(payload.get("endpoint").is_some());
|
||||
assert!(payload.get("tdsEndpoint").is_some());
|
||||
assert!(payload["endpoint"].is_null());
|
||||
assert!(payload["tdsEndpoint"].is_null());
|
||||
// 键集合仍是 15 个(不多不少)
|
||||
assert_eq!(payload.as_object().unwrap().len(), 15);
|
||||
}
|
||||
|
||||
/// 有值时按列原样带出(不回退、不改写)。
|
||||
#[test]
|
||||
fn me_payload_carries_endpoint_values_when_present() {
|
||||
let row = json!({
|
||||
"f_endpoint": "http://127.0.0.1:30040",
|
||||
"f_tds_endpoint": "http://127.0.0.1:30041",
|
||||
});
|
||||
let payload = me_payload(&row, false, "");
|
||||
assert_eq!(payload["endpoint"], json!("http://127.0.0.1:30040"));
|
||||
assert_eq!(payload["tdsEndpoint"], json!("http://127.0.0.1:30041"));
|
||||
assert_eq!(payload["accessAllowed"], json!(false));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user