Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissions language reworked #13365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions weblate/auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@


def check_global_permission(user: User, permission: str) -> bool:
"""Check whether user has a global permission."""
"""Check whether the user has a global permission."""
if user.is_superuser:
return True
return permission in user.global_permissions
Expand Down Expand Up @@ -129,9 +129,9 @@

@register_perm("comment.resolve", "comment.delete", "suggestion.delete")
def check_delete_own(user: User, permission: str, obj: Model):
if user.is_authenticated and obj.user == user:

Check failure on line 132 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "user"
return True
return check_permission(user, permission, obj.unit.translation)

Check failure on line 134 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "unit"


@register_perm("unit.check")
Expand Down Expand Up @@ -191,15 +191,15 @@
):
return Denied(
gettext(
"Contributing to this translation requires agreeing to its contributor agreement."
"Contributing to this translation requires accepting its contributor license agreement."
)
)

# Perform usual permission check
if not check_permission(user, permission, obj):
if not user.is_authenticated:
# Signing in might help, but user still might need additional privileges
return Denied(gettext("Sign in to save the translation."))
return Denied(gettext("Sign in to save translations."))
if permission == "unit.review":
return Denied(
gettext("Insufficient privileges for approving translations.")
Expand All @@ -226,7 +226,7 @@
):
return Denied(
gettext(
"This translation only accepts suggestions, and these are approved by voting."
"This translation only accepts suggestions, in turn approved by voting."
)
)

Expand All @@ -245,8 +245,8 @@
if isinstance(obj, Translation):
if not obj.enable_review:
if obj.is_source:
return Denied(gettext("Source string reviews are not enabled."))
return Denied(gettext("Translation reviews are not enabled."))
return Denied(gettext("Source-string reviews are turned off."))
return Denied(gettext("Translation reviews are turned off."))
else:
if isinstance(obj, CategoryLanguage):
project = obj.category.project
Expand All @@ -258,7 +258,7 @@
else:
project = obj
if not project.source_review and not project.translation_review:
return Denied(gettext("Reviews are not enabled."))
return Denied(gettext("Reviewing is turned off."))
return check_can_edit(user, permission, obj)


Expand All @@ -283,7 +283,7 @@
):
return Denied(
gettext(
"Only reviewers can change approved strings, please add a suggestion if you think the string should be changed."
"Only reviewers can change approved strings. Please add a suggestion if you think the string should be changed."
)
)
if isinstance(obj, Translation):
Expand Down Expand Up @@ -325,19 +325,19 @@
):
return Denied(
gettext(
"Cannot remove terminology translation, remove source string instead."
"Cannot remove terminology translation. Remove the source string instead."
)
)
obj = obj.translation
component = obj.component

Check failure on line 332 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "component"
# Check if removing is generally allowed
can_manage = check_manage_units(obj, component)

Check failure on line 334 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "check_manage_units" has incompatible type "Model"; expected "Translation"
if not can_manage:
return can_manage

# Does file format support removing?
if not component.file_format_cls.can_delete_unit:
return Denied(gettext("File format does not support this."))
return Denied(gettext("The file format does not support this."))

Check warning on line 340 in weblate/auth/permissions.py

View check run for this annotation

Codecov / codecov/patch

weblate/auth/permissions.py#L340

Added line #L340 was not covered by tests

if component.is_glossary:
permission = "glossary.delete"
Expand All @@ -354,7 +354,7 @@

# Does file format support adding?
if not component.file_format_cls.can_add_unit:
return Denied(gettext("File format does not support this."))
return Denied(gettext("The file format does not support this."))

if component.is_glossary:
permission = "glossary.add"
Expand Down Expand Up @@ -394,13 +394,13 @@
def check_suggestion_add(user: User, permission: str, obj: Model):
if isinstance(obj, Unit):
obj = obj.translation
if not obj.enable_suggestions or obj.is_readonly:

Check failure on line 397 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "enable_suggestions"

Check failure on line 397 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "is_readonly"
return False
# Check contributor agreement
if (
not user.is_bot
and obj.component.agreement

Check failure on line 402 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "component"
and not ContributorAgreement.objects.has_agreed(user, obj.component)

Check failure on line 403 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "component"
):
return False
return check_permission(user, permission, obj)
Expand Down Expand Up @@ -449,7 +449,7 @@

@register_perm("translation.delete")
def check_translation_delete(user: User, permission: str, obj: Model):
if obj.is_source:

Check failure on line 452 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "is_source"
return False
return check_permission(user, permission, obj)

Expand All @@ -476,7 +476,7 @@
return (
check_global_permission(user, "group.edit")
or (
obj.defining_project

Check failure on line 479 in weblate/auth/permissions.py

View workflow job for this annotation

GitHub Actions / mypy

"Model" has no attribute "defining_project"
and check_permission(user, "project.permissions", obj.defining_project)
)
or obj.admins.filter(pk=user.pk).exists()
Expand Down
Loading