From e2c2c79fc3534e1eb17217a3375e4e5bfa6b5dfc Mon Sep 17 00:00:00 2001 From: Josh Mize Date: Tue, 9 Sep 2014 02:08:38 -0500 Subject: [PATCH] Enable admin: fix bug 1044184 Add admin staticfiles Add rna dependencies and ConditionalAuthMiddleware Add/update rna, django-pagedown Add ConditionalAuthMiddleware, rna url Add django-filter and settings.REST_FRAMEWORK Add collectstatic to update_assets Remove ctx param from base_update_assets Clear *.pyc during deploy and move collectstatic Add rna and api-token-auth PT --- .gitmodules | 6 ++++ bedrock/mozorg/middleware.py | 10 +++++++ bedrock/settings/base.py | 47 ++++++++++++++++++++++++++++---- bedrock/urls.py | 12 ++++---- bin/update/deploy_base.py | 2 ++ etc/httpd/global.conf | 4 +++ static/.gitignore | 4 +++ vendor-local/src/django-filter | 1 + vendor-local/src/django-pagedown | 1 + vendor-local/src/rna | 2 +- vendor-local/vendor.pth | 16 ++++++----- 11 files changed, 84 insertions(+), 21 deletions(-) create mode 100644 static/.gitignore create mode 160000 vendor-local/src/django-filter create mode 160000 vendor-local/src/django-pagedown diff --git a/.gitmodules b/.gitmodules index b080ff3e4e..1670db3e54 100644 --- a/.gitmodules +++ b/.gitmodules @@ -55,3 +55,9 @@ [submodule "vendor-local/src/chkcrontab"] path = vendor-local/src/chkcrontab url = git://github.com/lyda/chkcrontab.git +[submodule "vendor-local/src/django-pagedown"] + path = vendor-local/src/django-pagedown + url = https://github.com/timmyomahony/django-pagedown.git +[submodule "vendor-local/src/django-filter"] + path = vendor-local/src/django-filter + url = https://github.com/alex/django-filter.git diff --git a/bedrock/mozorg/middleware.py b/bedrock/mozorg/middleware.py index 3b3fbb4c15..4d6f61edb6 100644 --- a/bedrock/mozorg/middleware.py +++ b/bedrock/mozorg/middleware.py @@ -6,9 +6,19 @@ import datetime from email.utils import formatdate import time +from django.conf import settings +from django.contrib.auth.middleware import AuthenticationMiddleware + from django_statsd.middleware import GraphiteRequestTimingMiddleware +class ConditionalAuthMiddleware(object): + def process_request(self, request): + if any(request.path.startswith(prefix) + for prefix in settings.AUTHENTICATED_URL_PREFIXES): + AuthenticationMiddleware().process_request(request) + + class CacheMiddleware(object): def process_response(self, request, response): diff --git a/bedrock/settings/base.py b/bedrock/settings/base.py index 6544585cc8..b30b93d6e1 100644 --- a/bedrock/settings/base.py +++ b/bedrock/settings/base.py @@ -63,12 +63,14 @@ DOTLANG_FILES = ['main', 'download_button', 'newsletter'] # matches the first url component (e.g. mozilla.org/gameon/) SUPPORTED_NONLOCALES += [ # from redirects.urls + 'admin', + 'contribute.json', + 'credits', + 'gameon', + 'rna', + 'robots.txt', 'telemetry', 'webmaker', - 'gameon', - 'robots.txt', - 'credits', - 'contribute.json', ] ALLOWED_HOSTS = [ @@ -102,7 +104,12 @@ def JINJA_CONFIG(): 'auto_reload': True, } +STATIC_URL = '/static/' +STATIC_ROOT = path('static') + JINGO_MINIFY_USE_STATIC = False +JINGO_EXCLUDE_APPS = ( + 'admin', 'registration', 'rest_framework', 'rna', 'waffle') CACHEBUST_IMGS = False # Bundles is a dictionary of two dictionaries, css and js, which list css files @@ -1049,24 +1056,29 @@ MIDDLEWARE_CLASSES = ( 'bedrock.mozorg.middleware.CacheMiddleware', 'dnt.middleware.DoNotTrackMiddleware', 'lib.l10n_utils.middleware.FixLangFileTranslationsMiddleware', + 'bedrock.mozorg.middleware.ConditionalAuthMiddleware', )) +AUTHENTICATED_URL_PREFIXES = ('/admin/', '/rna/') + INSTALLED_APPS = get_apps(exclude=( 'compressor', 'django_browserid', 'django.contrib.sessions', - 'django.contrib.staticfiles', 'session_csrf', 'djcelery', ), append=( - # Local apps + # third-party apps 'jingo_markdown', 'jingo_minify', 'django_statsd', + 'pagedown', + 'rest_framework', 'waffle', 'south', # Django contrib apps + 'django.contrib.admin', 'django_sha2', # Load after auth to monkey-patch it. 'django.contrib.contenttypes', 'django.contrib.messages', @@ -1102,6 +1114,8 @@ INSTALLED_APPS = get_apps(exclude=( 'rna', )) +SESSION_ENGINE = 'django.contrib.sessions.backends.cache' + LOCALE_PATHS = ( path('locale'), ) @@ -1426,3 +1440,24 @@ LOGGING = { }, }, } + +PASSWORD_HASHERS = ['django.contrib.auth.hashers.PBKDF2PasswordHasher'] + +REST_FRAMEWORK = { + # Use hyperlinked styles by default. + # Only used if the `serializer_class` attribute is not set on a view. + 'DEFAULT_MODEL_SERIALIZER_CLASS': + 'rna.serializers.HyperlinkedModelSerializerWithPkField', + + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly', + ), + + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.SessionAuthentication', + ), + + 'DEFAULT_FILTER_BACKENDS': ('rna.filters.TimestampedFilterBackend',) +} diff --git a/bedrock/urls.py b/bedrock/urls.py index af032d01a7..ff003dc3be 100644 --- a/bedrock/urls.py +++ b/bedrock/urls.py @@ -4,15 +4,13 @@ from django.conf import settings from django.conf.urls import handler404, include, patterns +from django.contrib import admin from funfactory.monkeypatches import patch patch() - -# Uncomment the next two lines to enable the admin: -# from django.contrib import admin -# admin.autodiscover() +admin.autodiscover() # The default django 500 handler doesn't run the ContextProcessors, which breaks # the base template page. So we replace it with one that does! @@ -21,6 +19,9 @@ handler500 = 'lib.bedrock_util.server_error_view' urlpatterns = patterns( '', + # authenticated urls + (r'^admin/', include(admin.site.urls)), + (r'^rna/', include('rna.urls')), # Main pages (r'^lightbeam/', include('bedrock.lightbeam.urls')), (r'^foundation/', include('bedrock.foundation.urls')), @@ -52,9 +53,6 @@ urlpatterns = patterns( # Uncomment the admin/doc line below to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - # (r'^admin/', include(admin.site.urls)), ) # In DEBUG mode, serve media files through Django. diff --git a/bin/update/deploy_base.py b/bin/update/deploy_base.py index e0b8f78d62..fe3969857f 100644 --- a/bin/update/deploy_base.py +++ b/bin/update/deploy_base.py @@ -39,6 +39,7 @@ def update_code(ctx, tag): ctx.local("git checkout -f %s" % tag) ctx.local("git submodule sync") ctx.local("git submodule update --init --recursive") + ctx.local("find . -name '*.pyc' -delete") @task @@ -52,6 +53,7 @@ def update_assets(ctx): management_cmd(ctx, 'compress_assets') management_cmd(ctx, 'update_product_details') management_cmd(ctx, 'update_externalfiles') + management_cmd(ctx, 'collectstatic --noinput') @task diff --git a/etc/httpd/global.conf b/etc/httpd/global.conf index 1f1264c463..efc78e7730 100644 --- a/etc/httpd/global.conf +++ b/etc/httpd/global.conf @@ -135,6 +135,10 @@ RewriteRule ^/ja/firefox/organizations/?$ http://www.mozilla.jp/business/downloa ## Redirect things to django! +# bug 1044184 +RewriteRule ^/admin(/.*)?$ /b/admin$1 [PT] +RewriteRule ^/rna(/.*)?$ /b/rna$1 [PT] + # bug 797192, 892470 RewriteRule ^/(\w{2,3}(?:-\w{2})?/)?plugincheck(/?)$ /b/$1/plugincheck$2 [PT] diff --git a/static/.gitignore b/static/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/static/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/vendor-local/src/django-filter b/vendor-local/src/django-filter new file mode 160000 index 0000000000..e58e15ebf2 --- /dev/null +++ b/vendor-local/src/django-filter @@ -0,0 +1 @@ +Subproject commit e58e15ebf27e90cc0d47b7e58a2181e9150c49ab diff --git a/vendor-local/src/django-pagedown b/vendor-local/src/django-pagedown new file mode 160000 index 0000000000..78556863fa --- /dev/null +++ b/vendor-local/src/django-pagedown @@ -0,0 +1 @@ +Subproject commit 78556863faa5654f749c5562b390317c6cad10b3 diff --git a/vendor-local/src/rna b/vendor-local/src/rna index 3122af9692..47771c3aed 160000 --- a/vendor-local/src/rna +++ b/vendor-local/src/rna @@ -1 +1 @@ -Subproject commit 3122af9692d93e720ff4f2cdffdd341869756840 +Subproject commit 47771c3aed24ff2c284b7fee83fe7dbc2cbb6b6a diff --git a/vendor-local/vendor.pth b/vendor-local/vendor.pth index a972c2d91f..1f41e0ff0c 100644 --- a/vendor-local/vendor.pth +++ b/vendor-local/vendor.pth @@ -3,23 +3,25 @@ packages/certifi packages/chardet packages/python-memcached packages/pytz -src/basket-client packages/PyYAML/lib -src/feedparser/feedparser +src/basket-client +src/chkcrontab +src/django-dnt src/django-extensions +src/django-filter +src/django-pagedown src/django-recaptcha src/django-rest-framework -src/django-dnt src/django-statsd src/django-waffle +src/feedparser/feedparser +src/icalendar/src src/jingo-markdown +src/legal-docs +src/mdx_outline src/pystatsd src/Python-Markdown src/requests src/rna src/six src/tweepy -src/mdx_outline -src/legal-docs -src/icalendar/src -src/chkcrontab