From ed5e3d5226a908adff3f83611156f7d253b778f3 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sat, 6 Aug 2016 11:31:39 +0200 Subject: [PATCH] Unfold many to many attributes in auth.DjangoAuthUser --- cas_server/auth.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cas_server/auth.py b/cas_server/auth.py index 81dc37f..5f4913a 100644 --- a/cas_server/auth.py +++ b/cas_server/auth.py @@ -379,6 +379,23 @@ class DjangoAuthUser(AuthUser): # pragma: no cover field_names = self.user._meta.get_all_field_names() for name in field_names: attr[name] = getattr(self.user, name) + + # unfold user_permissions many to many relation + if 'user_permissions' in attr: + attr['user_permissions'] = [ + ( + u"%s.%s" % ( + perm.content_type.model_class().__module__, + perm.content_type.model_class().__name__ + ), + perm.codename + ) for perm in attr['user_permissions'].filter() + ] + + # unfold group many to many relation + if 'groups' in attr: + attr['groups'] = [group.name for group in attr['groups'].filter()] + return attr else: return {}