(self, sketch_id, timeline_id)
return HTTP_STATUS_CODE_OK
Handles DELETE request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
            timeline_id: Integer primary key for a timeline database model
Handles DELETE request to the resource.
Handles DELETE request to the resource .
def delete(self, sketch_id, timeline_id):
        """Handles DELETE request to the resource.

        Args:
            sketch_id: Integer primary key for a sketch database model
            timeline_id: Integer primary key for a timeline 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.')

        timeline = Timeline.query.get(timeline_id)
        if not timeline:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND, 'No timeline found with this ID.')

        if timeline.sketch is None:
            abort(
                HTTP_STATUS_CODE_NOT_FOUND,
                'No sketch associated with this timeline.')

        # Check that this timeline belongs to the sketch
        if timeline.sketch.id != sketch.id:
            if not timeline:
                msg = 'No timeline found with this ID.'
            elif not sketch:
                msg = 'No sketch found with this ID.'
            else:
                sketch_use = sketch.id or 'No sketch ID'
                sketch_string = str(sketch_use)

                timeline_use = timeline.sketch.id or (
                    'No sketch associated with the timeline.')
                timeline_string = str(timeline_use)

                msg = (
                    'The sketch ID ({0:s}) does not match with the timeline '
                    'sketch ID ({1:s})'.format(sketch_string, timeline_string))
            abort(HTTP_STATUS_CODE_NOT_FOUND, 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.')

        not_delete_labels = current_app.config.get(
            'LABELS_TO_PREVENT_DELETION', [])
        for label in not_delete_labels:
            if timeline.has_label(label):
                abort(
                    HTTP_STATUS_CODE_FORBIDDEN,
                    'Timelines with label [{0:s}] cannot be deleted.'.format(
                        label))

        # Check if this searchindex is used in other sketches.
        close_index = True
        searchindex = timeline.searchindex
        index_name = searchindex.index_name
        search_indices = SearchIndex.query.filter_by(
            index_name=index_name).all()
        timelines = []
        for index in search_indices:
            timelines.extend(index.timelines)

        for timeline_ in timelines:
            if timeline_.sketch is None:
                continue

            if timeline_.sketch.id != sketch.id:
                close_index = False
                break

            if timeline_.id != timeline_id:
                # There are more than a single timeline using this index_name,
                # we can't close it (unless this timeline is archived).
                if timeline_.get_status.status != 'archived':
                    close_index = False
                    break

        if close_index:
            try:
                self.datastore.client.indices.close(
                    index=searchindex.index_name)
            except opensearchpy.NotFoundError:
                logger.error(
                    'Unable to close index: {0:s} - index not '
                    'found'.format(searchindex.index_name))

            searchindex.set_status(status='archived')
            timeline.set_status(status='archived')

        sketch.timelines.remove(timeline)
        db_session.commit()

        # Update the last activity of a sketch.
        utils.update_sketch_last_activity(sketch)

        return HTTP_STATUS_CODE_OK
def delete ( self , sketch_id , timeline_id ) : sketch = Sketch . query . get_with_acl ( sketch_id ) if not sketch : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch found with this ID.' ) timeline = Timeline . query . get ( timeline_id ) if not timeline : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No timeline found with this ID.' ) if timeline . sketch is None : abort ( HTTP_STATUS_CODE_NOT_FOUND , 'No sketch associated with this timeline.' ) # Check that this timeline belongs to the sketch if timeline . sketch . id != sketch . id : if not timeline : msg = 'No timeline found with this ID.' elif not sketch : msg = 'No sketch found with this ID.' else : sketch_use = sketch . id or 'No sketch ID' sketch_string = str ( sketch_use ) timeline_use = timeline . sketch . id or ( 'No sketch associated with the timeline.' ) timeline_string = str ( timeline_use ) msg = ( 'The sketch ID ({0:s}) does not match with the timeline ' 'sketch ID ({1:s})' . format ( sketch_string , timeline_string ) ) abort ( HTTP_STATUS_CODE_NOT_FOUND , 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.' ) not_delete_labels = current_app . config . get ( 'LABELS_TO_PREVENT_DELETION' , [ ] ) for label in not_delete_labels : if timeline . has_label ( label ) : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'Timelines with label [{0:s}] cannot be deleted.' . format ( label ) ) # Check if this searchindex is used in other sketches. close_index = True searchindex = timeline . searchindex index_name = searchindex . index_name search_indices = SearchIndex . query . filter_by ( index_name = index_name ) . all ( ) timelines = [ ] for index in search_indices : timelines . extend ( index . timelines ) for timeline_ in timelines : if timeline_ . sketch is None : continue if timeline_ . sketch . id != sketch . id : close_index = False break if timeline_ . id != timeline_id : # There are more than a single timeline using this index_name, # we can't close it (unless this timeline is archived). if timeline_ . get_status . status != 'archived' : close_index = False break if close_index : try : self . datastore . client . indices . close ( index = searchindex . index_name ) except opensearchpy . NotFoundError : logger . error ( 'Unable to close index: {0:s} - index not ' 'found' . format ( searchindex . index_name ) ) searchindex . set_status ( status = 'archived' ) timeline . set_status ( status = 'archived' ) sketch . timelines . remove ( timeline ) db_session . commit ( ) # Update the last activity of a sketch. utils . update_sketch_last_activity ( sketch ) return HTTP_STATUS_CODE_OK