Files
onyx/backend/danswer/server/features/document_set/models.py
T
hagen-danswer 2274cab554 Added permission syncing (#2340)
* Added permission syncing on the backend

* Rewored to work with celery

alembic fix

fixed test

* frontend changes

* got groups working

* added comments and fixed public docs

* fixed merge issues

* frontend complete!

* frontend cleanup and mypy fixes

* refactored connector access_type selection

* mypy fixes

* minor refactor and frontend improvements

* get to fetch

* renames and comments

* minor change to var names

* got curator stuff working

* addressed pablo's comments

* refactored user_external_group to reference users table

* implemented polling

* small refactor

* fixed a whoopsies on the frontend

* added scripts to seed dummy docs and test query times

* fixed frontend build issue

* alembic fix

* handled is_public overlap

* yuhong feedback

* added more checks for sync

* black

* mypy

* fixed circular import

* todos

* alembic fix

* alembic
2024-09-19 22:07:36 +00:00

79 lines
2.5 KiB
Python

from uuid import UUID
from pydantic import BaseModel
from pydantic import Field
from danswer.db.models import DocumentSet as DocumentSetDBModel
from danswer.server.documents.models import ConnectorCredentialPairDescriptor
from danswer.server.documents.models import ConnectorSnapshot
from danswer.server.documents.models import CredentialSnapshot
class DocumentSetCreationRequest(BaseModel):
name: str
description: str
cc_pair_ids: list[int]
is_public: bool
# For Private Document Sets, who should be able to access these
users: list[UUID] = Field(default_factory=list)
groups: list[int] = Field(default_factory=list)
class DocumentSetUpdateRequest(BaseModel):
id: int
description: str
cc_pair_ids: list[int]
is_public: bool
# For Private Document Sets, who should be able to access these
users: list[UUID]
groups: list[int]
class CheckDocSetPublicRequest(BaseModel):
"""Note that this does not mean that the Document Set itself is to be viewable by everyone
Rather, this refers to the CC-Pairs in the Document Set, and if every CC-Pair is public
"""
document_set_ids: list[int]
class CheckDocSetPublicResponse(BaseModel):
is_public: bool
class DocumentSet(BaseModel):
id: int
name: str
description: str
cc_pair_descriptors: list[ConnectorCredentialPairDescriptor]
is_up_to_date: bool
is_public: bool
# For Private Document Sets, who should be able to access these
users: list[UUID]
groups: list[int]
@classmethod
def from_model(cls, document_set_model: DocumentSetDBModel) -> "DocumentSet":
return cls(
id=document_set_model.id,
name=document_set_model.name,
description=document_set_model.description,
cc_pair_descriptors=[
ConnectorCredentialPairDescriptor(
id=cc_pair.id,
name=cc_pair.name,
connector=ConnectorSnapshot.from_connector_db_model(
cc_pair.connector
),
credential=CredentialSnapshot.from_credential_db_model(
cc_pair.credential
),
)
for cc_pair in document_set_model.connector_credential_pairs
],
is_up_to_date=document_set_model.is_up_to_date,
is_public=document_set_model.is_public,
users=[user.id for user in document_set_model.users],
groups=[group.id for group in document_set_model.groups],
)