~coolyashish/postorius/add_email_address_in_settings

« back to all changes in this revision

Viewing changes to src/postorius/auth/decorators.py

  • Committer: Florian Fuchs
  • Date: 2015-01-19 15:03:09 UTC
  • mfrom: (188.4.2 postorius)
  • Revision ID: flo.fuchs@gmail.com-20150119150309-lcdx9ztq29ejj0ze
* URLs now contains the list-id instead of the fqdn_listname. Contributed by Abhilash Raj (LP: 1201150).
* Added dev_requirements.txt for installation of development dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    """
52
52
    def wrapper(*args, **kwargs):
53
53
        user = args[0].user
54
 
        fqdn_listname = kwargs['fqdn_listname']
 
54
        list_id = kwargs['list_id']
55
55
        if not user.is_authenticated():
56
56
            raise PermissionDenied
57
57
        if user.is_superuser:
58
58
            return fn(*args, **kwargs)
59
59
        if getattr(user, 'is_list_owner', None):
60
60
            return fn(*args, **kwargs)
61
 
        mlist = List.objects.get_or_404(fqdn_listname=fqdn_listname)
 
61
        mlist = List.objects.get_or_404(fqdn_listname=list_id)
62
62
        if user.email not in mlist.owners:
63
63
            raise PermissionDenied
64
64
        else:
69
69
 
70
70
def list_moderator_required(fn):
71
71
    """Check if the logged in user is a moderator of the given list.
72
 
    Assumes that the request object is the first arg and that fqdn_listname
 
72
    Assumes that the request object is the first arg and that list_id
73
73
    is present in kwargs.
74
74
    """
75
75
    def wrapper(*args, **kwargs):
76
76
        user = args[0].user
77
 
        fqdn_listname = kwargs['fqdn_listname']
 
77
        list_id = kwargs['list_id']
78
78
        if not user.is_authenticated():
79
79
            raise PermissionDenied
80
80
        if user.is_superuser:
83
83
            return fn(*args, **kwargs)
84
84
        if getattr(user, 'is_list_moderator', None):
85
85
            return fn(*args, **kwargs)
86
 
        mlist = List.objects.get_or_404(fqdn_listname=fqdn_listname)
 
86
        mlist = List.objects.get_or_404(fqdn_listname=list_id)
87
87
        if user.email not in mlist.moderators and \
88
88
                user.email not in mlist.owners:
89
89
            raise PermissionDenied