Exemplo n.º 1
0
async def port_users_delete(
    request: Request,
    server_id: int,
    port_id: int,
    user_id: int,
    db=Depends(get_db),
    current_user=Depends(get_current_active_admin),
):
    """
    Delete a port user for port
    """
    port_user = delete_port_user(db, server_id, port_id, user_id)
    return port_user
Exemplo n.º 2
0
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)