fix(exports): 修正 creator_in 过滤条件逻辑
- 调整在 marketing 数据集的 order 或 order_info 主要表时, 当存在 plan_id_eq 或 reseller_id_eq 过滤参数,不设置 creator_in - 在 mergePermissionIntoFilters 函数中,传递了 plan_id_eq 或 reseller_id_eq 时, 删除已有的 creator_in 和 creator_ids 过滤,避免重复过滤 - 优化过滤逻辑,确保在特定条件下 creator_in 不会被错误附加 - 保留当 creator_in 已经存在且非空时的过滤行为不变
This commit is contained in:
parent
13b4ff56df
commit
4b573d3981
|
|
@ -118,22 +118,20 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
// FORCE set creator_in if URL params are present, even if p.Filters had something else (which is unlikely if mergePermission worked, but let's be safe)
|
||||
// Actually, we should probably append or merge? For now, let's assume URL overrides or merges if key missing.
|
||||
// Logic before was: if _, exists := p.Filters["creator_in"]; !exists { ... }
|
||||
// But if user passed userId in URL, they probably want it to be used.
|
||||
// If p.Filters["creator_in"] came from `Permission`, it might be the logged-in user.
|
||||
// If the user is an admin acting as another user (passed in URL), we should probably use the URL one?
|
||||
// But `mergePermissionIntoFilters` logic is strict.
|
||||
// Let's keep existing logic: if permission set it, don't override.
|
||||
// Wait, if permission is empty (e.g. admin), then `creator_in` is missing.
|
||||
// 如果传递了 plan_id_eq 或 reseller_id_eq,不设置 creator_in
|
||||
skipCreator := false
|
||||
if ds == "marketing" && (main == "order" || main == "order_info") {
|
||||
if v, ok := p.Filters["plan_id_eq"]; ok && v != nil && v != "" && v != 0 {
|
||||
skipCreator = true
|
||||
}
|
||||
if v, ok := p.Filters["reseller_id_eq"]; ok && v != nil && v != "" && v != 0 {
|
||||
skipCreator = true
|
||||
}
|
||||
}
|
||||
if !skipCreator {
|
||||
if _, exists := p.Filters["creator_in"]; !exists {
|
||||
p.Filters["creator_in"] = ids
|
||||
} else {
|
||||
// If it exists, should we merge?
|
||||
// If the existing one is from permission, it's a boundary.
|
||||
// If we are admin, permission might be empty.
|
||||
// Let's trust `mergePermissionIntoFilters`.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1555,10 +1553,6 @@ func mergePermissionIntoFilters(ds, main string, perm map[string]interface{}, fi
|
|||
if filters == nil {
|
||||
filters = map[string]interface{}{}
|
||||
}
|
||||
// if creator_in already present, keep it
|
||||
if hasNonEmptyIDs(filters["creator_in"]) {
|
||||
return filters
|
||||
}
|
||||
// 先处理 plan_id_eq 和 reseller_id_eq 的设置
|
||||
if v, ok := pickFirst(perm, filters, []string{"reseller_id", "merchant_id"}); ok {
|
||||
filters["reseller_id_eq"] = v
|
||||
|
|
@ -1566,15 +1560,26 @@ func mergePermissionIntoFilters(ds, main string, perm map[string]interface{}, fi
|
|||
if v, ok := pickFirst(perm, filters, []string{"plan_id", "activity_id"}); ok {
|
||||
filters["plan_id_eq"] = v
|
||||
}
|
||||
// 如果传递了 plan_id_eq 或 reseller_id_eq 且不为空,则不再过滤 creator
|
||||
// 如果传递了 plan_id_eq 或 reseller_id_eq 且不为空,则删除已有的 creator_in 并跳过设置
|
||||
if ds == "marketing" && (main == "order" || main == "order_info") {
|
||||
hasPlanOrReseller := false
|
||||
if v, ok := filters["plan_id_eq"]; ok && v != nil && v != "" && v != 0 {
|
||||
goto skipCreator
|
||||
hasPlanOrReseller = true
|
||||
}
|
||||
if v, ok := filters["reseller_id_eq"]; ok && v != nil && v != "" && v != 0 {
|
||||
hasPlanOrReseller = true
|
||||
}
|
||||
if hasPlanOrReseller {
|
||||
// 删除已有的 creator_in
|
||||
delete(filters, "creator_in")
|
||||
delete(filters, "creator_ids")
|
||||
goto skipCreator
|
||||
}
|
||||
}
|
||||
// if creator_in already present, keep it
|
||||
if hasNonEmptyIDs(filters["creator_in"]) {
|
||||
return filters
|
||||
}
|
||||
// try known keys
|
||||
{
|
||||
candidates := []string{"creator_in", "creator_ids", "user_ids", "user_id_in", "user_id", "owner_id"}
|
||||
|
|
|
|||
Loading…
Reference in New Issue