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
22 from mygpo
.publisher
.models
import PublishedPodcast
25 def require_publisher(protected_view
):
26 @wraps(protected_view
)
27 def wrapper(request
, *args
, **kwargs
):
29 if not request
.user
.is_authenticated():
30 return HttpResponseRedirect('/login/')
32 if is_publisher(request
.user
):
33 return protected_view(request
, *args
, **kwargs
)
35 return HttpResponseRedirect('/')
40 def is_publisher(user
):
42 checks if the given user has publisher rights,
43 ie he is either set as the publisher of at least one podcast,
44 or he has the staff flag set
47 if not user
.is_authenticated():
53 if PublishedPodcast
.objects
.filter(publisher
=user
).exists():