Skip to content

Commit

Permalink
feature: assign data to the other relationship tables; fix/polished g…
Browse files Browse the repository at this point in the history
…et endpoints
  • Loading branch information
Amboyandrey authored and SchadenKai committed Sep 24, 2024
1 parent 775ee30 commit b3fd1b9
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 24 deletions.
15 changes: 15 additions & 0 deletions backend/ee/enmedd/db/teamspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from enmedd.db.models import TokenRateLimit__Teamspace
from enmedd.db.models import User
from enmedd.db.models import User__Teamspace
from enmedd.db.models import Workspace__Teamspace
from enmedd.server.documents.models import ConnectorCredentialPairIdentifier


Expand Down Expand Up @@ -206,6 +207,17 @@ def _add_teamspace__assistant_relationships__no_commit(
return relationships


def _add_workspace__teamspace_relationship(
db_session: Session, workspace_id: int, teamspace_id: int
) -> Workspace__Teamspace:
relationship = Workspace__Teamspace(
workspace_id=workspace_id,
teamspace_id=teamspace_id,
)
db_session.add(relationship)
return relationship


def insert_teamspace(
db_session: Session, teamspace: TeamspaceCreate, creator_id: UUID
) -> Teamspace:
Expand Down Expand Up @@ -234,6 +246,9 @@ def insert_teamspace(
teamspace_id=db_teamspace.id,
cc_pair_ids=teamspace.cc_pair_ids,
)
_add_workspace__teamspace_relationship(
db_session, teamspace.workspace_id, db_teamspace.id
)

db_session.commit()
return db_teamspace
Expand Down
16 changes: 16 additions & 0 deletions backend/ee/enmedd/server/teamspace/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from enmedd.server.features.document_set.models import DocumentSet
from enmedd.server.manage.models import UserInfo
from enmedd.server.manage.models import UserPreferences
from enmedd.server.models import MinimalTeamspaceSnapshot
from enmedd.server.models import MinimalWorkspaceSnapshot
from enmedd.server.query_and_chat.models import ChatSessionDetails

Expand Down Expand Up @@ -63,6 +64,20 @@ def from_model(cls, teamspace_model: TeamspaceModel) -> "Teamspace":
credential=CredentialSnapshot.from_credential_db_model(
cc_pair_relationship.cc_pair.credential
),
groups=[
MinimalTeamspaceSnapshot(
id=group.id,
name=group.name,
workspace=[
MinimalWorkspaceSnapshot(
id=workspace.id,
workspace_name=workspace.workspace_name,
)
for workspace in group.workspace
],
)
for group in cc_pair_relationship.cc_pair.groups
],
)
for cc_pair_relationship in teamspace_model.cc_pair_relationships
if cc_pair_relationship.is_current
Expand Down Expand Up @@ -104,6 +119,7 @@ class TeamspaceCreate(BaseModel):
cc_pair_ids: list[int]
document_set_ids: Optional[List[int]] = []
assistant_ids: Optional[List[int]] = []
workspace_id: Optional[int] = 0


class TeamspaceUpdate(BaseModel):
Expand Down
17 changes: 17 additions & 0 deletions backend/enmedd/server/documents/cc_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from enmedd.server.documents.models import CCPairFullInfo
from enmedd.server.documents.models import ConnectorCredentialPairIdentifier
from enmedd.server.documents.models import ConnectorCredentialPairMetadata
from enmedd.server.models import MinimalTeamspaceSnapshot
from enmedd.server.models import MinimalWorkspaceSnapshot
from enmedd.server.models import StatusResponse

router = APIRouter(prefix="/manage")
Expand Down Expand Up @@ -64,11 +66,26 @@ def get_cc_pair_full_info(
db_session=db_session,
)

groups = [
MinimalTeamspaceSnapshot(
id=group.id,
name=group.name,
workspace=[
MinimalWorkspaceSnapshot(
id=workspace.id, workspace_name=workspace.workspace_name
)
for workspace in group.workspace
],
)
for group in cc_pair.groups
]

return CCPairFullInfo.from_models(
cc_pair_model=cc_pair,
index_attempt_models=list(index_attempts),
latest_deletion_attempt=latest_deletion_attempt,
num_docs_indexed=documents_indexed,
groups=groups,
)


Expand Down
7 changes: 5 additions & 2 deletions backend/enmedd/server/documents/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Any
from typing import Optional
from uuid import UUID

from pydantic import BaseModel
Expand Down Expand Up @@ -132,7 +133,7 @@ class CCPairFullInfo(BaseModel):
credential: CredentialSnapshot
index_attempts: list[IndexAttemptSnapshot]
latest_deletion_attempt: DeletionAttemptSnapshot | None
groups: list[MinimalTeamspaceSnapshot] | None
groups: list[MinimalTeamspaceSnapshot] = []

@classmethod
def from_models(
Expand All @@ -141,6 +142,7 @@ def from_models(
index_attempt_models: list[IndexAttempt],
latest_deletion_attempt: DeletionAttemptSnapshot | None,
num_docs_indexed: int, # not ideal, but this must be computed separately
groups: list[MinimalTeamspaceSnapshot] = [],
) -> "CCPairFullInfo":
return cls(
id=cc_pair_model.id,
Expand All @@ -157,6 +159,7 @@ def from_models(
for index_attempt_model in index_attempt_models
],
latest_deletion_attempt=latest_deletion_attempt,
groups=groups,
)


Expand Down Expand Up @@ -193,7 +196,7 @@ class ConnectorCredentialPairDescriptor(BaseModel):
name: str | None
connector: ConnectorSnapshot
credential: CredentialSnapshot
groups: list[MinimalTeamspaceSnapshot] | None
groups: Optional[list[MinimalTeamspaceSnapshot]] = []


class RunConnectorRequest(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions backend/enmedd/server/feature_flags/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
class FeatureFlags(BaseModel):
"""Features Control"""

profile_page: bool = True
multi_teamspace: bool = True
profile_page: bool = False
multi_teamspace: bool = False
multi_workspace: bool = False
query_history: bool = False
whitelabelling: bool = True
whitelabelling: bool = False
share_chat: bool = False
explore_assistants: bool = False

Expand Down
16 changes: 15 additions & 1 deletion backend/enmedd/server/features/document_set/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from enmedd.server.features.document_set.models import DocumentSet
from enmedd.server.features.document_set.models import DocumentSetCreationRequest
from enmedd.server.features.document_set.models import DocumentSetUpdateRequest
from enmedd.server.models import MinimalTeamspaceSnapshot
from enmedd.server.models import MinimalWorkspaceSnapshot


router = APIRouter(prefix="/manage")
Expand Down Expand Up @@ -116,7 +118,19 @@ def list_document_sets(
is_up_to_date=document_set_db_model.is_up_to_date,
is_public=document_set_db_model.is_public,
users=[user.id for user in document_set_db_model.users],
groups=[group.id for group in document_set_db_model.groups],
groups=[
MinimalTeamspaceSnapshot(
id=group.id,
name=group.name,
workspace=[
MinimalWorkspaceSnapshot(
id=workspace.id, workspace_name=workspace.workspace_name
)
for workspace in group.workspace
],
)
for group in document_set_db_model.groups
],
)
for document_set_db_model, cc_pairs in document_set_info
]
Expand Down
17 changes: 16 additions & 1 deletion backend/enmedd/server/features/document_set/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Optional
from uuid import UUID

from pydantic import BaseModel
Expand Down Expand Up @@ -52,7 +53,7 @@ class DocumentSet(BaseModel):
is_public: bool
# For Private Document Sets, who should be able to access these
users: list[UUID]
groups: list[MinimalTeamspaceSnapshot]
groups: Optional[list[MinimalTeamspaceSnapshot]]

@classmethod
def from_model(cls, document_set_model: DocumentSetDBModel) -> "DocumentSet":
Expand All @@ -76,6 +77,20 @@ def from_model(cls, document_set_model: DocumentSetDBModel) -> "DocumentSet":
credential=CredentialSnapshot.from_credential_db_model(
cc_pair.credential
),
groups=[
MinimalTeamspaceSnapshot(
id=group.id,
name=group.name,
workspace=[
MinimalWorkspaceSnapshot(
id=workspace.id,
workspace_name=workspace.workspace_name,
)
for workspace in group.workspace
],
)
for group in cc_pair.groups
],
)
for cc_pair in document_set_model.connector_credential_pairs
],
Expand Down
24 changes: 9 additions & 15 deletions backend/enmedd/server/manage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from enmedd.indexing.models import EmbeddingModelDetail
from enmedd.server.models import FullUserSnapshot
from enmedd.server.models import InvitedUserSnapshot
from enmedd.server.models import MinimalTeamspaceSnapshot
from enmedd.server.models import TeamspaceResponse
from enmedd.server.models import WorkspaceResponse

if TYPE_CHECKING:
Expand Down Expand Up @@ -45,7 +45,7 @@ class UserInfo(BaseModel):
vat: Optional[str]
preferences: UserPreferences
workspace: Optional[list[WorkspaceResponse]]
groups: Optional[list[MinimalTeamspaceSnapshot]]
groups: Optional[list[TeamspaceResponse]]

@classmethod
def from_model(cls, user: "UserModel") -> "UserInfo":
Expand Down Expand Up @@ -76,19 +76,13 @@ def from_model(cls, user: "UserModel") -> "UserInfo":
for workspace in user.workspace
],
# TODO fix /me error when new teamspace is created when this is uncommented
# groups=[
# MinimalTeamspaceSnapshot(
# id=group.id,
# name=group.name,
# workspace=[
# MinimalWorkspaceSnapshot(
# id=workspace.id, workspace_name=workspace.workspace_name
# )
# for workspace in group.workspace
# ],
# )
# for group in user.groups
# ],
groups=[
TeamspaceResponse(
id=group.id,
name=group.name,
)
for group in user.groups
],
)


Expand Down
10 changes: 8 additions & 2 deletions backend/enmedd/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ class MinimalWorkspaceSnapshot(BaseModel):

class MinimalTeamspaceSnapshot(BaseModel):
id: int
name: str
workspace: list[MinimalWorkspaceSnapshot]
name: str | None = None
workspace: Optional[list[MinimalWorkspaceSnapshot]] = []


# TODO add aditional teamspace info to include in the response
class TeamspaceResponse(BaseModel):
id: int
name: str | None = None


class WorkspaceResponse(BaseModel):
Expand Down

0 comments on commit b3fd1b9

Please sign in to comment.