Skip to content

Commit

Permalink
add fundamental delete function that will delete from database and th…
Browse files Browse the repository at this point in the history
…e corresponding OS index in OS
  • Loading branch information
jaegeral committed Jan 14, 2025
1 parent 699e54a commit 28ce85e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion timesketch/api/v1/resources/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,20 @@ def delete(self, sketch_id):
HTTP_STATUS_CODE_FORBIDDEN,
"Sketch with the label [{0:s}] cannot be deleted.".format(label),
)

sketch.set_status(status="deleted")
# TODO: actually delete the sketch

for timeline in sketch.active_timelines:
timeline.set_status(status="deleted")
searchindex = timeline.searchindex
db_session.delete(searchindex)
db_session.delete(timeline)
# remove the opensearch index
self.datastore.client.indices.delete(index=searchindex.index_name)

db_session.delete(sketch)
db_session.commit()
# TODO: there needs to be a lot of related data to be deleted
return HTTP_STATUS_CODE_OK

@login_required
Expand Down
15 changes: 15 additions & 0 deletions timesketch/tsctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,21 @@ def print_table(table_data):
print()


@cli.command(name="sketch-delete")
@click.argument("sketch_id")
def sketch_delete(sketch_id):
"""Delete a sketch."""
sketch = Sketch.query.filter_by(id=sketch_id).first()
if not sketch:
print("Sketch does not exist.")
else:
print(f"Sketch {sketch_id} Name: ({sketch.name})")
sketch.delete()
db_session.delete(sketch)
db_session.commit()
print(f"Sketch {sketch_id} deleted.")


@cli.command(name="sketch-info")
@click.argument("sketch_id")
def sketch_info(sketch_id):
Expand Down

0 comments on commit 28ce85e

Please sign in to comment.