Skip to content

Commit

Permalink
delete function works great again
Browse files Browse the repository at this point in the history
  • Loading branch information
FischLord committed Feb 8, 2024
1 parent 5608289 commit f984e0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Binary file modified database/ip_atlas.db
Binary file not shown.
27 changes: 25 additions & 2 deletions ip-atlas/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,37 @@ def delete_from_db(table, id):
tag = Tag.query.filter_by(id=id).first()
tag.deleted = True
elif table == "host_tag":
host_tag = HostTag.query.filter_by(id=id).first()
host_id, tag_id = id.split("_")
host_tag = HostTag.query.filter_by(host_id=host_id, tag_id=tag_id).first()
db.session.delete(host_tag)
elif table == "portFB":
portFB = PortFB.query.filter_by(id=id).first()
db.session.delete(portFB)
else:
print("Error: table not found")


# function which deletes an host from the table by the given id
def delete_host_by_id(id):
host = get_host_by_id(id)
portsFB = host["portsFB"]
tags = host["tags"]

print("Deleting host with ID:", id)
delete_from_db("host", id)
for portFB in portsFB:
portFBID = check_portFB_exists(portFB, method="id")
print("Deleting portFB with ID:", portFBID)
delete_from_db("portFB", portFBID)
for tag in tags:
tagID = check_tag_exists(tag, method="id")
print("Deleting host_tag with ID:", tagID)
# delete host_tag
for tag in tags:
tagID = check_tag_exists(tag, method="id")
print("Deleting host_tag with ID:", id, tagID)
delete_from_db("host_tag", f"{id}_{tagID}")
print("Host with id: ", id, " deleted")
db.session.commit()

# function which updates the given data in the table
def edit_db(table, data):
Expand Down
4 changes: 1 addition & 3 deletions ip-atlas/routes/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ def update_ip(id):
def delete(id):
id = int(id)
confirmed = request.args.get("confirmed")
data = loadJson()

if confirmed == "true":
deleteHost(id)
delete_host_by_id(id)
return jsonify(success=True)
else:
return jsonify(success=False, message="Deletion not confirmed")
Expand Down

0 comments on commit f984e0c

Please sign in to comment.