Remediated test #1 results
This commit is contained in:
@@ -512,6 +512,7 @@ export const getRiskScoreColor = (likelihood: RiskLikelihood | number, impact: R
|
||||
// ==========================================
|
||||
|
||||
const USER_EMAIL_CACHE: Record<string, string> = {};
|
||||
const EMAIL_TO_USER_ID_CACHE: Record<string, string> = {};
|
||||
|
||||
export const registerUserEmail = (userId: string | number, email: string) => {
|
||||
if (userId && email && typeof email === 'string' && email.trim()) {
|
||||
@@ -519,6 +520,7 @@ export const registerUserEmail = (userId: string | number, email: string) => {
|
||||
const cleanEmail = email.trim();
|
||||
USER_EMAIL_CACHE[cleanId] = cleanEmail;
|
||||
USER_EMAIL_CACHE[cleanId.toLowerCase()] = cleanEmail;
|
||||
EMAIL_TO_USER_ID_CACHE[cleanEmail.toLowerCase()] = cleanId;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -531,6 +533,11 @@ export const registerUserEmails = (users: Array<{ id: string | number; email?: s
|
||||
}
|
||||
};
|
||||
|
||||
export const getUserIdByEmail = (email?: string | null): string | undefined => {
|
||||
if (!email || typeof email !== 'string') return undefined;
|
||||
return EMAIL_TO_USER_ID_CACHE[email.trim().toLowerCase()];
|
||||
};
|
||||
|
||||
export const getUserEmail = (userIdOrEmail?: string | number | null): string => {
|
||||
if (!userIdOrEmail) return '—';
|
||||
const str = String(userIdOrEmail).trim();
|
||||
@@ -538,5 +545,28 @@ export const getUserEmail = (userIdOrEmail?: string | number | null): string =>
|
||||
if (str.includes('@')) return str;
|
||||
if (USER_EMAIL_CACHE[str]) return USER_EMAIL_CACHE[str];
|
||||
if (USER_EMAIL_CACHE[str.toLowerCase()]) return USER_EMAIL_CACHE[str.toLowerCase()];
|
||||
|
||||
// Synchronous fallback from stored auth session in browser
|
||||
try {
|
||||
const storedUserJson = localStorage.getItem('pfm_auth_user');
|
||||
const storedSub = localStorage.getItem('pfm_user_sub');
|
||||
if (storedUserJson) {
|
||||
const parsed = JSON.parse(storedUserJson);
|
||||
if (parsed?.email) {
|
||||
const email = String(parsed.email).trim();
|
||||
if (
|
||||
(parsed.id && String(parsed.id).toLowerCase() === str.toLowerCase()) ||
|
||||
(parsed.sub && String(parsed.sub).toLowerCase() === str.toLowerCase()) ||
|
||||
(storedSub && String(storedSub).toLowerCase() === str.toLowerCase())
|
||||
) {
|
||||
registerUserEmail(str, email);
|
||||
return email;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore storage parse errors
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user