def delete_note(alert_id, note_id): customers = g.get('customers', None) alert = Alert.find_by_id(alert_id, customers) if not alert: raise ApiError('alert not found', 404) note = Note.find_by_id(note_id) if not note: raise ApiError('note not found', 404) write_audit_trail.send(current_app._get_current_object(), event='alert-note-deleted', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=note.id, type='note', request=request) if alert.delete_note(note_id): return jsonify(status='ok') else: raise ApiError('failed to delete note', 500)
def update_note(alert_id, note_id): if not request.json: raise ApiError('nothing to change', 400) customers = g.get('customers', None) alert = Alert.find_by_id(alert_id, customers) if not alert: raise ApiError('not found', 404) note = Note.find_by_id(note_id) if not note: raise ApiError('not found', 404) update = request.json update['user'] = g.login write_audit_trail.send(current_app._get_current_object(), event='alert-note-updated', message='', user=g.login, customers=g.customers, scopes=g.scopes, resource_id=note.id, type='note', request=request) _, update['text'] = process_note(alert, update.get('text')) updated = note.update(**update) if updated: return jsonify(status='ok', note=updated.serialize) else: raise ApiError('failed to update note', 500)
def delete_note(self, note_id): history = History(id=note_id, event=self.event, severity=self.severity, status=self.status, value=self.value, text='note dismissed', change_type=ChangeType.dismiss, update_time=datetime.utcnow(), user=g.login) db.add_history(self.id, history) return Note.delete_by_id(note_id)
def add_note(self, text: str) -> Note: note = Note.from_alert(self, text) history = History(id=note.id, event=self.event, severity=self.severity, status=self.status, value=self.value, text=text, change_type=ChangeType.note, update_time=datetime.utcnow(), user=g.login) db.add_history(self.id, history) return note
def get_alert_notes(self, page: int = 1, page_size: int = 100) -> List['Note']: notes = db.get_alert_notes(self.id, page, page_size) return [Note.from_db(note) for note in notes]
def add_note(self, text: str) -> Note: return Note.from_alert(self, text)