mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +02:00
chore: fix linting
This commit is contained in:
parent
7d4c994900
commit
d6bffa6f07
61 changed files with 167 additions and 218 deletions
|
|
@ -20,7 +20,13 @@ export function constrainToAllowedSpaces<T extends SpaceScopedQuery>(query: T, c
|
|||
if (allowedSpaceIds.length === 1) {
|
||||
return query.where("searchSpaceId", allowedSpaceIds[0]) as T;
|
||||
}
|
||||
return query.where(({ cmp, or }: { cmp: (column: string, value: number) => unknown; or: (...args: unknown[]) => unknown }) =>
|
||||
or(...allowedSpaceIds.map((id) => cmp("searchSpaceId", id)))
|
||||
return query.where(
|
||||
({
|
||||
cmp,
|
||||
or,
|
||||
}: {
|
||||
cmp: (column: string, value: number) => unknown;
|
||||
or: (...args: unknown[]) => unknown;
|
||||
}) => or(...allowedSpaceIds.map((id) => cmp("searchSpaceId", id)))
|
||||
) as T;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ import { constrainToAllowedSpaces } from "./authz";
|
|||
// authorizes via `automation_id -> search_space`. No search_space_id on the
|
||||
// table by design.
|
||||
export const automationRunQueries = {
|
||||
byAutomation: defineQuery(z.object({ automationId: z.number() }), ({ args: { automationId }, ctx }) =>
|
||||
zql.automation_runs
|
||||
.where("automationId", automationId)
|
||||
.whereExists("automation", (q) => constrainToAllowedSpaces(q, ctx))
|
||||
.orderBy("createdAt", "desc")
|
||||
byAutomation: defineQuery(
|
||||
z.object({ automationId: z.number() }),
|
||||
({ args: { automationId }, ctx }) =>
|
||||
zql.automation_runs
|
||||
.where("automationId", automationId)
|
||||
.whereExists("automation", (q) => constrainToAllowedSpaces(q, ctx))
|
||||
.orderBy("createdAt", "desc")
|
||||
),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,17 +4,23 @@ import { zql } from "../schema/index";
|
|||
import { canReadSpace, constrainToAllowedSpaces, denySpace } from "./authz";
|
||||
|
||||
export const documentQueries = {
|
||||
bySpace: defineQuery(z.object({ searchSpaceId: z.number() }), ({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.documents.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}),
|
||||
bySpace: defineQuery(
|
||||
z.object({ searchSpaceId: z.number() }),
|
||||
({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.documents.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}
|
||||
),
|
||||
};
|
||||
|
||||
export const connectorQueries = {
|
||||
bySpace: defineQuery(z.object({ searchSpaceId: z.number() }), ({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.search_source_connectors.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}),
|
||||
bySpace: defineQuery(
|
||||
z.object({ searchSpaceId: z.number() }),
|
||||
({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.search_source_connectors.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}
|
||||
),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import { zql } from "../schema/index";
|
|||
import { canReadSpace, constrainToAllowedSpaces, denySpace } from "./authz";
|
||||
|
||||
export const folderQueries = {
|
||||
bySpace: defineQuery(z.object({ searchSpaceId: z.number() }), ({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.folders.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("position", "asc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("position", "asc");
|
||||
}),
|
||||
bySpace: defineQuery(
|
||||
z.object({ searchSpaceId: z.number() }),
|
||||
({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.folders.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("position", "asc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("position", "asc");
|
||||
}
|
||||
),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@ import { zql } from "../schema/index";
|
|||
import { canReadSpace, constrainToAllowedSpaces, denySpace } from "./authz";
|
||||
|
||||
export const podcastQueries = {
|
||||
bySpace: defineQuery(z.object({ searchSpaceId: z.number() }), ({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.podcasts.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}),
|
||||
bySpace: defineQuery(
|
||||
z.object({ searchSpaceId: z.number() }),
|
||||
({ args: { searchSpaceId }, ctx }) => {
|
||||
const query = zql.podcasts.where("searchSpaceId", searchSpaceId);
|
||||
if (!canReadSpace(ctx, searchSpaceId)) return denySpace(query).orderBy("createdAt", "desc");
|
||||
return constrainToAllowedSpaces(query, ctx).orderBy("createdAt", "desc");
|
||||
}
|
||||
),
|
||||
byId: defineQuery(z.object({ podcastId: z.number() }), ({ args: { podcastId }, ctx }) =>
|
||||
constrainToAllowedSpaces(zql.podcasts.where("id", podcastId), ctx).one()
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue