remove unnecessary imports
[mygpo.git] / mygpo / publisher / auth.py
blob43316c95a5235cdac02a282512a7e746b00a2f2c
2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
18 from django.http import HttpResponseRedirect
19 from mygpo.publisher.models import PodcastPublisher
22 def require_publisher(protected_view):
23 def wrapper(request, *args, **kwargs):
25 if not request.user.is_authenticated():
26 return HttpResponseRedirect('/login/')
28 if is_publisher(request.user):
29 return protected_view(request, *args, **kwargs)
31 return HttpResponseRedirect('/')
33 return wrapper
36 def is_publisher(user):
37 """
38 checks if the given user has publisher rights,
39 ie he is either set as the publisher of at least one podcast,
40 or he has the staff flag set
41 """
43 if not user.is_authenticated():
44 return False
46 if user.is_staff:
47 return True
49 if PodcastPublisher.objects.filter(user=user).count() > 0:
50 return True
52 return False