fix template for /share
[mygpo.git] / mygpo / publisher / auth.py
blob127bd79a3cfff16015e087b2b7e8db68ee6d7074
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 functools import wraps
20 from django.http import HttpResponseRedirect
23 def require_publisher(protected_view):
24 @wraps(protected_view)
25 def wrapper(request, *args, **kwargs):
27 if not request.user.is_authenticated():
28 return HttpResponseRedirect('/login/')
30 if is_publisher(request.user):
31 return protected_view(request, *args, **kwargs)
33 return HttpResponseRedirect('/')
35 return wrapper
38 def is_publisher(user):
39 """
40 checks if the given user has publisher rights,
41 ie he is either set as the publisher of at least one podcast,
42 or he has the staff flag set
43 """
45 if not user.is_authenticated():
46 return False
48 if user.is_staff:
49 return True
51 if user.published_objects:
52 return True
54 return False