Files
ln-bi/src/server/auth/manager-identity.ts
T
shishengliang f1b3f8d3da
ci/woodpecker/push/woodpecker Pipeline was successful
feat(assets): add dimension analysis and authorized user previews
Refactor asset drilldowns with combined dimension filters, parent summaries and progressive loading. Add the hidden /who read-only permission preview with scoped authorization, identity mapping and audit logging. Refine inventory counts and AI问数 presentation.
2026-09-28 12:29:51 +08:00

21 lines
1.3 KiB
TypeScript

import pool from '../db.js';
/** Match login identifiers only, never human names. Ambiguous or disabled identities fail closed. */
export async function resolveVehicleManagerIds(userId: string, loginName: string): Promise<string[]> {
const schema = process.env.BI_IDENTITY_SCHEMA || 'lingniu_prod';
if (!/^[a-zA-Z0-9_]+$/.test(schema)) throw new Error('Invalid identity schema');
const [rows] = await pool.query<any[]>(`SELECT CAST(u.id AS CHAR) legacyId, CAST(n.user_id AS CHAR) vehicleId
FROM \`${schema}\`.tab_user u
LEFT JOIN \`ry-cloud\`.sys_user n ON BINARY n.user_name=BINARY u.login_name
AND n.tenant_id=? AND n.del_flag='0' AND n.status='0'
WHERE u.id=? AND BINARY u.login_name=BINARY ? AND u.enabled=1 AND u.is_deleted=0
AND (SELECT COUNT(*) FROM \`${schema}\`.tab_user duplicate
WHERE BINARY duplicate.login_name=BINARY u.login_name AND duplicate.enabled=1 AND duplicate.is_deleted=0)=1`,
[process.env.BI_VEHICLE_IDENTITY_TENANT_ID || '000000', userId, loginName]);
return verifiedManagerIds(userId, rows);
}
export function verifiedManagerIds(userId: string, rows: { legacyId: string; vehicleId: string | null }[]): string[] {
if (rows.length !== 1 || rows[0].legacyId !== userId) return [];
return [...new Set([userId, ...(rows[0].vehicleId ? [rows[0].vehicleId] : [])])];
}