Skip to content

Commit

Permalink
Unit: Allow string removal for bilingual formats
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jan 29, 2021
1 parent 5a5809f commit 68b97f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Not yet released.
* Improved performance of consistency checks.
* Improved performance of translation memory for long strings.
* Added support for searching in explanations.
* New strings can now be added in bilingual formats as well.
* Strings can now be added and removed in bilingual formats as well.

Weblate 4.4.2
-------------
Expand Down
23 changes: 16 additions & 7 deletions weblate/auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,25 @@ def check_edit_approved(user, permission, obj):
return check_can_edit(user, permission, obj)


def check_manage_units(translation: Translation, component: Component) -> bool:
# Check if adding is generally allowed
if not component.manage_units or translation.is_readonly:
return False
source = translation.is_source
template = component.has_template()
# Add to source in monolingual and to translations in bilingual
if (source and not template) or (not source and template):
return False
return True


@register_perm("unit.delete")
def check_unit_delete(user, permission, obj):
if isinstance(obj, Unit):
obj = obj.translation
if not obj.is_source or obj.is_readonly:
component = obj.component
# Check if removing is generally allowed
if not check_manage_units(obj, component):
return False
return check_can_edit(user, permission, obj)

Expand All @@ -210,12 +224,7 @@ def check_unit_delete(user, permission, obj):
def check_unit_add(user, permission, translation):
component = translation.component
# Check if adding is generally allowed
if not component.manage_units or translation.is_readonly:
return False
source = translation.is_source
template = component.has_template()
# Add to source in monolingual and to translations in bilingual
if (source and not template) or (not source and template):
if not check_manage_units(translation, component):
return False

# Does file format support adding?
Expand Down

0 comments on commit 68b97f6

Please sign in to comment.