update schemas suitable for file upload

This commit is contained in:
Saurab-Shrestha 2024-03-18 18:00:29 +05:45
parent f7de7c3b54
commit 2008837110
12 changed files with 77 additions and 21 deletions

View File

@ -0,0 +1,32 @@
"""Update is_enabled to false by default
Revision ID: 14281ff34686
Revises: b7b896502e8e
Create Date: 2024-03-18 16:33:43.133458
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '14281ff34686'
down_revision: Union[str, None] = 'b7b896502e8e'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# op.create_unique_constraint('unique_user_role', 'user_roles', ['user_id', 'role_id', 'company_id'])
# ### end Alembic commands ###
pass
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
# op.drop_constraint('unique_user_role', 'user_roles', type_='unique')
pass
# ### end Alembic commands ###

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"index_store/data": {"3c748b5d-8c91-4395-9438-cb3305f308f7": {"__type__": "vector_store", "__data__": "{\"index_id\": \"3c748b5d-8c91-4395-9438-cb3305f308f7\", \"summary\": null, \"nodes_dict\": {\"1b9357d6-4c8e-40b1-bc5b-d13f4c07db7d\": \"1b9357d6-4c8e-40b1-bc5b-d13f4c07db7d\", \"9a7dd336-5118-472f-b99d-c4c0fa26c21c\": \"9a7dd336-5118-472f-b99d-c4c0fa26c21c\", \"8e356062-c915-43f4-8410-08a1b8c52ee3\": \"8e356062-c915-43f4-8410-08a1b8c52ee3\", \"719212ab-2bff-4581-b60d-e36578236552\": \"719212ab-2bff-4581-b60d-e36578236552\", \"759232c4-9bd4-48ed-a2ad-f970920ceeec\": \"759232c4-9bd4-48ed-a2ad-f970920ceeec\", \"67cb5d79-a63d-4b93-a85f-9f897a4ff177\": \"67cb5d79-a63d-4b93-a85f-9f897a4ff177\", \"bf21b013-39f4-4eba-afc8-a33d85670371\": \"bf21b013-39f4-4eba-afc8-a33d85670371\", \"968920d7-bd82-4952-95a6-68a06af2bda0\": \"968920d7-bd82-4952-95a6-68a06af2bda0\", \"73bcd66c-2e87-4ade-be00-4d5267a0e495\": \"73bcd66c-2e87-4ade-be00-4d5267a0e495\", \"9d9af823-92b9-4c61-89b6-9c5c1109e8b0\": \"9d9af823-92b9-4c61-89b6-9c5c1109e8b0\", \"c0f29056-12b9-452a-ba99-b205d18c30d5\": \"c0f29056-12b9-452a-ba99-b205d18c30d5\", \"243b2cae-0971-452c-aa04-1d071f92fa18\": \"243b2cae-0971-452c-aa04-1d071f92fa18\", \"7e60c684-f896-4dea-9bd7-7d27c5f299a8\": \"7e60c684-f896-4dea-9bd7-7d27c5f299a8\", \"95c10e98-6535-4758-ac9c-cdce1ed37540\": \"95c10e98-6535-4758-ac9c-cdce1ed37540\", \"13b8d581-8998-407a-86e8-4f1a70456028\": \"13b8d581-8998-407a-86e8-4f1a70456028\", \"a35cb220-4533-42b3-a062-56ea0cf37bc0\": \"a35cb220-4533-42b3-a062-56ea0cf37bc0\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}
{"index_store/data": {"3c748b5d-8c91-4395-9438-cb3305f308f7": {"__type__": "vector_store", "__data__": "{\"index_id\": \"3c748b5d-8c91-4395-9438-cb3305f308f7\", \"summary\": null, \"nodes_dict\": {\"13b8d581-8998-407a-86e8-4f1a70456028\": \"13b8d581-8998-407a-86e8-4f1a70456028\", \"a35cb220-4533-42b3-a062-56ea0cf37bc0\": \"a35cb220-4533-42b3-a062-56ea0cf37bc0\"}, \"doc_id_dict\": {}, \"embeddings_dict\": {}}"}}}

View File

@ -70,7 +70,7 @@ async def chunks_retrieval(
action='Chat',
details={
"query": body.text,
'user': current_user.fullname,
'user': current_user.username,
},
user_id=current_user.id
)

View File

@ -162,7 +162,7 @@ async def prompt_completion(
action='Chat',
details={
"query": body.prompt,
'user': current_user.fullname,
'user': current_user.username,
},
user_id=current_user.id
)

View File

@ -193,6 +193,7 @@ async def create_documents(
`Document Department Association` table with the departments ids for the documents.
"""
department_ids = departments.departments_ids
print("Department ids: ", department_ids)
file_ingested = crud.documents.get_by_filename(
db, file_name=file_name)
if file_ingested:

View File

@ -249,7 +249,7 @@ def register(
model='User',
action='creation',
details={"status": '409', 'detail': "The user with this email already exists!", },
# user_id=current_user.id
user_id=current_user.id
)
raise HTTPException(
status_code=409,

View File

@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
router = APIRouter(prefix='/documents', tags=['Documents'])
@router.get("", response_model=List[schemas.Document])
@router.get("", response_model=List[schemas.DocumentView])
def list_files(
request: Request,
db: Session = Depends(deps.get_db),
@ -44,11 +44,11 @@ def list_files(
if (role == "SUPER_ADMIN") or (role == "OPERATOR"):
docs = crud.documents.get_multi(db, skip=skip, limit=limit)
else:
docs = crud.documents.get_multi_documents(
docs = crud.documents.get_documents_by_departments(
db, department_id=current_user.department_id, skip=skip, limit=limit)
documents = [
schemas.Document(
schemas.DocumentView(
id=doc.id,
filename=doc.filename,
uploaded_by=get_username(db, doc.uploaded_by),
@ -57,7 +57,9 @@ def list_files(
departments=[
schemas.DepartmentList(id=dep.id, name=dep.name)
for dep in doc.departments
]
],
action_type=doc.action_type,
status=doc.status
)
for doc in docs
]
@ -135,26 +137,28 @@ def update_document(
log_audit: models.Audit = Depends(deps.get_audit_logger),
current_user: models.User = Security(
deps.get_current_user,
scopes=[Role.SUPER_ADMIN["name"], Role.OPERATOR["name"]],
scopes=[Role.ADMIN["name"],
Role.SUPER_ADMIN["name"],
Role.OPERATOR["name"]]
)
):
'''
Function to enable or disable document.
'''
try:
document = crud.documents.get_by_filename(
db, file_name=document_in.filename)
document = crud.documents.get_by_id(
db, id=document_in.id)
if not document:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Document with this filename doesn't exist!",
detail="Document with this id doesn't exist!",
)
docs = crud.documents.update(db=db, db_obj=document, obj_in=document_in)
log_audit(
model='Document',
action='update',
details={
'detail': f'{document_in.filename} status changed to {document_in.is_enabled} from {document.is_enabled}'
'detail': f'{document.filename} status changed to {document_in.is_enabled} from {document.is_enabled}'
},
user_id=current_user.id
)
@ -216,8 +220,6 @@ def update_department(
async def upload_documents(
request: Request,
departments: schemas.DocumentDepartmentList = Depends(),
file: UploadFile = File(...),
log_audit: models.Audit = Depends(deps.get_audit_logger),
db: Session = Depends(deps.get_db),
current_user: models.User = Security(
@ -229,6 +231,7 @@ async def upload_documents(
):
"""Upload the documents."""
try:
file = departments.file
original_filename = file.filename
if original_filename is None:
raise HTTPException(
@ -288,6 +291,7 @@ async def verify_documents(
if checker_in.status == MakerCheckerStatus.APPROVED.value:
checker = schemas.DocumentCheckerUpdate(
action_type=MakerCheckerActionType.UPDATE,
status=MakerCheckerStatus.APPROVED,
is_enabled=checker_in.is_enabled,
verified_at=datetime.now(),
@ -304,8 +308,9 @@ async def verify_documents(
elif checker_in.status == MakerCheckerStatus.REJECTED.value:
checker = schemas.DocumentCheckerUpdate(
action_type=MakerCheckerActionType.DELETE,
status=MakerCheckerStatus.REJECTED,
is_enabled=checker_in.is_enabled,
is_enabled=False,
verified_at=datetime.now(),
verified_by=current_user.id,
)

View File

@ -333,7 +333,7 @@ def admin_update_user(
)
role = crud.role.get_by_name(db, name=user_update.role)
if (role.id == 1) or (role.id == 4) :
if (role.id == 1) or (role.id == 3): # role id for SUPER_ADMIN and OPERATOR
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Cannot create SUPER ADMIN!",

View File

@ -4,6 +4,6 @@ from .user import User, UserCreate, UserInDB, UserUpdate, UserBaseSchema, Profil
from .user_role import UserRole, UserRoleCreate, UserRoleInDB, UserRoleUpdate
from .subscription import Subscription, SubscriptionBase, SubscriptionCreate, SubscriptionUpdate
from .company import Company, CompanyBase, CompanyCreate, CompanyUpdate
from .documents import Document, DocumentCreate, DocumentsBase, DocumentUpdate, DocumentList, DepartmentList, DocumentEnable, DocumentDepartmentUpdate, DocumentCheckerUpdate, DocumentMakerCreate, DocumentDepartmentList
from .documents import Document, DocumentCreate, DocumentsBase, DocumentUpdate, DocumentList, DepartmentList, DocumentEnable, DocumentDepartmentUpdate, DocumentCheckerUpdate, DocumentMakerCreate, DocumentDepartmentList, DocumentView
from .department import Department, DepartmentCreate, DepartmentUpdate, DepartmentAdminCreate, DepartmentDelete
from .audit import AuditBase, AuditCreate, AuditUpdate, Audit, GetAudit

View File

@ -18,7 +18,8 @@ class DocumentUpdate(BaseModel):
status: str
is_enabled: bool
class DocumentEnable(DocumentsBase):
class DocumentEnable(BaseModel):
id: int
is_enabled: bool
class DocumentDepartmentUpdate(DocumentsBase):
@ -52,6 +53,7 @@ class DocumentMakerCreate(DocumentMakerChecker):
class DocumentCheckerUpdate(BaseModel):
action_type: str
status: str
is_enabled: bool
verified_at: datetime
@ -60,4 +62,20 @@ class DocumentCheckerUpdate(BaseModel):
class DocumentDepartmentList(BaseModel):
departments_ids: str = Form(...)
doc_type_id: int
doc_type_id: int = Form(...)
file: UploadFile = File(...)
class DocumentView(BaseModel):
id: int
is_enabled: bool
filename: str
uploaded_by: str
uploaded_at: datetime
departments: List[DepartmentList] = []
action_type: str
status: str
class Config:
orm_mode = True