@@ -312,7 +312,9 @@ def check_unit_review(
312312
313313@register_perm ("unit.edit" , "suggestion.accept" )
314314def check_edit_approved (
315- user : User , permission : str , obj : Unit | Translation | Component | Project
315+ user : User ,
316+ permission : str ,
317+ obj : Unit | Translation | Component | Project | ProjectLanguage ,
316318) -> bool | PermissionResult :
317319 component = None
318320 if isinstance (obj , Unit ):
@@ -460,7 +462,7 @@ def check_suggestion_vote(
460462
461463@register_perm ("suggestion.add" )
462464def check_suggestion_add (
463- user : User , permission : str , obj : Unit | Translation
465+ user : User , permission : str , obj : Unit | Translation | ProjectLanguage
464466) -> bool | PermissionResult :
465467 if isinstance (obj , Unit ):
466468 obj = obj .translation
@@ -469,6 +471,7 @@ def check_suggestion_add(
469471 # Check contributor license agreement
470472 if (
471473 not user .is_bot
474+ and isinstance (obj , Translation )
472475 and obj .component .agreement
473476 and not ContributorAgreement .objects .has_agreed (user , obj .component )
474477 ):
@@ -478,37 +481,41 @@ def check_suggestion_add(
478481
479482@register_perm ("upload.perform" )
480483def check_upload (
481- user : User , permission : str , translation : Translation
484+ user : User , permission : str , obj : Translation | ProjectLanguage
482485) -> bool | PermissionResult :
483486 """
484487 Check whether user can perform any upload operation.
485488
486489 The actual check for the method is implemented in
487490 weblate.trans.util.check_upload_method_permissions.
488491 """
489- # Source upload
490- if translation .is_source and not user .has_perm ("source.edit" , translation ):
491- return Denied (gettext ("Insufficient privileges for editing source strings." ))
492- # Bilingual source translations
493- if (
494- translation .is_source
495- and not translation .is_template
496- and not issubclass (translation .component .file_format_cls , BilingualUpdateMixin )
497- ):
498- return Denied (
499- gettext ("The file format does not support updating source strings." )
500- )
501- if translation .component .is_glossary :
502- permission = "glossary.upload"
503- return check_can_edit (user , permission , translation ) and (
492+ if isinstance (obj , Translation ):
493+ # Source upload
494+ if obj .is_source and not user .has_perm ("source.edit" , obj ):
495+ return Denied (
496+ gettext ("Insufficient privileges for editing source strings." )
497+ )
498+ # Bilingual source translations
499+ if (
500+ obj .is_source
501+ and not obj .is_template
502+ and not issubclass (obj .component .file_format_cls , BilingualUpdateMixin )
503+ ):
504+ return Denied (
505+ gettext ("The file format does not support updating source strings." )
506+ )
507+ if obj .component .is_glossary :
508+ permission = "glossary.upload"
509+
510+ return check_can_edit (user , permission , obj ) and (
504511 # Normal upload
505- check_edit_approved (user , "unit.edit" , translation )
512+ check_edit_approved (user , "unit.edit" , obj )
506513 # Suggestion upload
507- or check_suggestion_add (user , "suggestion.add" , translation )
514+ or check_suggestion_add (user , "suggestion.add" , obj )
508515 # Add upload
509- or check_suggestion_add (user , "unit.add" , translation )
516+ or check_suggestion_add (user , "unit.add" , obj )
510517 # Source upload
511- or translation .is_source
518+ or ( isinstance ( obj , Translation ) and obj .is_source )
512519 )
513520
514521
0 commit comments