fix: 修复系统一致性与安全问题
This commit is contained in:
1 parent
aaeec14733
commit
f158f906d5
19 files changed
+194
-34
No files matched your search
@@ -132,7 +132,8 @@ export class CustomerInquirySubmissionController {
|
||||
if (field.type === "number" && !Number.isFinite(Number(value)))
|
||||
throw new BadRequestException(`${label}必须是数字`);
|
||||
}
|
||||
const allowedKeys = new Set(fields.map((field) => String(field.key)));
|
||||
const visibleFields = fields.filter((field) => this.isVisibleField(field, body.values));
|
||||
const allowedKeys = new Set(visibleFields.map((field) => String(field.key)));
|
||||
const values = Object.fromEntries(
|
||||
Object.entries(body.values).filter(([key]) => allowedKeys.has(key)),
|
||||
);
|
||||
@@ -150,4 +151,29 @@ export class CustomerInquirySubmissionController {
|
||||
});
|
||||
return this.present(submission);
|
||||
}
|
||||
|
||||
private visibilityRuleMatches(rule: unknown, values: Record<string, unknown>): boolean {
|
||||
if (!rule || typeof rule !== "object") return true;
|
||||
const item = rule as Record<string, unknown>;
|
||||
if (typeof item.field !== "string") return true;
|
||||
const value = values[item.field];
|
||||
switch (item.operator) {
|
||||
case "exists":
|
||||
return Array.isArray(value) ? value.length > 0 : Boolean(value);
|
||||
case "equals":
|
||||
return value === item.value;
|
||||
case "not-equals":
|
||||
return value !== item.value;
|
||||
case "in":
|
||||
return Array.isArray(item.value) && typeof value === "string" && item.value.includes(value);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private isVisibleField(field: Record<string, unknown>, values: Record<string, unknown>): boolean {
|
||||
return (Array.isArray(field.visibleWhen) ? field.visibleWhen : []).every((rule) =>
|
||||
this.visibilityRuleMatches(rule, values),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user