-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(knowledge): treat Google Workspace users without Gmail or Calendar as out of scope, not listing failures #8168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
47d94a5
fix(knowledge): treat Google Workspace users without Gmail or Calenda…
waleedlatif1 f4ec7f3
fix(knowledge): keep a Google Workspace user's visible documents unti…
waleedlatif1 4c785f0
fix(knowledge): read a user's visible documents from the ACL index an…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
apps/sim/lib/knowledge/__integration__/user-document-visibility.integration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /** Real PostgreSQL coverage for the probe that keeps a user's visible documents from being skipped. */ | ||
| import { db } from '@sim/db' | ||
| import { document, knowledgeConnector, organization, user, workspace } from '@sim/db/schema' | ||
| import { generateId } from '@sim/utils/id' | ||
| import { eq, inArray } from 'drizzle-orm' | ||
| import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest' | ||
| import { seedKnowledgeAclFixture } from '@/lib/knowledge/__integration__/seed-source-access-fixture' | ||
| import { hasVisibleUserDocuments } from '@/lib/knowledge/connectors/user-document-visibility' | ||
|
|
||
| const DAY_MS = 24 * 60 * 60 * 1000 | ||
|
|
||
| describe('Visible user documents in PostgreSQL', () => { | ||
| let owner: Awaited<ReturnType<typeof seedKnowledgeAclFixture>> | ||
| let otherConnectorId: string | ||
| const email = () => `${owner.aliceId}@fixture.test` | ||
|
|
||
| beforeEach(async () => { | ||
| owner = await seedKnowledgeAclFixture(undefined, { connectorType: 'google_drive' }) | ||
| otherConnectorId = generateId() | ||
| await db.insert(knowledgeConnector).values({ | ||
| id: otherConnectorId, | ||
| knowledgeBaseId: owner.knowledgeBaseId, | ||
| connectorType: 'google_drive', | ||
| sourceConfig: {}, | ||
| accessMode: 'admin', | ||
| status: 'active', | ||
| credentialId: owner.credentialId, | ||
| }) | ||
| }) | ||
| afterEach(async () => { | ||
| await db.delete(workspace).where(eq(workspace.id, owner.workspaceId)) | ||
| await db.delete(organization).where(eq(organization.id, owner.organizationId)) | ||
| await db.delete(user).where(inArray(user.id, [owner.aliceId, owner.bobId])) | ||
| }) | ||
| afterAll(() => db.$client.end()) | ||
|
|
||
| const insert = (overrides: Partial<typeof document.$inferInsert> = {}) => | ||
| db.insert(document).values({ | ||
| id: generateId(), | ||
| knowledgeBaseId: owner.knowledgeBaseId, | ||
| connectorId: owner.connectorId, | ||
| externalId: generateId(), | ||
| filename: 'Event.txt', | ||
| mimeType: 'text/plain', | ||
| fileUrl: '', | ||
| fileSize: 0, | ||
| acl: [`u:${email()}`], | ||
| aclVerifiedAt: new Date(), | ||
| ...overrides, | ||
| }) | ||
|
|
||
| it('finds a live, included document granted to the user with fresh permission evidence', async () => { | ||
| await insert() | ||
| expect(await hasVisibleUserDocuments(owner.connectorId, email())).toBe(true) | ||
| }) | ||
|
|
||
| it('matches a mixed-case, padded directory email to the normalized ACL token', async () => { | ||
| await insert() | ||
| expect(await hasVisibleUserDocuments(owner.connectorId, ` ${email().toUpperCase()} `)).toBe( | ||
| true | ||
| ) | ||
| }) | ||
|
|
||
| it.each([ | ||
| { | ||
| label: 'permission evidence older than the freshness limit', | ||
| overrides: () => ({ aclVerifiedAt: new Date(Date.now() - DAY_MS - 60_000) }), | ||
| }, | ||
| { label: 'no permission evidence', overrides: () => ({ aclVerifiedAt: null }) }, | ||
| { | ||
| label: 'a grant to a different user', | ||
| overrides: () => ({ acl: [`u:${owner.bobId}@fixture.test`] }), | ||
| }, | ||
| { | ||
| label: 'a document in another connector', | ||
| overrides: () => ({ connectorId: otherConnectorId }), | ||
| }, | ||
| { label: 'a user-excluded document', overrides: () => ({ userExcluded: true }) }, | ||
| { label: 'an archived document', overrides: () => ({ archivedAt: new Date() }) }, | ||
| { label: 'a deleted document', overrides: () => ({ deletedAt: new Date() }) }, | ||
| ])('ignores $label', async ({ overrides }) => { | ||
| await insert(overrides()) | ||
| expect(await hasVisibleUserDocuments(owner.connectorId, email())).toBe(false) | ||
| }) | ||
|
|
||
| it('refuses an address that cannot be a user token', async () => { | ||
| await insert() | ||
| expect(await hasVisibleUserDocuments(owner.connectorId, ' ')).toBe(false) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.