mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 21:26:01 +02:00
Combined the get document set endpoints (#2234)
* Combined the get document set endpoints * removed unused function * fixed permissioning for document sets
This commit is contained in:
@@ -468,26 +468,6 @@ def fetch_all_document_sets_for_user(
|
|||||||
return db_session.scalars(stmt).all()
|
return db_session.scalars(stmt).all()
|
||||||
|
|
||||||
|
|
||||||
def fetch_user_document_sets(
|
|
||||||
user_id: UUID | None, db_session: Session
|
|
||||||
) -> list[tuple[DocumentSetDBModel, list[ConnectorCredentialPair]]]:
|
|
||||||
# If Auth is turned off, all document sets become visible
|
|
||||||
# document sets are not permission enforced, only for organizational purposes
|
|
||||||
# the documents themselves are permission enforced
|
|
||||||
if user_id is None:
|
|
||||||
return fetch_document_sets(
|
|
||||||
user_id=user_id, db_session=db_session, include_outdated=True
|
|
||||||
)
|
|
||||||
|
|
||||||
versioned_fetch_doc_sets_fn = fetch_versioned_implementation(
|
|
||||||
"danswer.db.document_set", "fetch_document_sets"
|
|
||||||
)
|
|
||||||
|
|
||||||
return versioned_fetch_doc_sets_fn(
|
|
||||||
user_id=user_id, db_session=db_session, include_outdated=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def fetch_documents_for_document_set_paginated(
|
def fetch_documents_for_document_set_paginated(
|
||||||
document_set_id: int,
|
document_set_id: int,
|
||||||
db_session: Session,
|
db_session: Session,
|
||||||
|
@@ -9,16 +9,12 @@ from danswer.auth.users import current_user
|
|||||||
from danswer.auth.users import validate_curator_request
|
from danswer.auth.users import validate_curator_request
|
||||||
from danswer.db.document_set import check_document_sets_are_public
|
from danswer.db.document_set import check_document_sets_are_public
|
||||||
from danswer.db.document_set import fetch_all_document_sets_for_user
|
from danswer.db.document_set import fetch_all_document_sets_for_user
|
||||||
from danswer.db.document_set import fetch_user_document_sets
|
|
||||||
from danswer.db.document_set import insert_document_set
|
from danswer.db.document_set import insert_document_set
|
||||||
from danswer.db.document_set import mark_document_set_as_to_be_deleted
|
from danswer.db.document_set import mark_document_set_as_to_be_deleted
|
||||||
from danswer.db.document_set import update_document_set
|
from danswer.db.document_set import update_document_set
|
||||||
from danswer.db.engine import get_session
|
from danswer.db.engine import get_session
|
||||||
from danswer.db.models import User
|
from danswer.db.models import User
|
||||||
from danswer.db.models import UserRole
|
from danswer.db.models import UserRole
|
||||||
from danswer.server.documents.models import ConnectorCredentialPairDescriptor
|
|
||||||
from danswer.server.documents.models import ConnectorSnapshot
|
|
||||||
from danswer.server.documents.models import CredentialSnapshot
|
|
||||||
from danswer.server.features.document_set.models import CheckDocSetPublicRequest
|
from danswer.server.features.document_set.models import CheckDocSetPublicRequest
|
||||||
from danswer.server.features.document_set.models import CheckDocSetPublicResponse
|
from danswer.server.features.document_set.models import CheckDocSetPublicResponse
|
||||||
from danswer.server.features.document_set.models import DocumentSet
|
from danswer.server.features.document_set.models import DocumentSet
|
||||||
@@ -88,9 +84,12 @@ def delete_document_set(
|
|||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.get("/admin/document-set")
|
"""Endpoints for non-admins"""
|
||||||
def list_document_sets_admin(
|
|
||||||
user: User | None = Depends(current_curator_or_admin_user),
|
|
||||||
|
@router.get("/document-set")
|
||||||
|
def list_document_sets_for_user(
|
||||||
|
user: User | None = Depends(current_user),
|
||||||
db_session: Session = Depends(get_session),
|
db_session: Session = Depends(get_session),
|
||||||
get_editable: bool = Query(
|
get_editable: bool = Query(
|
||||||
False, description="If true, return editable document sets"
|
False, description="If true, return editable document sets"
|
||||||
@@ -104,45 +103,6 @@ def list_document_sets_admin(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
"""Endpoints for non-admins"""
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/document-set")
|
|
||||||
def list_document_sets(
|
|
||||||
user: User | None = Depends(current_user),
|
|
||||||
db_session: Session = Depends(get_session),
|
|
||||||
) -> list[DocumentSet]:
|
|
||||||
document_set_info = fetch_user_document_sets(
|
|
||||||
user_id=user.id if user else None, db_session=db_session
|
|
||||||
)
|
|
||||||
return [
|
|
||||||
DocumentSet(
|
|
||||||
id=document_set_db_model.id,
|
|
||||||
name=document_set_db_model.name,
|
|
||||||
description=document_set_db_model.description,
|
|
||||||
contains_non_public=any([not cc_pair.is_public for cc_pair in cc_pairs]),
|
|
||||||
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 cc_pairs
|
|
||||||
],
|
|
||||||
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],
|
|
||||||
)
|
|
||||||
for document_set_db_model, cc_pairs in document_set_info
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/document-set-public")
|
@router.get("/document-set-public")
|
||||||
def document_set_public(
|
def document_set_public(
|
||||||
check_public_request: CheckDocSetPublicRequest,
|
check_public_request: CheckDocSetPublicRequest,
|
||||||
|
@@ -21,7 +21,7 @@ class DocumentSetClient:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_document_sets() -> list[DocumentSet]:
|
def fetch_document_sets() -> list[DocumentSet]:
|
||||||
response = requests.get(f"{API_SERVER_URL}/manage/admin/document-set")
|
response = requests.get(f"{API_SERVER_URL}/manage/document-set")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
document_sets = [
|
document_sets = [
|
||||||
|
@@ -2,9 +2,9 @@ import { errorHandlingFetcher } from "@/lib/fetcher";
|
|||||||
import { DocumentSet } from "@/lib/types";
|
import { DocumentSet } from "@/lib/types";
|
||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
|
|
||||||
const DOCUMENT_SETS_URL = "/api/manage/admin/document-set";
|
const DOCUMENT_SETS_URL = "/api/manage/document-set";
|
||||||
const GET_EDITABLE_DOCUMENT_SETS_URL =
|
const GET_EDITABLE_DOCUMENT_SETS_URL =
|
||||||
"/api/manage/admin/document-set?get_editable=true";
|
"/api/manage/document-set?get_editable=true";
|
||||||
|
|
||||||
export function refreshDocumentSets() {
|
export function refreshDocumentSets() {
|
||||||
mutate(DOCUMENT_SETS_URL);
|
mutate(DOCUMENT_SETS_URL);
|
||||||
|
@@ -5,7 +5,6 @@ import { fetchSS } from "../utilsSS";
|
|||||||
import { FullLLMProvider } from "@/app/admin/configuration/llm/interfaces";
|
import { FullLLMProvider } from "@/app/admin/configuration/llm/interfaces";
|
||||||
import { ToolSnapshot } from "../tools/interfaces";
|
import { ToolSnapshot } from "../tools/interfaces";
|
||||||
import { fetchToolsSS } from "../tools/fetchTools";
|
import { fetchToolsSS } from "../tools/fetchTools";
|
||||||
import { IconManifestType } from "react-icons/lib";
|
|
||||||
import {
|
import {
|
||||||
OpenAIIcon,
|
OpenAIIcon,
|
||||||
AnthropicIcon,
|
AnthropicIcon,
|
||||||
|
Reference in New Issue
Block a user