from mediagoblin.tools.routing import endpoint_to_controller
from werkzeug.wrappers import Request
-from werkzeug.exceptions import HTTPException, NotFound
+from werkzeug.exceptions import HTTPException
+from werkzeug.routing import RequestRedirect
from mediagoblin import meddleware, __version__
-from mediagoblin.tools import common, translate, template
+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, setup_beaker_cache)
-from mediagoblin.tools.pluginapi import PluginManager
+ setup_storage)
+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__)
# Open and setup the config
global_config, app_config = setup_global_and_app_config(config_path)
+ media_type_warning()
+
+ setup_crypto()
+
##########################################
# Setup other connections / useful objects
##########################################
+ # Setup Session Manager, not needed in celery
+ self.session_manager = session.SessionManager()
+
# load all available locales
setup_locales()
setup_plugins()
# Set up the database
- self.connection, 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)
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()
# set up staticdirector tool
self.staticdirector = get_staticdirector(app_config)
- # set up caching
- self.cache = setup_beaker_cache()
-
# Setup celery, if appropriate
if setup_celery and not app_config.get('celery_setup_elsewhere'):
if os.environ.get('CELERY_ALWAYS_EAGER', 'false').lower() == 'true':
## Attach utilities to the request object
# Do we really want to load this via middleware? Maybe?
- request.session = request.environ['beaker.session']
+ session_manager = self.session_manager
+ request.session = session_manager.load_session_from_cookie(request)
# Attach self as request.app
# Also attach a few utilities from request.app for convenience?
request.app = self
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:
- endpoint, url_values = map_adapter.match()
+ found_rule, url_values = map_adapter.match(return_rule=True)
request.matchdict = url_values
+ except RequestRedirect as response:
+ # Deal with 301 responses eg due to missing final slash
+ return response(environ, start_response)
except HTTPException as exc:
# Stop and render exception
return render_http_exception(
request, exc,
exc.get_description(environ))(environ, start_response)
- controller = endpoint_to_controller(endpoint)
+ 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:
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,
+ request, response)
+
return response(environ, start_response)
def __call__(self, environ, start_response):
raise IOError("Usable mediagoblin config not found.")
mgoblin_app = MediaGoblinApp(mediagoblin_config)
+ mgoblin_app = hook_transform('wrap_wsgi', mgoblin_app)
return mgoblin_app