fix: update public board lookup to filter by workspace slug

This commit is contained in:
Henry
2025-07-28 22:21:52 +01:00
parent ca1dd92ab4
commit 28d2de4dad
3 changed files with 35 additions and 6 deletions

View File

@@ -28,9 +28,14 @@ export default function PublicBoardView() {
? router.query.boardSlug[0] ? router.query.boardSlug[0]
: router.query.boardSlug; : router.query.boardSlug;
const workspaceSlug = Array.isArray(router.query.workspaceSlug)
? router.query.workspaceSlug[0]
: router.query.workspaceSlug;
const { data, isLoading } = api.board.bySlug.useQuery( const { data, isLoading } = api.board.bySlug.useQuery(
{ {
boardSlug: boardSlug ?? "", boardSlug: boardSlug ?? "",
workspaceSlug: workspaceSlug ?? "",
members: formatToArray(router.query.members), members: formatToArray(router.query.members),
labels: formatToArray(router.query.labels), labels: formatToArray(router.query.labels),
}, },

View File

@@ -111,15 +111,21 @@ export const boardRouter = createTRPCRouter({
.meta({ .meta({
openapi: { openapi: {
method: "GET", method: "GET",
path: "/board/{boardSlug}", path: "/workspaces/{workspaceSlug}/boards/{boardSlug}",
summary: "Get board by slug", summary: "Get board by slug",
description: "Retrieves a board by its slug", description:
"Retrieves a board by its slug within a specific workspace",
tags: ["Boards"], tags: ["Boards"],
protect: false, protect: false,
}, },
}) })
.input( .input(
z.object({ z.object({
workspaceSlug: z
.string()
.min(3)
.max(24)
.regex(/^(?![-]+$)[a-zA-Z0-9-]+$/),
boardSlug: z boardSlug: z
.string() .string()
.min(3) .min(3)
@@ -131,10 +137,26 @@ export const boardRouter = createTRPCRouter({
) )
.output(z.custom<Awaited<ReturnType<typeof boardRepo.getBySlug>>>()) .output(z.custom<Awaited<ReturnType<typeof boardRepo.getBySlug>>>())
.query(async ({ ctx, input }) => { .query(async ({ ctx, input }) => {
const result = await boardRepo.getBySlug(ctx.db, input.boardSlug, { const workspace = await workspaceRepo.getBySlugWithBoards(
members: input.members ?? [], ctx.db,
labels: input.labels ?? [], input.workspaceSlug,
}); );
if (!workspace)
throw new TRPCError({
message: `Workspace with slug ${input.workspaceSlug} not found`,
code: "NOT_FOUND",
});
const result = await boardRepo.getBySlug(
ctx.db,
input.boardSlug,
workspace.id,
{
members: input.members ?? [],
labels: input.labels ?? [],
},
);
return result; return result;
}), }),

View File

@@ -201,6 +201,7 @@ export const getByPublicId = async (
export const getBySlug = async ( export const getBySlug = async (
db: dbClient, db: dbClient,
boardSlug: string, boardSlug: string,
workspaceId: number,
filters: { filters: {
members: string[]; members: string[];
labels: string[]; labels: string[];
@@ -293,6 +294,7 @@ export const getBySlug = async (
}, },
where: and( where: and(
eq(boards.slug, boardSlug), eq(boards.slug, boardSlug),
eq(boards.workspaceId, workspaceId),
isNull(boards.deletedAt), isNull(boards.deletedAt),
eq(boards.visibility, "public"), eq(boards.visibility, "public"),
), ),