If MINIGROUP_DIGESTIF_USERPASS isn't set, minigroup checkbox is hidden.

The minigroup routes are also not installed.

However, this functionality is still enabled for testing, so that
tests can be run against the routes.
This commit is contained in:
Atul Varma 2014-05-08 04:45:06 -04:00
Родитель 26ed309302
Коммит 38aac5ad2b
6 изменённых файлов: 18 добавлений и 17 удалений

Просмотреть файл

@ -59,7 +59,8 @@ variables are given default values: `SECRET_KEY`, `PORT`, `ORIGIN`,
* `ADMIN_EMAIL` is the email address to send error reports to. If
undefined, error reports will not be emailed.
* `MINIGROUP_DIGESTIF_USERPASS` is a string of the form `username:password`
that enables the sending of Minigroup digests from external jobs. For
that enables the sending of Minigroup digests from external jobs. If
empty or undefined, minigroup digest functionality will be disabled. For
more information, see [minigroup_digestif/README.md][].
* `SECURE_PROXY_SSL_HEADER` is an optional HTTP request header field name
and value indicating that the request is actually secure. For example,

Просмотреть файл

@ -1,3 +1,4 @@
from django.conf import settings
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from django.contrib.auth.models import User
@ -31,8 +32,10 @@ class ChannelFormSetHelper(FormHelper):
class MembershipForm(ModelForm):
class Meta:
model = Membership
fields = ['title', 'bio', 'twitter_name', 'phone_number', 'is_listed',
'receives_minigroup_digest']
fields = ['title', 'bio', 'twitter_name', 'phone_number',
'is_listed']
if 'minigroup_digestif' in settings.INSTALLED_APPS:
fields.append('receives_minigroup_digest')
labels = {
'receives_minigroup_digest': 'Send me a daily digest of all '
'activity on the Hive minigroup.',

Просмотреть файл

@ -75,9 +75,11 @@ INSTALLED_APPS = (
'crispy_forms',
'registration',
'directory',
'minigroup_digestif',
) + EMAIL_BACKEND_INSTALLED_APPS
if MINIGROUP_DIGESTIF_USERPASS or is_running_test_suite():
INSTALLED_APPS += ('minigroup_digestif',)
MIDDLEWARE_CLASSES = (
'hive.ssl.RedirectToHttpsMiddleware',
'hive.ssl.HstsMiddleware',

Просмотреть файл

@ -1,3 +1,4 @@
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib import admin
@ -11,6 +12,10 @@ urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('hive.account_urls')),
url(r'^minigroup_digestif/', include('minigroup_digestif.urls')),
url(r'', include('directory.urls')),
)
if 'minigroup_digestif' in settings.INSTALLED_APPS:
urlpatterns += patterns('',
url(r'^minigroup_digestif/', include('minigroup_digestif.urls')),
)

Просмотреть файл

@ -8,19 +8,12 @@ from directory.models import Membership
def userpass(string):
return 'Basic %s' % (string.encode('base64'))
class BaseTestCase(TestCase):
@override_settings(MINIGROUP_DIGESTIF_USERPASS='user:pass')
class EndpointTests(TestCase):
def setUp(self):
TestCase.setUp(self)
self.client = Client(enforce_csrf_checks=True)
@override_settings(MINIGROUP_DIGESTIF_USERPASS='')
class DisabledEndpointTests(BaseTestCase):
def test_return_not_implemented_if_unconfigured(self):
response = self.client.post('/minigroup_digestif/send')
self.assertEqual(response.status_code, 501)
@override_settings(MINIGROUP_DIGESTIF_USERPASS='user:pass')
class EnabledEndpointTests(BaseTestCase):
def test_no_authorization_header_returns_401(self):
response = self.client.post('/minigroup_digestif/send')
self.assertEqual(response.status_code, 401)

Просмотреть файл

@ -38,9 +38,6 @@ def send_digest(request):
@csrf_exempt
@require_POST
def send(request):
if (not hasattr(settings, 'MINIGROUP_DIGESTIF_USERPASS') or
not settings.MINIGROUP_DIGESTIF_USERPASS):
return HttpResponse(status=501, reason='Not Implemented')
if request.META.has_key('HTTP_AUTHORIZATION'):
try:
authmeth, auth = request.META['HTTP_AUTHORIZATION'].split(' ', 1)