12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import time
- from typing import List, Optional
- from fastapi import APIRouter
- from fastapi import Depends
- from sqlalchemy.orm import Session
- from app.utils.utils import *
- from utils.sx_time import sxtimeit
- from utils.sx_web import web_try
- from app.common.decorators import verify_user, verify_all, verify_super_admin, verify_admin
- from app import crud, get_db, get_page, schemas
- router = APIRouter(
- prefix="/jpt/users",
- tags=["users-用户管理"],
- )
- @router.post("/register")
- @web_try()
- @sxtimeit
- def create_user(item: schemas.UsersCreate, db: Session = Depends(get_db)):
- return crud.create_users(db,item)
- @router.post("/login")
- @web_try()
- @sxtimeit
- def login(item: schemas.LoginBase, db: Session = Depends(get_db)):
- return crud.login(db,item)
- @router.get("/project_users", dependencies=[Depends(verify_admin)])
- @web_try()
- @sxtimeit
- def get_users_by_project(project_id: int, db: Session = Depends(get_db)):
- return crud.get_users_by_project(db,project_id)
- @router.get("/retrieve_users", dependencies=[Depends(verify_admin)])
- @web_try()
- @sxtimeit
- def retrieve_users_by_project(project_id: int, db: Session = Depends(get_db)):
- return crud.retrieve_users_by_project(db,project_id)
- @router.post("/add_project_users", dependencies=[Depends(verify_admin)])
- @web_try()
- @sxtimeit
- def add_users_to_project(item: schemas.AddUsersToProject, db: Session = Depends(get_db)):
- crud.add_users_to_project(db,item.user_ids,item.project_id)
- return 'success'
- @router.delete("/remove_project_users", dependencies=[Depends(verify_admin)])
- @web_try()
- @sxtimeit
- def remove_project_users(item: schemas.RemoveUsersToProject, db: Session = Depends(get_db)):
- crud.remove_project_users(db,item.user_id,item.project_id)
- return 'success'
- @router.put("/set_user_to_admin", dependencies=[Depends(verify_super_admin)])
- @web_try()
- @sxtimeit
- def set_user_to_admin(item: schemas.SetUserToAdmin, db: Session = Depends(get_db)):
- crud.set_user_to_admin(db,item.user_id,item.project_id)
- @router.put("/remove_user_to_admin", dependencies=[Depends(verify_super_admin)])
- @web_try()
- @sxtimeit
- def remove_user_to_admin(item: schemas.SetUserToAdmin, db: Session = Depends(get_db)):
- crud.remove_user_to_admin(db,item.user_id,item.project_id)
|