18
18
func(req, *args, **kwargs)
19
19
return method_or_die
21
class require_cap(object):
22
'''Require that the logged in user has the specified capability.'''
23
def __init__(self, cap):
21
def require_admin(func):
22
'''Require that the logged in user is an admin.'''
23
def admin_or_die(req, *args, **kwargs):
24
if not req.user or not req.user.admin:
26
func(req, *args, **kwargs)
29
class require_role_anywhere(object):
30
'''Require that the logged in user has a role in any offering.'''
31
def __init__(self, *roles):
26
34
def __call__(self, func):
27
def cap_or_die(req, *args, **kwargs):
28
if not req.user or not req.user.hasCap(self.cap):
35
def role_or_die(req, *args, **kwargs):
29
37
raise Unauthorized()
30
func(req, *args, **kwargs)
40
return func(req, *args, **kwargs)
42
roles = set((e.role for e in req.user.active_enrolments))
44
for role in self.roles:
46
return func(req, *args, **kwargs)