async def user_details( request: Request, user_id: int, db=Depends(get_db), current_user=Depends(get_current_active_superuser), ): """ Get any user details """ user = get_user(db, user_id) return jsonable_encoder(user)
async def port_user_add( request: Request, server_id: int, port_id: int, port_user: PortUserCreate, db=Depends(get_db), current_user=Depends(get_current_active_admin), ): """ Add a port user to port """ db_user = get_user(db, port_user.user_id) if not db_user: raise HTTPException(status_code=400, detail="User not found") port_user = add_port_user(db, server_id, port_id, port_user) return jsonable_encoder(port_user)
async def user_delete( request: Request, user_id: int, user_delete: UserDelete, db=Depends(get_db), current_user=Depends(get_current_active_superuser), ): """ Delete existing user """ user = get_user(db, user_id) if not user: raise HTTPException(status.HTTP_404_NOT_FOUND, detail="User not found") if user_delete.remove_rule: for port in user.ports: edit_port_usage( db, port.id, PortUsageEdit( port_id=port.id, download=0, upload=0, download_accumulate=0, upload_accumulate=0, download_checkpoint=0, upload_checkpoint=0, ), ) if port.forward_rule: trigger_port_clean(port.server, port, False) delete_forward_rule_by_id(db, port.forward_rule.id) for port_user in user.allowed_ports: delete_port_user( db, port_user.port.server.id, port_user.port_id, user.id ) for server_user in user.allowed_servers: delete_server_user(db, server_user.server_id, user.id) return delete_user(db, user)
async def port_user_add( request: Request, server_id: int, port_id: int, port_user: PortUserCreate, db=Depends(get_db), current_user=Depends(get_current_active_admin), ): """ Add a port user to port """ db_user = get_user(db, port_user.user_id) if not db_user: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="User not found") db_port_user = get_port_user(db, server_id, port_id, port_user.user_id) if db_port_user: raise HTTPException( status_code=status.HTTP_409_CONFLICT, detail="Port user already exists", ) port_user = add_port_user(db, server_id, port_id, port_user) return jsonable_encoder(port_user)