|
|
@@ -397,6 +397,9 @@ pub fn ops_province_write_allowed(
|
|
|
/// 「失败关闭/回落本地 `bos_data_scope`」同口径;
|
|
|
/// * 两边都有有效省 ⇒ 取交;
|
|
|
/// * 本地空、注入有有效省 ⇒ 用注入。
|
|
|
+///
|
|
|
+/// 口径 A(2026-11-28):写口认**负责范围**省份(`bos_data_scope`/注入),⛔ 用档案
|
|
|
+/// `region_node_id` 单点冒充上界。
|
|
|
pub fn merge_ops_province_allowed(
|
|
|
local_allowed: &std::collections::HashSet<String>,
|
|
|
grant_seeds_present: bool,
|
|
|
@@ -417,6 +420,39 @@ pub fn merge_ops_province_allowed(
|
|
|
.collect()
|
|
|
}
|
|
|
|
|
|
+/// BUG-3D-48:拆出交集两侧被抹掉的省,便于拒写文案/日志对账(⛔ 改判权结果)。
|
|
|
+///
|
|
|
+/// 返回 `(allowed, local_only, granted_only)`:
|
|
|
+/// * `local_only`=本地有、最终 allowed 没有(典型=注入收窄抹省);
|
|
|
+/// * `granted_only`=注入有、最终 allowed 没有(典型=本地范围更窄);
|
|
|
+/// * 非「两边都有效后取交」形态 ⇒ 两侧差集皆空(回落/单边采用不叫「抹省」)。
|
|
|
+pub fn province_merge_explain(
|
|
|
+ local_allowed: &std::collections::HashSet<String>,
|
|
|
+ grant_seeds_present: bool,
|
|
|
+ grant_allowed: &std::collections::HashSet<String>,
|
|
|
+) -> (
|
|
|
+ std::collections::HashSet<String>,
|
|
|
+ std::collections::HashSet<String>,
|
|
|
+ std::collections::HashSet<String>,
|
|
|
+) {
|
|
|
+ let allowed = merge_ops_province_allowed(local_allowed, grant_seeds_present, grant_allowed);
|
|
|
+ let intersecting = grant_seeds_present
|
|
|
+ && !grant_allowed.is_empty()
|
|
|
+ && !local_allowed.is_empty();
|
|
|
+ if !intersecting {
|
|
|
+ return (allowed, std::collections::HashSet::new(), std::collections::HashSet::new());
|
|
|
+ }
|
|
|
+ let local_only = local_allowed.difference(&allowed).cloned().collect();
|
|
|
+ let granted_only = grant_allowed.difference(&allowed).cloned().collect();
|
|
|
+ (allowed, local_only, granted_only)
|
|
|
+}
|
|
|
+
|
|
|
+fn sorted_csv(ids: &std::collections::HashSet<String>) -> String {
|
|
|
+ let mut v: Vec<_> = ids.iter().cloned().collect();
|
|
|
+ v.sort();
|
|
|
+ v.join(",")
|
|
|
+}
|
|
|
+
|
|
|
/// 节点 → 最近省级祖先 id(闭包含自身 ⇒ 省节点命中自身);祖先链无「省」⇒ `None`。
|
|
|
async fn nearest_province_node(
|
|
|
state: &AppState,
|
|
|
@@ -563,17 +599,29 @@ pub async fn assert_ops_region_tree_write(
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
- let allowed = merge_ops_province_allowed(&local_allowed, grant_seeds_present, &grant_allowed);
|
|
|
+ let (allowed, local_only, granted_only) =
|
|
|
+ province_merge_explain(&local_allowed, grant_seeds_present, &grant_allowed);
|
|
|
+ if !local_only.is_empty() || !granted_only.is_empty() {
|
|
|
+ tracing::warn!(
|
|
|
+ local_provinces = %sorted_csv(&local_allowed),
|
|
|
+ granted_provinces = %sorted_csv(&grant_allowed),
|
|
|
+ allowed_provinces = %sorted_csv(&allowed),
|
|
|
+ local_only = %sorted_csv(&local_only),
|
|
|
+ granted_only = %sorted_csv(&granted_only),
|
|
|
+ "区域写口:负责省取交后有省被抹掉(注入只收窄;详见 BUG-3D-48)"
|
|
|
+ );
|
|
|
+ }
|
|
|
let target_province = nearest_province_node(state, anchor).await?;
|
|
|
if !ops_province_write_allowed(&allowed, target_province.as_deref()) {
|
|
|
return Err(BosError::forbidden_role(format!(
|
|
|
"区域 {anchor} 不在本团队负责省份下,区域运营主/子账号不能建/改(KLT-P301);\
|
|
|
- allowed_provinces={} local_seeds={} grant_seeds={} discarded_grant_seeds={}",
|
|
|
- {
|
|
|
- let mut v: Vec<_> = allowed.iter().cloned().collect();
|
|
|
- v.sort();
|
|
|
- v.join(",")
|
|
|
- },
|
|
|
+ allowed_provinces={} local_provinces={} granted_provinces={} \
|
|
|
+ local_only={} granted_only={} local_seeds={} grant_seeds={} discarded_grant_seeds={}",
|
|
|
+ sorted_csv(&allowed),
|
|
|
+ sorted_csv(&local_allowed),
|
|
|
+ sorted_csv(&grant_allowed),
|
|
|
+ sorted_csv(&local_only),
|
|
|
+ sorted_csv(&granted_only),
|
|
|
local_seeds.join(","),
|
|
|
grant_seeds.join(","),
|
|
|
discarded_grant_seeds.join(","),
|
|
|
@@ -966,7 +1014,7 @@ pub async fn pairs_by_where(
|
|
|
mod tests {
|
|
|
use super::{
|
|
|
collect_allowed_provinces, is_ops_region_writable_level, merge_ops_province_allowed,
|
|
|
- ops_province_write_allowed,
|
|
|
+ ops_province_write_allowed, province_merge_explain,
|
|
|
};
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
@@ -1040,4 +1088,27 @@ mod tests {
|
|
|
jiangsu
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /// BUG-3D-48:交集抹省须可观测(local_only/granted_only),⛔ 改 allowed 结果。
|
|
|
+ #[test]
|
|
|
+ fn province_merge_explain_exposes_intersect_stripping() {
|
|
|
+ let local = HashSet::from([
|
|
|
+ "上海".to_string(),
|
|
|
+ "江苏".to_string(),
|
|
|
+ "广东".to_string(),
|
|
|
+ ]);
|
|
|
+ let grant = HashSet::from(["上海".to_string(), "江苏".to_string()]);
|
|
|
+ let (allowed, local_only, granted_only) = province_merge_explain(&local, true, &grant);
|
|
|
+ assert_eq!(allowed, grant);
|
|
|
+ assert_eq!(local_only, HashSet::from(["广东".to_string()]));
|
|
|
+ assert!(granted_only.is_empty());
|
|
|
+
|
|
|
+ // 回落/无注入 ⇒ 不叫抹省,差集空
|
|
|
+ let (a2, lo2, go2) = province_merge_explain(&local, false, &HashSet::new());
|
|
|
+ assert_eq!(a2, local);
|
|
|
+ assert!(lo2.is_empty() && go2.is_empty());
|
|
|
+ let (a3, lo3, go3) = province_merge_explain(&local, true, &HashSet::new());
|
|
|
+ assert_eq!(a3, local);
|
|
|
+ assert!(lo3.is_empty() && go3.is_empty());
|
|
|
+ }
|
|
|
}
|