Skip to content

Commit

Permalink
feat: provide detailed error on permission denied for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Dec 3, 2024
1 parent 2f427d4 commit 5a2014e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Not yet released.
* Added page navigation while :ref:`translating`.
* :ref:`manage-appearance` now has distinct settings for dark mode.
* Improved :ref:`translation-propagation` performance.
* More detailed error messages for :http:post:`/api/translations/(string:project)/(string:component)/(string:language)/file/`.

**Bug fixes**
* Using the `has:variant` field now correctly displays strings that have variant(s) in the search language, see :ref:`search-strings`.
Expand Down
7 changes: 3 additions & 4 deletions weblate/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,8 @@ def file(self, request: Request, **kwargs):
except Http404 as error:
raise ValidationError({"format": str(error)}) from error

if not user.has_perm("upload.perform", obj):
raise PermissionDenied
if not (can_upload := user.has_perm("upload.perform", obj)):
self.permission_denied(request, can_upload.reason)

serializer = UploadRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down Expand Up @@ -1397,8 +1397,7 @@ def units(self, request: Request, **kwargs):
serializer_class = BilingualUnitSerializer

if request.method == "POST":
can_add = request.user.has_perm("unit.add", obj)
if not can_add:
if not (can_add := request.user.has_perm("unit.add", obj)):
self.permission_denied(request, can_add.reason)
serializer = serializer_class(
data=request.data, context={"translation": obj}
Expand Down

0 comments on commit 5a2014e

Please sign in to comment.