~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/rpc/decorators.py

  • Committer: William Grant
  • Date: 2010-02-16 04:11:46 UTC
  • Revision ID: grantw@unimelb.edu.au-20100216041146-rvfbuwin7fncc0nw
Restrict privileges on group-related userservice actions to users with admin_groups on the offering.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
            raise Unauthorized()
26
26
       func(req, *args, **kwargs)
27
27
    return admin_or_die
28
 
 
29
 
class require_role_anywhere(object):
30
 
    '''Require that the logged in user has a role in any offering.'''
31
 
    def __init__(self, *roles):
32
 
        self.roles = roles
33
 
 
34
 
    def __call__(self, func):
35
 
        def role_or_die(req, *args, **kwargs):
36
 
            if not req.user:
37
 
                raise Unauthorized()
38
 
 
39
 
            if req.user.admin:
40
 
                return func(req, *args, **kwargs)
41
 
 
42
 
            roles = set((e.role for e in req.user.active_enrolments))
43
 
 
44
 
            for role in self.roles:
45
 
                if role in roles:
46
 
                    return func(req, *args, **kwargs)
47
 
            raise Unauthorized()
48
 
        return role_or_die