2121from marshmallow import ValidationError
2222
2323from app .blueprints .access_controls import ac_api_requires
24+ from app .blueprints .access_controls import ac_api_return_access_denied
2425from app .blueprints .rest .endpoints import response_api_paginated
2526from app .blueprints .rest .endpoints import response_api_not_found
2627from app .blueprints .rest .endpoints import response_api_created
2728from app .blueprints .rest .endpoints import response_api_error
2829from app .blueprints .rest .endpoints import response_api_success
30+ from app .blueprints .rest .endpoints import response_api_deleted
2931from app .blueprints .rest .parsing import parse_pagination_parameters
3032from app .iris_engine .access_control .iris_user import iris_current_user
3133from app .business .comments import comments_get_filtered_by_event
3234from app .business .comments import comments_create_for_event
3335from app .business .comments import comments_get_for_event
36+ from app .business .comments import comments_delete_for_event
3437from app .business .events import events_get
3538from app .business .errors import ObjectNotFoundError
3639from app .models .cases import CasesEvent
@@ -86,6 +89,18 @@ def read(self, event_identifier, identifier):
8689 except ObjectNotFoundError :
8790 return response_api_not_found ()
8891
92+ def delete (self , event_identifier , identifier ):
93+ try :
94+ event = self ._get_event (event_identifier , [CaseAccessLevel .full_access ])
95+ comment = comments_get_for_event (event , identifier )
96+ if comment .comment_user_id != iris_current_user .id :
97+ return ac_api_return_access_denied ()
98+
99+ comments_delete_for_event (event , comment )
100+ return response_api_deleted ()
101+ except ObjectNotFoundError :
102+ return response_api_not_found ()
103+
89104
90105events_comments_blueprint = Blueprint ('events_comments' , __name__ , url_prefix = '/<int:event_identifier>/comments' )
91106comments_operations = CommentsOperations ()
@@ -107,3 +122,9 @@ def create_event_comment(event_identifier):
107122@ac_api_requires ()
108123def get_event_comment (event_identifier , identifier ):
109124 return comments_operations .read (event_identifier , identifier )
125+
126+
127+ @events_comments_blueprint .delete ('/<int:identifier>' )
128+ @ac_api_requires ()
129+ def delete_task_comment (event_identifier , identifier ):
130+ return comments_operations .delete (event_identifier , identifier )
0 commit comments