diff --git a/weblate/auth/permissions.py b/weblate/auth/permissions.py index 83e53b2157f6..7edc930195fa 100644 --- a/weblate/auth/permissions.py +++ b/weblate/auth/permissions.py @@ -312,7 +312,9 @@ def check_unit_review( @register_perm("unit.edit", "suggestion.accept") def check_edit_approved( - user: User, permission: str, obj: Unit | Translation | Component | Project + user: User, + permission: str, + obj: Unit | Translation | Component | Project | ProjectLanguage, ) -> bool | PermissionResult: component = None if isinstance(obj, Unit): @@ -460,7 +462,7 @@ def check_suggestion_vote( @register_perm("suggestion.add") def check_suggestion_add( - user: User, permission: str, obj: Unit | Translation + user: User, permission: str, obj: Unit | Translation | ProjectLanguage ) -> bool | PermissionResult: if isinstance(obj, Unit): obj = obj.translation @@ -469,6 +471,7 @@ def check_suggestion_add( # Check contributor license agreement if ( not user.is_bot + and isinstance(obj, Translation) and obj.component.agreement and not ContributorAgreement.objects.has_agreed(user, obj.component) ): @@ -478,7 +481,7 @@ def check_suggestion_add( @register_perm("upload.perform") def check_upload( - user: User, permission: str, translation: Translation + user: User, permission: str, obj: Translation | ProjectLanguage ) -> bool | PermissionResult: """ Check whether user can perform any upload operation. @@ -486,29 +489,33 @@ def check_upload( The actual check for the method is implemented in weblate.trans.util.check_upload_method_permissions. """ - # Source upload - if translation.is_source and not user.has_perm("source.edit", translation): - return Denied(gettext("Insufficient privileges for editing source strings.")) - # Bilingual source translations - if ( - translation.is_source - and not translation.is_template - and not issubclass(translation.component.file_format_cls, BilingualUpdateMixin) - ): - return Denied( - gettext("The file format does not support updating source strings.") - ) - if translation.component.is_glossary: - permission = "glossary.upload" - return check_can_edit(user, permission, translation) and ( + if isinstance(obj, Translation): + # Source upload + if obj.is_source and not user.has_perm("source.edit", obj): + return Denied( + gettext("Insufficient privileges for editing source strings.") + ) + # Bilingual source translations + if ( + obj.is_source + and not obj.is_template + and not issubclass(obj.component.file_format_cls, BilingualUpdateMixin) + ): + return Denied( + gettext("The file format does not support updating source strings.") + ) + if obj.component.is_glossary: + permission = "glossary.upload" + + return check_can_edit(user, permission, obj) and ( # Normal upload - check_edit_approved(user, "unit.edit", translation) + check_edit_approved(user, "unit.edit", obj) # Suggestion upload - or check_suggestion_add(user, "suggestion.add", translation) + or check_suggestion_add(user, "suggestion.add", obj) # Add upload - or check_suggestion_add(user, "unit.add", translation) + or check_suggestion_add(user, "unit.add", obj) # Source upload - or translation.is_source + or (isinstance(obj, Translation) and obj.is_source) ) diff --git a/weblate/templates/language-project.html b/weblate/templates/language-project.html index 6edee5720f92..7538edb6a7df 100644 --- a/weblate/templates/language-project.html +++ b/weblate/templates/language-project.html @@ -4,6 +4,7 @@ {% block nav_pills %} {% perm 'project.edit' object.project as user_can_edit_project %} + {% perm 'upload.perform' object as user_can_upload_translation %}
+ {% blocktranslate trimmed %} + Project-wide uploads are currently not supported. Translation + files need to be uploaded on the individual translations. Switch + to the "Components" tab above, open the desired component, and + perform the upload there. + {% endblocktranslate %} +
+