0001-a2_rbac-modify-Role.to_json-to-list-all-roles-visibl.patch
src/authentic2/custom_user/models.py | ||
---|---|---|
148 | 148 |
'first_name': self.first_name, |
149 | 149 |
'last_name': self.last_name, |
150 | 150 |
'is_superuser': self.is_superuser, |
151 |
'roles': [role.to_json() for role in self.roles_and_parents().filter(service__isnull=True)],
|
|
152 |
'services': [service.to_json(user=self) for service in Service.objects.all()],
|
|
151 |
'roles': [role.to_json() for role in self.roles_and_parents()], |
|
152 |
'services': [service.to_json(roles=self.roles_and_parents()) for service in Service.objects.all()],
|
|
153 | 153 |
}) |
154 | 154 |
return d |
src/authentic2/models.py | ||
---|---|---|
3 | 3 |
from django.utils.http import urlquote |
4 | 4 |
from django.conf import settings |
5 | 5 |
from django.db import models |
6 |
from django.db.models.query import Q |
|
6 | 7 |
from django.utils.translation import ugettext_lazy as _ |
7 | 8 |
from django.core.exceptions import ValidationError |
8 | 9 | |
... | ... | |
278 | 279 |
def __unicode__(self): |
279 | 280 |
return self.name |
280 | 281 | |
281 |
def to_json(self, user=None): |
|
282 |
if user: |
|
283 |
roles = user.roles_and_parents().filter(service=self) |
|
284 |
else: |
|
285 |
roles = self.roles.all() |
|
282 |
def to_json(self, roles=None): |
|
283 |
if not roles: |
|
284 |
roles = Role.objects.all() |
|
285 |
roles = roles.filter(Q(service=self)|Q(ou=self.ou, service__isnull=True)) |
|
286 | 286 |
return { |
287 | 287 |
'name': self.name, |
288 | 288 |
'slug': self.slug, |
289 |
- |