diff options
author | Stephen Finucane <stephen@that.guru> | 2017-02-26 23:57:22 +0000 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2017-03-20 19:14:55 +0000 |
commit | 0b4f508a84389fd2b3a9c2a5cfc2128468f2c600 (patch) | |
tree | bbc4ebdd2ec0de892823b1469a4f229135d4f6e9 | |
parent | d1c605f9cb11f8c0f76a91217b73382ebf590d93 (diff) | |
download | patchwork-0b4f508a84389fd2b3a9c2a5cfc2128468f2c600.tar patchwork-0b4f508a84389fd2b3a9c2a5cfc2128468f2c600.tar.gz |
views: Allow use of basic auth for bundle mboxes
API clients are going to talk using basic auth. We also need to do this
for bundles. The alternative is to provide another endpoint for bundles
in the API but that seems unnecessary.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
-rw-r--r-- | patchwork/views/bundle.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index e717429..95c44ae 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -19,6 +19,7 @@ from __future__ import absolute_import +from django.conf import settings from django.contrib.auth.decorators import login_required import django.core.urlresolvers from django.http import (HttpResponse, HttpResponseRedirect, @@ -30,6 +31,12 @@ from patchwork.forms import BundleForm, DeleteBundleForm from patchwork.models import Patch, Bundle, BundlePatch, Project from patchwork.views import generic_list, patch_to_mbox, get_patch_ids +if settings.ENABLE_REST_API: + from rest_framework.authentication import BasicAuthentication # noqa + basic_auth = BasicAuthentication() +else: + basic_auth = None + @login_required def setbundle(request): @@ -193,7 +200,8 @@ def mbox(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username=username, name=bundlename) - if not (request.user == bundle.owner or bundle.public): + if not (request.user == bundle.owner or bundle.public or + (basic_auth and basic_auth.authenticate(request))): return HttpResponseNotFound() mbox = '\n'.join([patch_to_mbox(p).as_string(True) |