def owner_purge_user(team_id): session = current_app.db.session res = request.get_json() user_idt = res.get("user_id") owner_idt = get_jwt_identity() excluir_registro = TeamUserModel.query.filter( TeamUserModel.team_id == team_id, TeamUserModel.user_id == user_idt, TeamModel.owner_id == owner_idt, ).first() try: if excluir_registro.team.owner_id == owner_idt: session.delete(excluir_registro) session.commit() return { f"the user {excluir_registro.user.nickname} has been expelled": f"{excluir_registro.team.team_name}", }, HTTPStatus.OK else: return { "error": "You aren't the owner of the team" }, HTTPStatus.UNAUTHORIZED except AttributeError: return {"error": "Team id or user id incorrects."}, HTTPStatus.NOT_FOUND
def delete_user(id): session = db_session.create_session() user = session.query(User).get(id) auth = user.auth[0] session.delete(user) session.delete(auth) session.commit() session.close()
def delete(self, user_id): user = UserModel.query.get_or_404(user_id) session = current_app.db.session session.delete(user) session.commit() return { "data": f"User {user_id} has successfully been deleted" }, HTTPStatus.OK
def admin_decline_user(id): if check_user(id): session = db_session.create_session() user = session.query(User).get(id) session.delete(user) session.delete( session.query(Applications).filter( Applications.user_id == id).first()) session.commit() session.close() return True
def admin_accept_user(id): if check_user(id): session = db_session.create_session() user = session.query(User).get(id) user.is_approved = True application = session.query(Applications).filter( Applications.user_id == id).first() session.delete(application) session.commit() session.close() return True
def delete_reservation(reservation_id): session = Session() try: reservation = session.query(Reservation).filter_by( id=int(reservation_id)).one() except Exception: abort(404, description="Reservation not found") auth_check(reservation.user_id, auth.current_user()) session.delete(reservation) session.commit() return jsonify({"Success": "Reservation has been deleted"}), 200
def delete_team(team_id): session = current_app.db.session owner_id = get_jwt_identity() team_to_be_deleted: TeamModel = TeamModel.query.filter_by( owner_id=owner_id, id=team_id ).first() if not team_to_be_deleted: return {"error": "Invalid team ID"}, HTTPStatus.NOT_FOUND session.delete(team_to_be_deleted) session.commit() return {"message": f"Deleted team with ID: {team_id}"}, HTTPStatus.OK
def delete_user(user_id): session = Session() auth_check(user_id, auth.current_user()) user = session.query(User).filter_by(id=int(user_id)).one() reservations = session.query(Reservation).filter_by( user_id=int(user_id)).all() session.delete(user) for reservation in reservations: session.delete(reservation) session.commit() return jsonify({"Success": "User has been deleted"}), 200
def delete_category(id): session = current_app.db.session category_filter = CategoryModel.query.get(id) session.delete(category_filter) session.commit() return {}, HTTPStatus.NO_CONTENT