In this commit, I added a new column which will be used for RDFa metadata of
[mediagoblin.git] / mediagoblin / app.py
index 1137c0d72fffd899af0adfe09193123aba034bc0..e65e6d1044958f992591e2411056fb14697c1dd8 100644 (file)
@@ -25,18 +25,21 @@ from werkzeug.exceptions import HTTPException
 from werkzeug.routing import RequestRedirect
 
 from mediagoblin import meddleware, __version__
+from mediagoblin.db.util import check_db_up_to_date
 from mediagoblin.tools import common, session, translate, template
 from mediagoblin.tools.response import render_http_exception
 from mediagoblin.tools.theme import register_themes
 from mediagoblin.tools import request as mg_request
+from mediagoblin.media_types.tools import media_type_warning
 from mediagoblin.mg_globals import setup_globals
 from mediagoblin.init.celery import setup_celery_from_config
 from mediagoblin.init.plugins import setup_plugins
 from mediagoblin.init import (get_jinja_loader, get_staticdirector,
     setup_global_and_app_config, setup_locales, setup_workbench, setup_database,
     setup_storage)
-from mediagoblin.tools.pluginapi import PluginManager
+from mediagoblin.tools.pluginapi import PluginManager, hook_transform
 from mediagoblin.tools.crypto import setup_crypto
+from mediagoblin.auth.tools import check_auth_enabled, no_auth_logout
 
 
 _log = logging.getLogger(__name__)
@@ -67,6 +70,8 @@ class MediaGoblinApp(object):
         # Open and setup the config
         global_config, app_config = setup_global_and_app_config(config_path)
 
+        media_type_warning()
+
         setup_crypto()
 
         ##########################################
@@ -85,7 +90,10 @@ class MediaGoblinApp(object):
         setup_plugins()
 
         # Set up the database
-        self.db = setup_database()
+        self.db = setup_database(app_config['run_migrations'])
+
+        # Quit app if need to run dbupdate
+        check_db_up_to_date()
 
         # Register themes
         self.theme_registry, self.current_theme = register_themes(app_config)
@@ -97,6 +105,11 @@ class MediaGoblinApp(object):
             PluginManager().get_template_paths()
             )
 
+        # Check if authentication plugin is enabled and respond accordingly.
+        self.auth = check_auth_enabled()
+        if not self.auth:
+            app_config['allow_comments'] = False
+
         # Set up storage systems
         self.public_store, self.queue_store = setup_storage()
 
@@ -186,8 +199,12 @@ class MediaGoblinApp(object):
 
         request.urlgen = build_proxy
 
+        # Log user out if authentication_disabled
+        no_auth_logout(request)
+
         mg_request.setup_user_in_request(request)
 
+        request.controller_name = None
         try:
             found_rule, url_values = map_adapter.match(return_rule=True)
             request.matchdict = url_values
@@ -201,6 +218,9 @@ class MediaGoblinApp(object):
                 exc.get_description(environ))(environ, start_response)
 
         controller = endpoint_to_controller(found_rule)
+        # Make a reference to the controller's symbolic name on the request...
+        # used for lazy context modification
+        request.controller_name = found_rule.endpoint
 
         # pass the request through our meddleware classes
         try:
@@ -227,7 +247,7 @@ class MediaGoblinApp(object):
             for m in self.meddleware[::-1]:
                 m.process_response(request, response)
         except HTTPException as e:
-            response = render_http_exeption(
+            response = render_http_exception(
                 request, e, e.get_description(environ))
 
         session_manager.save_session_to_cookie(request.session,
@@ -259,8 +279,6 @@ def paste_app_factory(global_config, **app_config):
         raise IOError("Usable mediagoblin config not found.")
 
     mgoblin_app = MediaGoblinApp(mediagoblin_config)
-
-    for callable_hook in PluginManager().get_hook_callables('wrap_wsgi'):
-        mgoblin_app = callable_hook(mgoblin_app)
+    mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app)
 
     return mgoblin_app