Projet

Général

Profil

0001-templatetags-introduce-has_role_uuid-64495.patch

Frédéric Péters, 12 août 2022 14:34

Télécharger (2,59 ko)

Voir les différences:

Subject: [PATCH] templatetags: introduce |has_role_uuid (#64495)

 debian/debian_config_common.py |  4 +---
 hobo/context_processors.py     |  2 +-
 hobo/templatetags/hobo.py      | 12 ++++++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
debian/debian_config_common.py
359 359
    if 'authentic2' not in INSTALLED_APPS:
360 360
        MELLON_ADAPTER = ('hobo.multitenant.mellon.MellonAdapter',)
361 361

  
362
if PROJECT_NAME in ('wcs', 'combo'):
363
    TEMPLATES[0]['OPTIONS'].setdefault('builtins', []).append('hobo.templatetags.hobo')
364

  
362
TEMPLATES[0]['OPTIONS'].setdefault('builtins', []).append('hobo.templatetags.hobo')
365 363

  
366 364
if 'authentic2' not in INSTALLED_APPS:
367 365
    MELLON_DEFAULT_ASSERTION_CONSUMER_BINDING = 'artifact'
hobo/context_processors.py
144 144
    # * theme_base will get evaluated when encountered in a template and return
145 145
    #   a template string downloaded from settings.THEME_SKELETON_URL.
146 146
    #
147
    # * theme_404 is identical but dedicated to 404 erorr pages.
147
    # * theme_404 is identical but dedicated to 404 error pages.
148 148
    #
149 149
    #   Both those variables are to be used by "slave" sites, authentic,
150 150
    #   w.c.s., etc.
hobo/templatetags/hobo.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import decimal
18
import sys
18 19

  
19 20
from django import template
20 21
from django.utils.translation import get_language
......
59 60
        return num2words(unlazy(number), lang=get_language(), to='currency')
60 61
    except (TypeError, ValueError, decimal.InvalidOperation):
61 62
        return ''
63

  
64

  
65
@register.filter
66
def has_role_uuid(user, role_uuid):
67
    if not user or not user.is_authenticated:
68
        return False
69
    if 'authentic2' in sys.modules:
70
        return user.roles.filter(uuid=role_uuid).exists()
71
    elif 'wcs' in sys.modules:
72
        return role_uuid in user.roles
73
    return user.groups.filter(role__uuid=role_uuid).exists()
62
-