diff --git a/web/src/lib/taskQueries.test.ts b/web/src/lib/taskQueries.test.ts index fc85fc0..342091e 100644 --- a/web/src/lib/taskQueries.test.ts +++ b/web/src/lib/taskQueries.test.ts @@ -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({}); }); }); diff --git a/web/src/lib/taskQueries.ts b/web/src/lib/taskQueries.ts index a6d9bd6..3021535 100644 --- a/web/src/lib/taskQueries.ts +++ b/web/src/lib/taskQueries.ts @@ -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 = {}; 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), ))