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('/')
38 def is_publisher(user
):
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
45 if not user
.is_authenticated():
51 if user
.published_objects
: