feat: 用户多应用成员关系与微信扫码登录
- 新增 user_app / user_identity 模型、应用注册表与成员关系服务,启动时校验配置覆盖 - 新增微信开放平台扫码登录:二维码地址、回调与 ticket 换取 token - 管理端接口改为路由层声明 appIds + 角色鉴权,新增批量用户信息、锁定、授权与个人配置 - 删除账号同步清理成员关系与外部身份,避免关系被新账号复用 - 补充多应用、应用配置、注册表测试与迁移/建号脚本
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
import config from "../conf.json" with { type: "json" };
|
||||
|
||||
/**
|
||||
* appId -> 平台/登录方式 元数据
|
||||
*
|
||||
* conf.json 只放 appid / secret;平台与登录方式放代码里,便于评审与测试。
|
||||
* 未在 conf.json 配置的应用(ttapp-escort / web-escort-admin / tcm)
|
||||
* 只告警不阻塞启动:它们可能通过密码登录或其他服务写入成员关系。
|
||||
*/
|
||||
export const APP_REGISTRY = {
|
||||
"wxapp-escort": { platform: "weixin", provider: "weixin-mini" },
|
||||
"wxapp-escort-admin": { platform: "weixin", provider: "weixin-mini" },
|
||||
"ttapp-escort": { platform: "douyin", provider: "douyin-mini" },
|
||||
"web-escort-admin": { platform: "weixin", provider: "weixin-web" },
|
||||
tcm: { platform: "web", provider: "password" },
|
||||
};
|
||||
|
||||
// 管理端应用:任一应用内的 admin 都视为管理端管理员
|
||||
export const ADMIN_APP_IDS = ["wxapp-escort-admin", "web-escort-admin"];
|
||||
|
||||
// 本阶段只做固定角色白名单,不引入自定义 RBAC
|
||||
export const GRANTABLE_ROLES = ["user", "admin"];
|
||||
|
||||
/**
|
||||
* 启动校验:conf.json 中的 appId 必须有元数据;appId 不能含 . 或 $,
|
||||
* 否则会被当成 Mongo 路径写坏文档。
|
||||
*/
|
||||
export function assertRegistryCoverage() {
|
||||
const configured = Object.keys(config.app || {});
|
||||
|
||||
const invalid = configured.filter((id) => !/^[A-Za-z0-9_-]+$/.test(id));
|
||||
if (invalid.length) {
|
||||
throw new Error(`conf.json 中存在非法 appId(只允许字母、数字、_、-): ${invalid.join(", ")}`);
|
||||
}
|
||||
|
||||
const missing = configured.filter((id) => !APP_REGISTRY[id]);
|
||||
if (missing.length) {
|
||||
throw new Error(`APP_REGISTRY 缺少 appId 元数据: ${missing.join(", ")}`);
|
||||
}
|
||||
|
||||
const orphan = Object.keys(APP_REGISTRY).filter((id) => !configured.includes(id));
|
||||
if (orphan.length) {
|
||||
console.warn(`[user] APP_REGISTRY 中未在 conf.json 配置的 appId: ${orphan.join(", ")}`);
|
||||
}
|
||||
|
||||
return configured;
|
||||
}
|
||||
Reference in New Issue
Block a user