users.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import time
  2. from typing import List, Optional
  3. from fastapi import APIRouter
  4. from fastapi import Depends
  5. from sqlalchemy.orm import Session
  6. from app.utils.utils import *
  7. from utils.sx_time import sxtimeit
  8. from utils.sx_web import web_try
  9. from app.common.decorators import verify_user, verify_all, verify_super_admin, verify_admin
  10. from app import crud, get_db, get_page, schemas
  11. router = APIRouter(
  12. prefix="/jpt/users",
  13. tags=["users-用户管理"],
  14. )
  15. @router.post("/register")
  16. @web_try()
  17. @sxtimeit
  18. def create_user(item: schemas.UsersCreate, db: Session = Depends(get_db)):
  19. return crud.create_users(db,item)
  20. @router.post("/login")
  21. @web_try()
  22. @sxtimeit
  23. def login(item: schemas.LoginBase, db: Session = Depends(get_db)):
  24. return crud.login(db,item)
  25. @router.get("/project_users", dependencies=[Depends(verify_admin)])
  26. @web_try()
  27. @sxtimeit
  28. def get_users_by_project(project_id: int, db: Session = Depends(get_db)):
  29. return crud.get_users_by_project(db,project_id)
  30. @router.get("/retrieve_users", dependencies=[Depends(verify_admin)])
  31. @web_try()
  32. @sxtimeit
  33. def retrieve_users_by_project(project_id: int, db: Session = Depends(get_db)):
  34. return crud.retrieve_users_by_project(db,project_id)
  35. @router.post("/add_project_users", dependencies=[Depends(verify_admin)])
  36. @web_try()
  37. @sxtimeit
  38. def add_users_to_project(item: schemas.AddUsersToProject, db: Session = Depends(get_db)):
  39. crud.add_users_to_project(db,item.user_ids,item.project_id)
  40. return 'success'
  41. @router.delete("/remove_project_users", dependencies=[Depends(verify_admin)])
  42. @web_try()
  43. @sxtimeit
  44. def remove_project_users(item: schemas.RemoveUsersToProject, db: Session = Depends(get_db)):
  45. crud.remove_project_users(db,item.user_id,item.project_id)
  46. return 'success'
  47. @router.put("/set_user_to_admin", dependencies=[Depends(verify_super_admin)])
  48. @web_try()
  49. @sxtimeit
  50. def set_user_to_admin(item: schemas.SetUserToAdmin, db: Session = Depends(get_db)):
  51. crud.set_user_to_admin(db,item.user_id,item.project_id)
  52. @router.put("/remove_user_to_admin", dependencies=[Depends(verify_super_admin)])
  53. @web_try()
  54. @sxtimeit
  55. def remove_user_to_admin(item: schemas.SetUserToAdmin, db: Session = Depends(get_db)):
  56. crud.remove_user_to_admin(db,item.user_id,item.project_id)