Harden Tasgird user task lookup

This commit is contained in:
2026-03-29 03:16:07 +00:00
parent e6b727b345
commit 69c8d80ef2
2 changed files with 29 additions and 3 deletions
+22 -1
View File
@@ -559,6 +559,23 @@ app.get('/api/tasks/list', async (c) => {
return matched.map((user: any) => String(user.id || '').trim()).filter(Boolean);
}
try {
const allUsers = await taskPb.collection(PB_AUTH_COLLECTION).getFullList({
fields: 'id,name,email,username',
});
const lowerTarget = target.toLowerCase();
const fuzzy = allUsers.filter((user: any) => {
const values = [user?.name, user?.username, user?.email]
.map((value) => String(value || '').trim().toLowerCase())
.filter(Boolean);
return values.includes(lowerTarget);
});
if (fuzzy.length) {
return fuzzy.map((user: any) => String(user.id || '').trim()).filter(Boolean);
}
} catch {
}
if (meId && target === meName) {
return [meId];
}
@@ -572,7 +589,11 @@ app.get('/api/tasks/list', async (c) => {
let effectiveUserName = targetUserName;
try {
if (targetUserName) {
const targetUserIds = await resolveUserIdsByName(targetUserName);
const targetUserIds = Array.from(new Set([
...(await resolveUserIdsByName(targetUserName)),
...(requestedUserId ? [requestedUserId] : []),
...(meId && targetUserName === meName ? [meId] : []),
].map((id) => String(id || '').trim()).filter(Boolean)));
if (!targetUserIds.length) {
warning = `No Users record matched name "${targetUserName}".`;
records = [];