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 .iris_engine .access_control .iris_user import iris_current_user
3032from app .blueprints .rest .parsing import parse_pagination_parameters
3133from app .business .comments import comments_get_filtered_by_evidence
3234from app .business .comments import comments_create_for_evidence
3335from app .business .comments import comments_get_for_evidence
36+ from app .business .comments import comments_delete_for_evidence
3437from app .models .models import CaseReceivedFile
3538from app .business .evidences import evidences_get
3639from app .business .errors import ObjectNotFoundError
@@ -87,6 +90,18 @@ def read(self, event_identifier, identifier):
8790 except ObjectNotFoundError :
8891 return response_api_not_found ()
8992
93+ def delete (self , evidence_identifier , identifier ):
94+ try :
95+ evidence = self ._get_evidence (evidence_identifier , [CaseAccessLevel .full_access ])
96+ comment = comments_get_for_evidence (evidence , identifier )
97+ if comment .comment_user_id != iris_current_user .id :
98+ return ac_api_return_access_denied ()
99+
100+ comments_delete_for_evidence (evidence , comment )
101+ return response_api_deleted ()
102+ except ObjectNotFoundError :
103+ return response_api_not_found ()
104+
90105
91106evidences_comments_blueprint = Blueprint ('evidences_comments' , __name__ , url_prefix = '/<int:evidence_identifier>/comments' )
92107comments_operations = CommentsOperations ()
@@ -108,3 +123,9 @@ def create_evidence_comment(evidence_identifier):
108123@ac_api_requires ()
109124def get_evidence_comment (evidence_identifier , identifier ):
110125 return comments_operations .read (evidence_identifier , identifier )
126+
127+
128+ @evidences_comments_blueprint .delete ('/<int:identifier>' )
129+ @ac_api_requires ()
130+ def delete_evidence_comment (evidence_identifier , identifier ):
131+ return comments_operations .delete (evidence_identifier , identifier )
0 commit comments