WOUAFIX 收口 OA 与企微用户一致性差异
这个提交包含在:
@@ -208,10 +208,23 @@ async function ensureAdminEmployee(prisma, params) {
|
||||
|
||||
const existing = await prisma.employee.findFirst({
|
||||
where: { OR: [{ email: params.email }, { phone: params.phone }] },
|
||||
select: { id: true, email: true, phone: true, status: true },
|
||||
select: { id: true, employee_no: true, email: true, phone: true, status: true, archived_at: true },
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
if ((existing.status === "archived" || existing.archived_at) && process.env.TRIALRUN_ADMIN_REACTIVATE_ARCHIVED !== "1") {
|
||||
const fallbackAdmin = await findActiveAdminEmployee(prisma, existing.id);
|
||||
if (fallbackAdmin) {
|
||||
return {
|
||||
employeeId: fallbackAdmin.id,
|
||||
created: false,
|
||||
password: null,
|
||||
skippedArchived: true,
|
||||
fallbackEmployeeNo: fallbackAdmin.employee_no,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.employee.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
@@ -278,6 +291,23 @@ async function ensureAdminEmployee(prisma, params) {
|
||||
return { employeeId: employee.id, created: true, password };
|
||||
}
|
||||
|
||||
async function findActiveAdminEmployee(prisma, excludedEmployeeId) {
|
||||
const where = {
|
||||
status: "active",
|
||||
archived_at: null,
|
||||
roles: { some: { role_code: "admin" } },
|
||||
};
|
||||
if (excludedEmployeeId) {
|
||||
where.id = { not: excludedEmployeeId };
|
||||
}
|
||||
|
||||
return prisma.employee.findFirst({
|
||||
where,
|
||||
orderBy: { employee_no: "asc" },
|
||||
select: { id: true, employee_no: true },
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const adminEmail = requiredEnv("TRIALRUN_ADMIN_EMAIL");
|
||||
const adminPhone = requiredEnv("TRIALRUN_ADMIN_PHONE");
|
||||
@@ -326,6 +356,10 @@ async function main() {
|
||||
console.log(`- created: ${result.created}`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`- force_on flags: ${forceOnFlags.join(", ")}`);
|
||||
if (result.skippedArchived) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`- archived trialrun admin: kept archived; active admin fallback: ${result.fallbackEmployeeNo}`);
|
||||
}
|
||||
if (result.password) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`- one-time password: ${result.password}`);
|
||||
|
||||
在新工单中引用
屏蔽一个用户