Skip to content

Commit

Permalink
Allow object permissions with dots.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyarnold authored and brianmay committed Nov 27, 2019
1 parent 8d992c2 commit 1547aa3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ Authors ordered by first contribution
- Adam Dobrawy <guardian@jawnosc.tk>
- Jeff Hackshaw <intrepidevio@gmail.com>
- Chase Bennett <ch@se.gd>
- Jonny Arnold <jonny.arnold89@gmail.com>
3 changes: 2 additions & 1 deletion guardian/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def assign_perm(perm, user_or_group, obj=None):
return perm

if not isinstance(perm, Permission):
perm = perm.split('.')[-1]
if '.' in perm:
app_label, perm = perm.split(".", 1)

if isinstance(obj, QuerySet):
if isinstance(user_or_group, (QuerySet, list)):
Expand Down
9 changes: 9 additions & 0 deletions guardian/testapp/tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ def test_group_assign_perm_global(self):
self.assertTrue(self.user.has_perm("contenttypes.change_contenttype"))
self.assertTrue(isinstance(perm, Permission))

def test_assign_perm_with_dots(self):
Permission.objects.create(
codename="contenttype.reorder",
content_type=ContentType.objects.get_for_model(self.ctype)
)

assign_perm("contenttypes.contenttype.reorder", self.user, self.ctype)
self.assertTrue(self.user.has_perm("contenttypes.contenttype.reorder", self.ctype))

def test_deprecation_warning(self):
with warnings.catch_warnings(record=True) as warns:
warnings.simplefilter('always')
Expand Down

0 comments on commit 1547aa3

Please sign in to comment.