@@ -1989,7 +1989,7 @@ class IssueAttachmentDetailAPIEndpoint(BaseAPIView):
19891989 """Issue Attachment Detail Endpoint"""
19901990
19911991 serializer_class = IssueAttachmentSerializer
1992- permission_classes = [ProjectEntityPermission ]
1992+ # permission_classes = [ProjectEntityPermission]
19931993 model = FileAsset
19941994 use_read_replica = True
19951995
@@ -2012,6 +2012,24 @@ def delete(self, request, slug, project_id, issue_id, pk):
20122012 Soft delete an attachment from a work item by marking it as deleted.
20132013 Records deletion activity and triggers metadata cleanup.
20142014 """
2015+ issue = Issue .objects .get (
2016+ pk = issue_id , workspace__slug = slug , project_id = project_id
2017+ )
2018+ # if the request user is creator or admin then delete the attachment
2019+ if (
2020+ not request .user == issue .created_by
2021+ and not ProjectMember .objects .filter (
2022+ project_id = project_id ,
2023+ user_id = request .user .id ,
2024+ role = ProjectMember .Role .ADMIN ,
2025+ is_active = True ,
2026+ ).exists ()
2027+ ):
2028+ return Response (
2029+ {"error" : "You are not allowed to delete this attachment" },
2030+ status = status .HTTP_403_FORBIDDEN ,
2031+ )
2032+
20152033 issue_attachment = FileAsset .objects .get (
20162034 pk = pk , workspace__slug = slug , project_id = project_id
20172035 )
@@ -2074,6 +2092,17 @@ def get(self, request, slug, project_id, issue_id, pk):
20742092
20752093 Retrieve details of a specific attachment.
20762094 """
2095+ # if the user is part of the project then allow the download
2096+ if not ProjectMember .objects .filter (
2097+ project_id = project_id ,
2098+ user_id = request .user .id ,
2099+ is_active = True ,
2100+ ).exists ():
2101+ return Response (
2102+ {"error" : "You are not allowed to download this attachment" },
2103+ status = status .HTTP_403_FORBIDDEN ,
2104+ )
2105+
20772106 # Get the asset
20782107 asset = FileAsset .objects .get (
20792108 id = pk , workspace__slug = slug , project_id = project_id
@@ -2128,6 +2157,24 @@ def patch(self, request, slug, project_id, issue_id, pk):
21282157 Mark an attachment as uploaded after successful file transfer to storage.
21292158 Triggers activity logging and metadata extraction.
21302159 """
2160+
2161+ issue = Issue .objects .get (
2162+ pk = issue_id , workspace__slug = slug , project_id = project_id
2163+ )
2164+ # if the user is creator or admin then allow the upload
2165+ if (
2166+ not request .user == issue .created_by
2167+ and not ProjectMember .objects .filter (
2168+ project_id = project_id ,
2169+ user_id = request .user .id ,
2170+ role = ProjectMember .Role .ADMIN ,
2171+ ).exists ()
2172+ ):
2173+ return Response (
2174+ {"error" : "You are not allowed to upload this attachment" },
2175+ status = status .HTTP_403_FORBIDDEN ,
2176+ )
2177+
21312178 issue_attachment = FileAsset .objects .get (
21322179 pk = pk , workspace__slug = slug , project_id = project_id
21332180 )
0 commit comments