Skip to content

Commit

Permalink
auth: Avoid overlapping permission names
Browse files Browse the repository at this point in the history
The names have to be unique to correctly apply filtering on project scoped forms.
  • Loading branch information
nijel committed Oct 11, 2023
1 parent d0bfe7e commit 30b3066
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion weblate/auth/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
# Translators: Permission name
("announcement.edit", gettext_noop("Manage announcements")),
# Translators: Permission name
("memory.edit", gettext_noop("Manage translation memory")),
("memory.manage", gettext_noop("Manage translation memory")),
# Translators: Permission name
("machinery.edit", gettext_noop("Manage machinery")),
# Translators: Permission name
Expand Down
2 changes: 1 addition & 1 deletion weblate/auth/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def check_memory_perms(user, permission, memory):
if memory.user_id == user.id:
return True
if memory.project is None:
return user.is_superuser
return check_permission(user, "memory.manage")

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

View workflow job for this annotation

GitHub Actions / pylint

E1120: No value for argument 'obj' in function call (no-value-for-parameter)
project = memory.project
else:
project = memory
Expand Down
10 changes: 9 additions & 1 deletion weblate/auth/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from django.test.utils import modify_settings, override_settings
from django.utils import timezone

from weblate.auth.data import SELECTION_ALL_PROTECTED, SELECTION_ALL_PUBLIC
from weblate.auth.data import (
GLOBAL_PERM_NAMES,
PERMISSION_NAMES,
SELECTION_ALL_PROTECTED,
SELECTION_ALL_PUBLIC,
)
from weblate.auth.models import Group, Permission, Role, User
from weblate.trans.models import Comment, Project
from weblate.trans.tests.test_views import FixtureTestCase
Expand All @@ -24,6 +29,9 @@ def setUp(self):
)
self.project.add_user(self.admin, "Administration")

def test_permission_overlap(self):
self.assertEqual(PERMISSION_NAMES & GLOBAL_PERM_NAMES, set())

def test_admin_perm(self):
self.assertTrue(self.superuser.has_perm("upload.authorship", self.project))
self.assertTrue(self.admin.has_perm("upload.authorship", self.project))
Expand Down

0 comments on commit 30b3066

Please sign in to comment.