暫無描述

case_comments.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # IRIS Source Code
  2. # Copyright (C) 2024 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from datetime import datetime
  19. from flask_login import current_user
  20. from app import db
  21. from app.datamgmt.case.case_comments import get_case_comment
  22. from app.iris_engine.module_handler.module_handler import call_modules_hook
  23. from app.iris_engine.utils.tracker import track_activity
  24. from app.business.errors import BusinessProcessingError
  25. def case_comments_update(comment_text, comment_id, object_type, caseid):
  26. comment = get_case_comment(comment_id, caseid=caseid)
  27. if not comment:
  28. raise BusinessProcessingError('Invalid comment ID')
  29. if hasattr(current_user, 'id') and current_user.id is not None:
  30. if comment.comment_user_id != current_user.id:
  31. raise BusinessProcessingError('Permission denied')
  32. comment.comment_text = comment_text
  33. comment.comment_update_date = datetime.utcnow()
  34. db.session.commit()
  35. hook = object_type
  36. if hook.endswith('s'):
  37. hook = hook[:-1]
  38. call_modules_hook(f'on_postload_{hook}_comment_update', data=comment, caseid=caseid)
  39. track_activity(f"comment {comment.comment_id} on {object_type} edited", caseid=caseid)
  40. return comment