From d580c3206d89888513e67fc9e5fb6b38380968fd Mon Sep 17 00:00:00 2001 From: MiLla <18826902282@163.com> Date: Thu, 21 Nov 2024 10:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=B0=91=E9=87=8F?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=EF=BC=8C=E5=8E=BB=E9=99=A4=E4=BA=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E7=9A=84=E4=BB=A3=E7=A0=81=E4=B8=8E=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E6=B3=A8=E9=87=8A=E3=80=82=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BC=A0=E5=85=A5estimator=E8=80=8C=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=8E=A5=E5=8F=97estimators=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=97=B6owner=5Fid=E6=81=92=E4=B8=BA1?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/manage_project.py | 15 ++++++--------- api/manage_tanant.py | 1 - 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/api/manage_project.py b/api/manage_project.py index 4bb19e4..a102747 100644 --- a/api/manage_project.py +++ b/api/manage_project.py @@ -63,8 +63,8 @@ async def create_project(data: dict, session: SessionDep, current_user: User = D requirement = data["requirement"] start_time_str = data["start_time"] deadline_str = data["deadline"] - estimators = data["estimators"] - auditors = data["auditors"] + estimators = data["estimator"] + auditors = data["auditor"] # 验证是否缺少必要参数 if not name or not requirement or not start_time_str or not deadline_str: @@ -76,6 +76,9 @@ async def create_project(data: dict, session: SessionDep, current_user: User = D if start_time > deadline: raise HTTPException(status_code=400, detail="Start time must be before deadline") + # 验证是否有传入评估/审核员 + if not estimators or not auditors: + raise HTTPException(status_code=400, detail="Need more estimators or auditors") # 验证评估审核员是否存在 query_estimators = select(User).where(User.username.in_(estimators)) users_estimators = session.exec(query_estimators).all() @@ -106,7 +109,6 @@ async def create_project(data: dict, session: SessionDep, current_user: User = D else: # 新增项目 exist_project = session.exec(select(Project).where(Project.name == name)).first() - print(exist_project) # 测试用 if exist_project: raise HTTPException(status_code=404, detail="Project already exists") @@ -115,14 +117,13 @@ async def create_project(data: dict, session: SessionDep, current_user: User = D requirement=requirement, start_time=start_time, deadline=deadline, - owner_id=1 # 假设owner_id是1,之后应该是通过token获取owner_id吧 + owner_id=current_user.tenant_id, ) session.add(project) # 处理项目和用户的关联 # 先清除现有的关联 # 生成删除语句并执行 - print(project_id) # 测试用 stmt = delete(ProjectUserLink).where(ProjectUserLink.project_id == project.id) session.execute(stmt) session.commit() # 提交事务 @@ -157,10 +158,6 @@ async def delete_project(data: dict, session: SessionDep, current_user: User = D project_name = data.get("name") - # 权限检查:只有管理员才可以删除项目 - # if current_user.role != 1: - # raise HTTPException(status_code=403, detail="Only admin users can delete projects") - if not project_name: raise HTTPException(status_code=400, detail="Project name is required") diff --git a/api/manage_tanant.py b/api/manage_tanant.py index 1178120..6816733 100644 --- a/api/manage_tanant.py +++ b/api/manage_tanant.py @@ -108,7 +108,6 @@ async def create_or_update_tenant(data: dict, session: SessionDep, current_user: user.password = password session.add(user) session.commit() - print(user) # 测试用 return {"message": "Tenant and User update successfully"}