def delete(self, sketch_id, group_id): """Handles DELETE request to the resource. Args: sketch_id: Integer primary key for a sketch database model. group_id: Integer primary key for an aggregation group database model. """ sketch = Sketch.query.get_with_acl(sketch_id) group = AggregationGroup.query.get(group_id) if not group: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No Group found with this ID.') if not sketch: abort( HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.') # Check that this group belongs to the sketch if group.sketch_id != sketch.id: msg = ( 'The sketch ID ({0:d}) does not match with the aggregation ' 'group sketch ID ({1:d})'.format(sketch.id, group.sketch_id)) abort(HTTP_STATUS_CODE_FORBIDDEN, msg) if not sketch.has_permission(user=current_user, permission='write'): abort( HTTP_STATUS_CODE_FORBIDDEN, 'The user does not have write permission on the sketch.') db_session.delete(group) db_session.commit() return HTTP_STATUS_CODE_OK
def delete(self, sketch_id, aggregation_id): """Handles DELETE request to the resource. Args: sketch_id: Integer primary key for a sketch database model. group_id: Integer primary key for an aggregation group database model. """ sketch = Sketch.query.get_with_acl(sketch_id) if not sketch: abort(HTTP_STATUS_CODE_NOT_FOUND, 'No sketch found with this ID.') aggregation = Aggregation.query.get(aggregation_id) if not aggregation: abort(HTTP_STATUS_CODE_NOT_FOUND, 'No aggregation found with this ID.') if not sketch.has_permission(user=current_user, permission='write'): abort(HTTP_STATUS_CODE_FORBIDDEN, 'The user does not have write permission on the sketch.') # Check that this aggregation belongs to the sketch if aggregation.sketch_id != sketch.id: msg = ('The sketch ID ({0:d}) does not match with the aggregation ' 'sketch ID ({1:d})'.format(sketch.id, aggregation.sketch_id)) abort(HTTP_STATUS_CODE_FORBIDDEN, msg) db_session.delete(aggregation) db_session.commit() # Update the last activity of a sketch. utils.update_sketch_last_activity(sketch) return HTTP_STATUS_CODE_OK
def run(self, index_name): """Delete timeline in both Timesketch and Elasticsearch. Args: index_name: The name of the index in Elasticsearch """ index_name = unicode(index_name.decode(encoding=u'utf-8')) searchindex = SearchIndex.query.filter_by( index_name=index_name).first() if not searchindex: sys.stdout.write(u'No such index\n') sys.exit() es = ElasticsearchDataStore(host=current_app.config[u'ELASTIC_HOST'], port=current_app.config[u'ELASTIC_PORT']) timelines = Timeline.query.filter_by(searchindex=searchindex).all() sketches = [ t.sketch for t in timelines if t.sketch and t.sketch.get_status.status != u'deleted' ] if sketches: sys.stdout.write(u'WARNING: This timeline is in use by:\n') for sketch in sketches: sys.stdout.write(u' * {0:s}\n'.format(sketch.name)) sys.stdout.flush() really_delete = prompt_bool( u'Are you sure you want to delete this timeline?') if really_delete: for timeline in timelines: db_session.delete(timeline) db_session.delete(searchindex) db_session.commit() es.client.indices.delete(index=index_name)
def delete(self, searchtemplate_id): """Handles DELETE request to the resource. Args: searchtemplate_id: Primary key for a search template database model Returns: HTTP status 200 if successful, otherwise error messages. """ searchtemplate = SearchTemplate.query.get(searchtemplate_id) if not searchtemplate: abort(HTTP_STATUS_CODE_NOT_FOUND, 'Search template was not found') saved_searches = View.query.filter_by(searchtemplate=searchtemplate) for saved_search in saved_searches: saved_search.searchtemplate = None db_session.delete(searchtemplate) db_session.commit() return HTTP_STATUS_CODE_OK
def run(self, index_name): """Delete timeline in both Timesketch and Elasticsearch. Args: index_name: The name of the index in Elasticsearch """ if not isinstance(index_name, six.text_type): index_name = codecs.decode(index_name, 'utf-8') searchindex = SearchIndex.query.filter_by( index_name=index_name).first() if not searchindex: sys.stdout.write('No such index\n') sys.exit() es = ElasticsearchDataStore( host=current_app.config['ELASTIC_HOST'], port=current_app.config['ELASTIC_PORT']) timelines = Timeline.query.filter_by(searchindex=searchindex).all() sketches = [ t.sketch for t in timelines if t.sketch and t.sketch.get_status.status != 'deleted' ] if sketches: sys.stdout.write('WARNING: This timeline is in use by:\n') for sketch in sketches: sys.stdout.write(' * {0:s}\n'.format(sketch.name)) sys.stdout.flush() really_delete = prompt_bool( 'Are you sure you want to delete this timeline?') if really_delete: for timeline in timelines: db_session.delete(timeline) db_session.delete(searchindex) db_session.commit() es.client.indices.delete(index=index_name)