Project

General

Profile

0004-attributes_ng-retrieve-both-static-and-session-roles.patch

Valentin Deniaud, 13 June 2019 10:41 AM

Download (2.77 KB)

View differences:

Subject: [PATCH] attributes_ng: retrieve both static and session roles
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Le parti pris ici c'est qu'on prend par défaut les rôles dynamiques. Ça
permet de ne rien changer dans hobo et d'avoir le comportement attendu
(les rôles dynamiques sont envoyés dans le SAML), mais à part ça c'est
pas forcément logique.
 .../attributes_ng/sources/django_user.py      | 27 ++++++++++++-------
 1 file changed, 18 insertions(+), 9 deletions(-)
src/authentic2/attributes_ng/sources/django_user.py
ctx['django_user_full_name'] = user.get_full_name()
Role = get_role_model()
user_auth_level = ctx['request'].session.get('auth_level', 1)
roles = Role.objects.for_user(user, max_auth_level=user_auth_level)
ctx['a2_role_slugs'] = roles.values_list('slug', flat=True)
ctx['a2_role_names'] = roles.values_list('name', flat=True)
ctx['a2_role_uuids'] = roles.values_list('uuid', flat=True)
if 'service' in ctx and getattr(ctx['service'], 'ou', None):
ou = ctx['service'].ou
ctx['a2_service_ou_role_slugs'] = roles.filter(ou=ou).values_list('slug', flat=True)
ctx['a2_service_ou_role_names'] = roles.filter(ou=ou).values_list('name', flat=True)
ctx['a2_service_ou_role_uuids'] = roles.filter(ou=ou).values_list('uuid', flat=True)
for role_type in ('session', 'static'):
if role_type == 'session':
prefix = 'a2_'
roles = Role.objects.for_user(user, max_auth_level=user_auth_level)
else:
prefix = 'a2_static_'
roles = Role.objects.for_user(user)
ctx[prefix + 'role_slugs'] = roles.values_list('slug', flat=True)
ctx[prefix + 'role_names'] = roles.values_list('name', flat=True)
ctx[prefix + 'role_uuids'] = roles.values_list('uuid', flat=True)
if 'service' in ctx and getattr(ctx['service'], 'ou', None):
ou = ctx['service'].ou
ctx[prefix + 'service_ou_role_slugs'] = \
roles.filter(ou=ou).values_list('slug', flat=True)
ctx[prefix + 'service_ou_role_names'] = \
roles.filter(ou=ou).values_list('name', flat=True)
ctx[prefix + 'service_ou_role_uuids'] = \
roles.filter(ou=ou).values_list('uuid', flat=True)
return ctx