-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2718] fix: background task metadata #5909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,7 +50,7 @@ def delete(self, request, workspace_id, asset_key): | |||||||||||||||||||||||||||||||||||||||||||
| asset_key = str(workspace_id) + "/" + asset_key | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset = FileAsset.objects.get(asset=asset_key) | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.is_deleted = True | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save() | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save(update_fields=["is_deleted"]) | ||||||||||||||||||||||||||||||||||||||||||||
| return Response(status=status.HTTP_204_NO_CONTENT) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,7 +59,7 @@ def restore(self, request, workspace_id, asset_key): | |||||||||||||||||||||||||||||||||||||||||||
| asset_key = str(workspace_id) + "/" + asset_key | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset = FileAsset.objects.get(asset=asset_key) | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.is_deleted = False | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save() | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save(update_fields=["is_deleted"]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add permission checks and error handling for restore operation. Similar to the delete endpoint, this restore operation needs additional safeguards. Consider implementing these changes: def restore(self, request, workspace_id, asset_key):
asset_key = str(workspace_id) + "/" + asset_key
- file_asset = FileAsset.objects.get(asset=asset_key)
- file_asset.is_deleted = False
- file_asset.save(update_fields=["is_deleted"])
- return Response(status=status.HTTP_204_NO_CONTENT)
+ try:
+ file_asset = FileAsset.objects.get(asset=asset_key)
+
+ # Add permission check
+ if not request.user.has_workspace_permission(workspace_id, "update"):
+ return Response(
+ {"error": "You don't have permission to restore this asset"},
+ status=status.HTTP_403_FORBIDDEN
+ )
+
+ file_asset.is_deleted = False
+ file_asset.save(update_fields=["is_deleted"])
+ return Response(status=status.HTTP_204_NO_CONTENT)
+ except FileAsset.DoesNotExist:
+ return Response(
+ {"error": "Asset not found"},
+ status=status.HTTP_404_NOT_FOUND
+ )📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| return Response(status=status.HTTP_204_NO_CONTENT) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,5 +96,5 @@ def delete(self, request, asset_key): | |||||||||||||||||||||||||||||||||||||||||||
| asset=asset_key, created_by=request.user | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.is_deleted = True | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save() | ||||||||||||||||||||||||||||||||||||||||||||
| file_asset.save(update_fields=["is_deleted"]) | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for the delete operation. While this endpoint correctly scopes to user's own assets, it still needs error handling. Consider implementing these changes: def delete(self, request, asset_key):
- file_asset = FileAsset.objects.get(
- asset=asset_key, created_by=request.user
- )
- file_asset.is_deleted = True
- file_asset.save(update_fields=["is_deleted"])
- return Response(status=status.HTTP_204_NO_CONTENT)
+ try:
+ file_asset = FileAsset.objects.get(
+ asset=asset_key, created_by=request.user
+ )
+ file_asset.is_deleted = True
+ file_asset.save(update_fields=["is_deleted"])
+ return Response(status=status.HTTP_204_NO_CONTENT)
+ except FileAsset.DoesNotExist:
+ return Response(
+ {"error": "Asset not found"},
+ status=status.HTTP_404_NOT_FOUND
+ )
|
||||||||||||||||||||||||||||||||||||||||||||
| return Response(status=status.HTTP_204_NO_CONTENT) | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add permission checks and error handling.
While the update_fields optimization is good, this endpoint needs additional safeguards:
Consider implementing these changes:
def delete(self, request, workspace_id, asset_key): asset_key = str(workspace_id) + "/" + asset_key - file_asset = FileAsset.objects.get(asset=asset_key) - file_asset.is_deleted = True - file_asset.save(update_fields=["is_deleted"]) - return Response(status=status.HTTP_204_NO_CONTENT) + try: + file_asset = FileAsset.objects.get(asset=asset_key) + + # Add permission check + if not request.user.has_workspace_permission(workspace_id, "delete"): + return Response( + {"error": "You don't have permission to delete this asset"}, + status=status.HTTP_403_FORBIDDEN + ) + + file_asset.is_deleted = True + file_asset.save(update_fields=["is_deleted"]) + return Response(status=status.HTTP_204_NO_CONTENT) + except FileAsset.DoesNotExist: + return Response( + {"error": "Asset not found"}, + status=status.HTTP_404_NOT_FOUND + )