Skip to content

Commit 4538ef7

Browse files
committed
Added Nomcom role suport to role_required() through has_role(). This will let us get rid of the more specialized ad_hoc nomcom_memeber_required() which can't handle access for multiple roles.
- Legacy-Id: 6155
1 parent 71f85f9 commit 4538ef7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

ietf/ietfauth/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def user_is_person(user, person):
2020

2121
return person.user_id == user.id
2222

23-
def has_role(user, role_names):
23+
def has_role(user, role_names, *args, **kwargs):
2424
"""Determines whether user has any of the given standard roles
2525
given. Role names must be a list or, in case of a single value, a
2626
string."""
@@ -53,6 +53,9 @@ def has_role(user, role_names):
5353
"WG Secretary": Q(person=person,name="secr", group__type="wg", group__state="active"),
5454
"RG Chair": Q(person=person,name="chair", group__type="rg", group__state="active"),
5555
"RG Secretary": Q(person=person,name="secr", group__type="rg", group__state="active"),
56+
"Nomcom Chair": Q(person=person, name="chair", group__type="nomcom", group__state="active", group__acronym__icontains=kwargs.get('year', '0000')),
57+
"Nomcom Advisor": Q(person=person, name="advisor", group__type="nomcom", group__state="active", group__acronym__icontains=kwargs.get('year', '0000')),
58+
"Nomcom": Q(person=person, group__type="nomcom", group__state="active", group__acronym__icontains=kwargs.get('year', '0000')),
5659
}
5760

5861
filter_expr = Q()
@@ -85,7 +88,7 @@ def inner(request, *args, **kwargs):
8588
def role_required(*role_names):
8689
"""View decorator for checking that the user is logged in and
8790
has one of the listed roles."""
88-
return passes_test_decorator(lambda u, *args, **kwargs: has_role(u, role_names),
91+
return passes_test_decorator(lambda u, *args, **kwargs: has_role(u, role_names, *args, **kwargs),
8992
"Restricted to role%s %s" % ("s" if len(role_names) != 1 else "", ", ".join(role_names)))
9093

9194
# specific permissions

0 commit comments

Comments
 (0)