Project

General

Profile

0001-attributes_ng-limit-roles-depending-on-authenticatio.patch

Valentin Deniaud, 05 June 2019 02:30 PM

Download (2.07 KB)

View differences:

Subject: [PATCH 1/3] attributes_ng: limit roles depending on authentication
 level

This has the effect of seeing only roles currently available to the user
when getting user SAML attributes, and setting service role attributes
accordingly.
 src/authentic2/attributes_ng/sources/django_user.py   | 3 ++-
 src/authentic2/attributes_ng/sources/service_roles.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
src/authentic2/attributes_ng/sources/django_user.py
ctx['django_user_identifier'] = splitted[0]
ctx['django_user_full_name'] = user.get_full_name()
Role = get_role_model()
roles = Role.objects.for_user(user)
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)
src/authentic2/attributes_ng/sources/service_roles.py
if not user or not service:
return ctx
ctx = ctx.copy()
roles = Role.objects.for_user(user) \
user_auth_level = ctx['request'].session.get('auth_level', 1)
roles = Role.objects.for_user(user, max_auth_level=user_auth_level) \
.filter(service=service) \
.prefetch_related('attributes')
for service_role in roles: