Skip to content

Commit 8344e60

Browse files
committed
Implementation of DELETE /api/v2/tasks/{object_identifier}/comments/{identifier}
1 parent 1055a0c commit 8344e60

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

source/app/blueprints/rest/v2/tasks_routes/comments.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222

2323
from app.iris_engine.access_control.iris_user import iris_current_user
2424
from app.blueprints.access_controls import ac_api_requires
25+
from app.blueprints.access_controls import ac_api_return_access_denied
2526
from app.blueprints.rest.endpoints import response_api_paginated
2627
from app.blueprints.rest.endpoints import response_api_not_found
2728
from app.blueprints.rest.parsing import parse_pagination_parameters
2829
from app.blueprints.rest.endpoints import response_api_created
2930
from app.blueprints.rest.endpoints import response_api_error
3031
from app.blueprints.rest.endpoints import response_api_success
32+
from app.blueprints.rest.endpoints import response_api_deleted
3133
from app.business.comments import comments_get_filtered_by_task
3234
from app.business.comments import comments_create_for_task
3335
from app.business.comments import comments_get_for_task
36+
from app.business.comments import comments_delete_for_task
3437
from app.business.tasks import tasks_get
3538
from app.business.errors import ObjectNotFoundError
3639
from app.schema.marshables import CommentSchema
@@ -86,6 +89,18 @@ def read(self, task_identifier, identifier):
8689
except ObjectNotFoundError:
8790
return response_api_not_found()
8891

92+
def delete(self, task_identifier, identifier):
93+
try:
94+
task = self._get_task(task_identifier, [CaseAccessLevel.full_access])
95+
comment = comments_get_for_task(task, identifier)
96+
if comment.comment_user_id != iris_current_user.id:
97+
return ac_api_return_access_denied()
98+
99+
comments_delete_for_task(task, comment)
100+
return response_api_deleted()
101+
except ObjectNotFoundError:
102+
return response_api_not_found()
103+
89104

90105
tasks_comments_blueprint = Blueprint('tasks_comments', __name__, url_prefix='/<int:task_identifier>/comments')
91106
comments_operations = CommentsOperations()
@@ -107,3 +122,9 @@ def create_tasks_comment(task_identifier):
107122
@ac_api_requires()
108123
def get_task_comment(task_identifier, identifier):
109124
return comments_operations.read(task_identifier, identifier)
125+
126+
127+
@tasks_comments_blueprint.delete('/<int:identifier>')
128+
@ac_api_requires()
129+
def delete_task_comment(task_identifier, identifier):
130+
return comments_operations.delete(task_identifier, identifier)

source/app/business/comments.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from app.datamgmt.case.case_rfiles_db import delete_evidence_comment
5151
from app.datamgmt.case.case_iocs_db import delete_ioc_comment
5252
from app.datamgmt.case.case_notes_db import delete_note_comment
53+
from app.datamgmt.case.case_tasks_db import delete_task_comment
5354
from app.iris_engine.module_handler.module_handler import call_modules_hook
5455
from app.iris_engine.utils.tracker import track_activity
5556
from app.models.comments import Comments
@@ -326,3 +327,10 @@ def comments_delete_for_note(note: Notes, comment: Comments):
326327

327328
call_modules_hook('on_postload_note_comment_delete', comment.comment_id, caseid=comment.comment_case_id)
328329
track_activity(f'comment {comment.comment_id} on note {note.note_id} deleted', caseid=comment.comment_case_id)
330+
331+
332+
def comments_delete_for_task(task: CaseTasks, comment: Comments):
333+
delete_task_comment(task.id, comment.comment_id)
334+
335+
call_modules_hook('on_postload_task_comment_delete', comment.comment_id, caseid=comment.comment_case_id)
336+
track_activity(f'comment {comment.comment_id} on task {task.id} deleted', caseid=comment.comment_case_id)

source/app/datamgmt/case/case_tasks_db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ def get_case_task_comment(task_id, comment_id):
267267
Comments.comment_date,
268268
Comments.comment_update_date,
269269
Comments.comment_uuid,
270+
Comments.comment_user_id,
271+
Comments.comment_case_id,
270272
User.name,
271273
User.user
272274
).join(

tests/tests_rest_comments.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,14 @@ def test_delete_notes_comment_should_return_204(self):
663663

664664
response = self._subject.delete(f'/api/v2/notes/{object_identifier}/comments/{identifier}')
665665
self.assertEqual(204, response.status_code)
666+
667+
def test_delete_tasks_comment_should_return_204(self):
668+
case_identifier = self._subject.create_dummy_case()
669+
body = {'task_assignees_id': [], 'task_status_id': 1, 'task_title': 'dummy title'}
670+
response = self._subject.create(f'/api/v2/cases/{case_identifier}/tasks', body).json()
671+
object_identifier = response['id']
672+
response = self._subject.create(f'/api/v2/tasks/{object_identifier}/comments', {}).json()
673+
identifier = response['comment_id']
674+
675+
response = self._subject.delete(f'/api/v2/tasks/{object_identifier}/comments/{identifier}')
676+
self.assertEqual(204, response.status_code)

0 commit comments

Comments
 (0)