async def forward_rule_delete( response: Response, server_id: int, port_id: int, db=Depends(get_db), current_user=Depends(get_current_active_user), ): """ Delete a port forward rule """ forward_rule, port = delete_forward_rule(db, server_id, port_id, current_user) trigger_port_clean(port.server, port) return forward_rule
async def forward_rules_delete( response: Response, server_id: int, db=Depends(get_db), user=Depends(get_current_active_admin), ): """ Delete all port forward rules of the server """ db_forward_rules = get_forward_rule_for_server(db, server_id) for forward_rule in db_forward_rules: delete_forward_rule_by_id(db, forward_rule.id) trigger_port_clean(forward_rule.port.server, forward_rule.port) return db_forward_rules
async def port_delete( request: Request, server_id: int, port_id: int, db=Depends(get_db), current_user=Depends(get_current_active_admin), ): """ Delete an existing port on server """ db_port = get_port(db, server_id, port_id) if not db_port: raise HTTPException(status_code=404, detail="Port not found") if db_port.forward_rule: trigger_port_clean(db_port.server, db_port) delete_port(db, server_id, port_id) remove_tc(server_id, db_port.num) return db_port
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)