From 45e7d3ba984c070b7d48fa1b23a094e96414390d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 12 Oct 2015 13:08:40 +0200 Subject: [PATCH] models: modify Role.to_json() and Service.to_json() to list ou attributes --- src/authentic2/a2_rbac/models.py | 3 +++ src/authentic2/custom_user/models.py | 5 ++++- src/authentic2/models.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/authentic2/a2_rbac/models.py b/src/authentic2/a2_rbac/models.py index 7575171..1c7607c 100644 --- a/src/authentic2/a2_rbac/models.py +++ b/src/authentic2/a2_rbac/models.py @@ -157,6 +157,9 @@ class Role(RoleAbstractBase): 'slug': self.slug, 'is_admin': bool(self.admin_scope_ct and self.admin_scope_id), 'is_service': bool(self.service), + 'ou__uuid': self.ou.uuid if self.ou else None, + 'ou__name': self.ou.name if self.ou else None, + 'ou__slug': self.ou.slug if self.ou else None, } diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index e3d750c..7ac2e22 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -144,7 +144,10 @@ class User(AbstractBaseUser, PermissionMixin): 'uuid': self.uuid, 'username': self.username, 'email': self.email, - 'ou': unicode(self.ou) if self.ou else None, + 'ou': self.ou if self.ou else None, + 'ou__uuid': self.ou.uuid if self.ou else None, + 'ou__slug': self.ou.slug if self.ou else None, + 'ou__name': self.ou.name if self.ou else None, 'first_name': self.first_name, 'last_name': self.last_name, 'is_superuser': self.is_superuser, diff --git a/src/authentic2/models.py b/src/authentic2/models.py index 88280ac..a9fc5fd 100644 --- a/src/authentic2/models.py +++ b/src/authentic2/models.py @@ -286,6 +286,9 @@ class Service(models.Model): return { 'name': self.name, 'slug': self.slug, - 'ou': unicode(self.ou) if self.ou else None, + 'ou': self.ou if self.ou else None, + 'ou__uuid': self.ou.uuid if self.ou else None, + 'ou__name': self.ou.name if self.ou else None, + 'ou__slug': self.ou.slug if self.ou else None, 'roles': [role.to_json() for role in roles], } -- 2.1.4