Skip to content

Commit e7c143b

Browse files
committed
ack PR comments
1 parent 6fcc820 commit e7c143b

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

apps/sim/app/api/knowledge/[id]/connectors/[connectorId]/documents/route.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ export async function GET(request: NextRequest, { params }: RouteParams) {
8484
processingStatus: document.processingStatus,
8585
})
8686
.from(document)
87-
.where(and(eq(document.connectorId, connectorId), eq(document.userExcluded, true)))
87+
.where(
88+
and(
89+
eq(document.connectorId, connectorId),
90+
eq(document.userExcluded, true),
91+
isNull(document.deletedAt)
92+
)
93+
)
8894
.orderBy(document.filename)
8995
: []
9096

@@ -130,6 +136,22 @@ export async function PATCH(request: NextRequest, { params }: RouteParams) {
130136
return NextResponse.json({ error: status === 404 ? 'Not found' : 'Unauthorized' }, { status })
131137
}
132138

139+
const connectorRows = await db
140+
.select({ id: knowledgeConnector.id })
141+
.from(knowledgeConnector)
142+
.where(
143+
and(
144+
eq(knowledgeConnector.id, connectorId),
145+
eq(knowledgeConnector.knowledgeBaseId, knowledgeBaseId),
146+
isNull(knowledgeConnector.deletedAt)
147+
)
148+
)
149+
.limit(1)
150+
151+
if (connectorRows.length === 0) {
152+
return NextResponse.json({ error: 'Connector not found' }, { status: 404 })
153+
}
154+
133155
const body = await request.json()
134156
const parsed = PatchSchema.safeParse(body)
135157
if (!parsed.success) {

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/add-connector-modal/add-connector-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function AddConnectorModal({ open, onOpenChange, knowledgeBaseId }: AddCo
6666
)
6767

6868
const { data: credentials = [], isLoading: credentialsLoading } = useOAuthCredentials(
69-
connectorConfig?.oauth.provider,
69+
connectorProviderId ?? undefined,
7070
Boolean(connectorConfig)
7171
)
7272

apps/sim/connectors/confluence/confluence.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { getConfluenceCloudId } from '@/tools/confluence/utils'
66

77
const logger = createLogger('ConfluenceConnector')
88

9+
/**
10+
* Escapes a value for use inside CQL double-quoted strings.
11+
*/
12+
function escapeCql(value: string): string {
13+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
14+
}
15+
916
/**
1017
* Strips HTML tags from content and decodes HTML entities.
1118
*/
@@ -515,7 +522,7 @@ async function listDocumentsViaCql(
515522
.filter(Boolean)
516523

517524
// Build CQL query
518-
let cql = `space="${spaceKey}"`
525+
let cql = `space="${escapeCql(spaceKey)}"`
519526

520527
if (contentType === 'blogpost') {
521528
cql += ' AND type="blogpost"'
@@ -525,9 +532,9 @@ async function listDocumentsViaCql(
525532
// contentType === 'all' — no type filter
526533

527534
if (labels.length === 1) {
528-
cql += ` AND label="${labels[0]}"`
535+
cql += ` AND label="${escapeCql(labels[0])}"`
529536
} else if (labels.length > 1) {
530-
const labelList = labels.map((l) => `"${l}"`).join(',')
537+
const labelList = labels.map((l) => `"${escapeCql(l)}"`).join(',')
531538
cql += ` AND label in (${labelList})`
532539
}
533540

apps/sim/connectors/jira/jira.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ const logger = createLogger('JiraConnector')
88

99
const PAGE_SIZE = 50
1010

11+
/**
12+
* Escapes a value for use inside JQL double-quoted strings.
13+
*/
14+
function escapeJql(value: string): string {
15+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
16+
}
17+
1118
/**
1219
* Computes a SHA-256 hash of the given content.
1320
*/
@@ -140,9 +147,9 @@ export const jiraConnector: ConnectorConfig = {
140147

141148
const cloudId = await getJiraCloudId(domain, accessToken)
142149

143-
let jql = `project = "${projectKey}" ORDER BY updated DESC`
150+
let jql = `project = "${escapeJql(projectKey)}" ORDER BY updated DESC`
144151
if (jqlFilter.trim()) {
145-
jql = `project = "${projectKey}" AND (${jqlFilter.trim()}) ORDER BY updated DESC`
152+
jql = `project = "${escapeJql(projectKey)}" AND (${jqlFilter.trim()}) ORDER BY updated DESC`
146153
}
147154

148155
const startAt = cursor ? Number(cursor) : 0
@@ -256,7 +263,7 @@ export const jiraConnector: ConnectorConfig = {
256263

257264
// Verify the project exists by running a minimal search
258265
const params = new URLSearchParams()
259-
params.append('jql', `project = "${projectKey}"`)
266+
params.append('jql', `project = "${escapeJql(projectKey)}"`)
260267
params.append('maxResults', '0')
261268

262269
const url = `https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/search?${params.toString()}`

0 commit comments

Comments
 (0)