优化配送订单联系人受控展示
This commit is contained in:
@@ -175,7 +175,27 @@ func getGasorderBasic(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, common.ProtectPreciseLocation(ctx, &models.GasorderBasic{}, response))
|
||||
protected := common.ProtectPreciseLocation(ctx, &models.GasorderBasic{}, response)
|
||||
infra.Response.Success(ctx, restorePlatformGasorderDetailContacts(protected, order))
|
||||
}
|
||||
|
||||
// restorePlatformGasorderDetailContacts 仅为已通过平台订单菜单鉴权的详情接口恢复联系人快照明文。
|
||||
// 参数:value 为完成公共字段保护后的详情响应,order 为当前订单数据库记录。
|
||||
// 返回值:恢复联系人姓名和电话、且移除对应脱敏辅助键后的详情响应。
|
||||
func restorePlatformGasorderDetailContacts(value any, order models.GasorderBasic) any {
|
||||
response, ok := value.(map[string]any)
|
||||
if !ok {
|
||||
return value
|
||||
}
|
||||
detail, ok := response["order"].(map[string]any)
|
||||
if !ok {
|
||||
return value
|
||||
}
|
||||
detail["contact_name"] = order.ContactName
|
||||
detail["contact_phone"] = order.ContactPhone
|
||||
delete(detail, "contact_name_masked")
|
||||
delete(detail, "contact_phone_masked")
|
||||
return value
|
||||
}
|
||||
|
||||
func CreateGasorderContract(ctx *gin.Context) {
|
||||
|
||||
@@ -285,3 +285,25 @@ func TestGasorderSensitiveContactsAreMasked(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlatformGasorderDetailRestoresContacts 验证平台订单详情受控恢复联系人明文并删除脱敏辅助键。
|
||||
func TestPlatformGasorderDetailRestoresContacts(t *testing.T) {
|
||||
value := map[string]any{
|
||||
"order": map[string]any{
|
||||
"contact_name_masked": "张*",
|
||||
"contact_phone_masked": "138****8000",
|
||||
},
|
||||
}
|
||||
order := models.GasorderBasic{ContactName: "张三", ContactPhone: "13800138000"}
|
||||
restored := restorePlatformGasorderDetailContacts(value, order).(map[string]any)
|
||||
detail := restored["order"].(map[string]any)
|
||||
if detail["contact_name"] != "张三" || detail["contact_phone"] != "13800138000" {
|
||||
t.Fatalf("平台订单详情未恢复联系人明文: %#v", detail)
|
||||
}
|
||||
if _, exists := detail["contact_name_masked"]; exists {
|
||||
t.Fatalf("平台订单详情仍包含联系人脱敏辅助键: %#v", detail)
|
||||
}
|
||||
if _, exists := detail["contact_phone_masked"]; exists {
|
||||
t.Fatalf("平台订单详情仍包含联系电话脱敏辅助键: %#v", detail)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user