Skip to content

Commit

Permalink
feat(files): Source file upload: allow replacing source file with app…
Browse files Browse the repository at this point in the history
…ropriate unit permissions (#11513)

In addition to previous permission `component.edit`, now also allow the `replace` upload method on
source file upload, if the `unit.add`, `unit.delete` and `unit.edit` permissions are present.

This allows to give users access to replacing the source file, without having to give them full
`component.edit` permissions.

Co-authored-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
danimoh and nijel committed May 6, 2024
1 parent c07a08f commit 0e386e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/user/files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Replace existing translation file (``replace``)
Existing file is replaced with new content. This can lead to loss of existing
translations, use with caution.

This option is available only if the user has the :ref:`"Edit component settings" permission <privileges>`.
This option is available only if the user has the
:ref:`"Edit component settings" permission or "Add new string", "Remove a string" and "Edit strings" permissions <privileges>`.
Update source strings (``source``)
Updates source strings in bilingual translation file. This is similar to
what :ref:`addon-weblate.gettext.msgmerge` does.
Expand Down
5 changes: 3 additions & 2 deletions weblate/trans/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ def check_upload_method_permissions(
if method == "approve":
return user.has_perm("unit.review", translation)
if method == "replace":
return bool(translation.filename) and user.has_perm(
"component.edit", translation
return bool(translation.filename) and (
user.has_perm("component.edit", translation)
or user.has_perms(["unit.add", "unit.delete", "unit.edit"], translation)
)
raise ValueError(f"Invalid method: {method}")

Expand Down

0 comments on commit 0e386e6

Please sign in to comment.