Skip to content

Commit

Permalink
fixed behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
hagen-danswer committed Nov 26, 2024
1 parent d550776 commit 9b2d04a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/ee/danswer/access/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _get_access_for_documents(
for document_id, group_names in fetch_user_groups_for_documents(
db_session=db_session,
document_ids=document_ids,
exclude_sync_access=True,
)
}
documents = get_documents_by_ids(
Expand Down
15 changes: 14 additions & 1 deletion backend/ee/danswer/db/user_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sqlalchemy.orm import Session

from danswer.db.connector_credential_pair import get_connector_credential_pair_from_id
from danswer.db.enums import AccessType
from danswer.db.enums import ConnectorCredentialPairStatus
from danswer.db.models import ConnectorCredentialPair
from danswer.db.models import Credential__UserGroup
Expand Down Expand Up @@ -297,7 +298,13 @@ def fetch_documents_for_user_group_paginated(
def fetch_user_groups_for_documents(
db_session: Session,
document_ids: list[str],
exclude_sync_access: bool = False,
) -> Sequence[tuple[str, list[str]]]:
"""
Fetches all user groups that have access to the given documents.
can use exclude_sync_access to exclude groups for sync access
"""
stmt = (
select(Document.id, func.array_agg(UserGroup.name))
.join(
Expand All @@ -308,7 +315,13 @@ def fetch_user_groups_for_documents(
ConnectorCredentialPair,
ConnectorCredentialPair.id == UserGroup__ConnectorCredentialPair.cc_pair_id,
)
.join(
)

if exclude_sync_access:
stmt = stmt.where(ConnectorCredentialPair.access_type != AccessType.SYNC)

stmt = (
stmt.join(
DocumentByConnectorCredentialPair,
and_(
DocumentByConnectorCredentialPair.connector_id
Expand Down

0 comments on commit 9b2d04a

Please sign in to comment.