1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2018 by the Free Software Foundation, Inc.
4 # This file is part of Postorius.
6 # Postorius is free software: you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option)
11 # Postorius is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along with
17 # Postorius. If not, see <http://www.gnu.org/licenses/>.
21 from django
.contrib
.auth
.mixins
import LoginRequiredMixin
, UserPassesTestMixin
23 from postorius
.auth
.utils
import set_domain_access_props
, set_list_access_props
26 class ListOwnerMixin(LoginRequiredMixin
, UserPassesTestMixin
):
27 """Mixin to allow access to only List owners."""
30 user
= self
.request
.user
31 mlist_id
= self
.kwargs
['list_id']
34 set_list_access_props(user
, mlist_id
)
35 if user
.is_list_owner
:
40 class ListModeratorMixin(LoginRequiredMixin
, UserPassesTestMixin
):
41 """Mixin to allow access to only List Moderators."""
44 user
= self
.request
.user
45 mlist_id
= self
.kwargs
['list_id']
48 set_list_access_props(user
, mlist_id
)
49 if user
.is_list_owner
or user
.is_list_moderator
:
54 class DomainOwnerMixin(LoginRequiredMixin
, UserPassesTestMixin
):
55 """Mixin to allow access to only Domain Owner."""
58 user
= self
.request
.user
59 domain
= self
.kwargs
['domain']
62 set_domain_access_props(user
, domain
)
63 if user
.is_domain_owner
:
68 class SuperUserRequiredMixin(LoginRequiredMixin
, UserPassesTestMixin
):
69 """Mixin to allow access to only Django Superusers."""
72 if self
.request
.user
.is_superuser
: