项目管理_删除项目功能完成,依旧是暂时去除了权限验证以测试代码
This commit is contained in:
parent
a8e9a4920b
commit
0594809a48
@ -27,56 +27,7 @@ async def get_project(response: Response, session: SessionDep):
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
return {"projects": projects}
|
||||
|
||||
|
||||
# 新增和修改项目
|
||||
# @router.post("/api/s1/project")
|
||||
# async def create_project(data:dict, session: SessionDep, current_user: User = Depends(get_current_user)):
|
||||
# if current_user.role != TenantRole:
|
||||
# raise HTTPException(status_code=403, detail="Only tenant users can add or update project")
|
||||
# name = data["name"]
|
||||
# requirement = data["requirement"]
|
||||
# start_time = data["start_time"]
|
||||
# deadline = data["deadline"]
|
||||
# estimators = data["estimator"]
|
||||
# auditors = data["auditor"]
|
||||
#
|
||||
# #验证是否缺少必要参数
|
||||
# if not name or not requirement or not start_time or not deadline or not estimators or not auditors:
|
||||
# raise HTTPException(status_code=400, detail="Need more details")
|
||||
#
|
||||
# #验证开始时间是否早于结束时间
|
||||
# if datetime.fromisoformat(start_time) > datetime.fromisoformat(deadline):
|
||||
# raise HTTPException(status_code=400, detail="Start time must be before deadline")
|
||||
#
|
||||
# #验证评估审核员是否存在
|
||||
# query_estimators = select(User).where(User.username.in_(estimators), User.tenant_id == current_user.tenant_id)
|
||||
# users_estimators = session.exec(query_estimators).all()
|
||||
# query_auditors = select(User).where(User.username.in_(auditors), User.tenant_id == current_user.tenant_id)
|
||||
# users_auditors = session.exec(query_auditors).all()
|
||||
# # 提取出所有查询到的
|
||||
# existing_estimators = {user.username for user in users_estimators}
|
||||
# existing_auditors = {user.username for user in users_auditors}
|
||||
#
|
||||
# # 验证是否所有的username都存在于数据库中
|
||||
# missing_usernames = (set(auditors) | set(estimators)) - existing_estimators - existing_auditors
|
||||
#
|
||||
# if missing_usernames:
|
||||
# raise HTTPException(status_code=404, detail=f"Missing usernames:{missing_usernames}")
|
||||
#
|
||||
# newProject = Project(
|
||||
# name=name,
|
||||
# requirement=requirement,
|
||||
# start_time=start_time,
|
||||
# deadline=deadline,
|
||||
# owner_id = current_user.tenant_id,
|
||||
# )
|
||||
# session.add(newProject)
|
||||
# session.commit()
|
||||
# session.refresh(newProject)
|
||||
#
|
||||
# return {"newProject": newProject,
|
||||
# "refreshProject.id": newProject.id,
|
||||
# }
|
||||
#新增与修改项目
|
||||
@router.post("/api/s1/project")
|
||||
async def create_project(data: dict, session: SessionDep):
|
||||
project_id = data.get("project_id")
|
||||
@ -160,6 +111,35 @@ async def create_project(data: dict, session: SessionDep):
|
||||
session.commit()
|
||||
session.refresh(project)
|
||||
|
||||
return {"newProject": project,
|
||||
"refreshProject.id": project.id,
|
||||
return {"message": "Added or updated successfully",
|
||||
"information": project,
|
||||
}
|
||||
|
||||
#删除项目
|
||||
@router.delete("/api/s1/project")
|
||||
async def delete_project(data : dict, session: SessionDep):
|
||||
project_id = data.get("project_id")
|
||||
# 权限检查:只有管理员才可以删除项目
|
||||
# if current_user.role != 1:
|
||||
# raise HTTPException(status_code=403, detail="Only admin users can delete projects")
|
||||
|
||||
if not project_id:
|
||||
raise HTTPException(status_code=400, detail="Project ID is required")
|
||||
|
||||
# 查找项目
|
||||
project = session.exec(
|
||||
select(Project).where(Project.id == project_id)).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404,
|
||||
detail="Project not found or you do not have permission to delete this project")
|
||||
|
||||
# 删除与项目相关的用户链接
|
||||
# 先清除现有的关联
|
||||
stmt = delete(ProjectUserLink).where(ProjectUserLink.project_id == project_id)
|
||||
session.execute(stmt)
|
||||
|
||||
# 删除项目
|
||||
session.delete(project)
|
||||
session.commit()
|
||||
|
||||
return {"detail": "Project deleted successfully"}
|
||||
Loading…
Reference in New Issue
Block a user