fix(web): check the task owner in loadTaskTags too

A link joins two owned rows: REVIEW.md asks for the ownership check on both
sides, so loadTaskTags also joins sl_tasks on the account (still one query).

Refs #179

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
le king fu 2026-11-02 21:19:43 -05:00
commit d98b3e5bff
2 changed files with 8 additions and 4 deletions

View file

@ -111,8 +111,9 @@ describe('loadTaskTags', () => {
const other = await foreignTagOn(a.t2);
const map = await loadTaskTags(a.userId, [a.t1, a.t2]);
expect(map[a.t2].map((t) => t.id)).toEqual([a.blue]);
// Nor are the tags of `a` returned to the other account.
expect(await loadTaskTags(other.userId, [a.t1, a.t2])).toEqual({ [a.t2]: [{ id: other.tag, name: 'foreign', color: '#4A90A4' }] });
// The task side is checked too: the other account gets nothing for tasks
// of `a`, its own tag included.
expect(await loadTaskTags(other.userId, [a.t1, a.t2])).toEqual({});
});
});

View file

@ -92,8 +92,9 @@ export async function loadSubtasks(userId: string, parentIds: string[]) {
return map;
}
// Tags of the given tasks, grouped by task id, in one query. Deleted tags and
// tags of another account never appear.
// Tags of the given tasks, grouped by task id, in one query. Ownership is
// checked on both sides of the link: deleted tags, tags of another account and
// tasks of another account never appear.
export async function loadTaskTags(userId: string, taskIds: string[]) {
const map: Record<string, TaskTagPill[]> = {};
if (taskIds.length === 0) return map;
@ -101,8 +102,10 @@ export async function loadTaskTags(userId: string, taskIds: string[]) {
.select({ taskId: slTaskTags.taskId, id: slTags.id, name: slTags.name, color: slTags.color })
.from(slTaskTags)
.innerJoin(slTags, eq(slTags.id, slTaskTags.tagId))
.innerJoin(slTasks, eq(slTasks.id, slTaskTags.taskId))
.where(and(
inArray(slTaskTags.taskId, taskIds),
eq(slTasks.userId, userId),
eq(slTags.userId, userId),
isNull(slTags.deletedAt),
))