117 Commits

Author SHA1 Message Date
Christopher Allan Webber
f7a5c7c78c Fully working context hooks, both template/view and global level, with tests
Needs documentation though... that's coming next :)

This commit sponsored by Luca Tius.  Thanks Luca!
2013-05-14 14:24:27 -05:00
Christopher Allan Webber
98dacfe67e Use the controller's symbolic/lookup name as part of the key for context hooks
This commit sponsored by David Collins.  Thank you!
2013-05-10 20:26:55 -05:00
Christopher Allan Webber
3810309443 The beginning of context hooks.
Not the working solution, but getting there conceptually.  Basically
we'll have a key with the view and the template as a tuple which is
the context hook that anyone can attach to.

However, some changes have still to be made:
 - The unit test doesn't work yet and contains a set_trace ;)
 - We'll probably switch the "view" component from being the callable
   to the "urlgen"'able name per Elrond's suggestion
 - Found a bug in unit tests related to running custom apps for
   different configs... hm.  I need to fix this!

Nonetheless, making progress.

This commit sponsored by... wait a minute... Christopher Webber?!
2013-05-08 14:35:31 -05:00
Christopher Allan Webber
c5d8d30182 removing old callable utilities and porting stuff over. 2013-04-19 16:51:14 -05:00
Christopher Allan Webber
6a28bc4e87 Fixing typo in calling render_http_exception 2013-04-17 10:03:33 -05:00
Elrond
b0ee3aae91 Make session cookies more secure.
1. Our session cookies only need to be available to http, so
   mark them appropiately.

2. Send the cookie to the subpath for mediagoblin.

And instantiate a session manager on the app, once.
2013-04-09 22:49:11 +02:00
Brett Smith
9e1fa2396f Remove beaker stuff from the code.
This is all obsoleted by It's Dangerous.
2013-03-24 15:10:08 -04:00
Brett Smith
c7424612d7 Back sessions with It's Dangerous.
This is a contribution to #668.
2013-03-24 14:44:41 -04:00
Elrond
5907154a59 Basic itsdangerous infrastructure.
Implement the basic infrastructure for using itsdangerous
in mediagoblin. Usage instructions will follow.
2013-03-22 18:46:47 +01:00
Joar Wandborg
f3f530286f Updated raven plugin
- Added wrap_wsgi, celery_setup, celery_logging_setup hooks
- Updated raven plugin docs
- Updated production considerations docs
- Added raven logging setup
2013-03-03 02:32:03 +01:00
András Veres-Szentkirályi
e5e2c5e7aa removed unused import NotFound 2013-02-22 22:24:29 +01:00
Sebastian Spaeth
fd61aac7c7 Unbreak 301 responses
The move to werkzeug routing went pretty smooth, but one thing was
broken by accident: URLs without final slash result in a 301
werkzeug.routing.RequestRedirect response. We displayed it as a generic
error page rather than actually sending the redirect. Do that. One thing
it does though is to skip all meddlewares, which should be OK for a 301
response, but might need rework if we decide otherwise. With this, 301
responses with lacking final slash are unbroken again.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 16:52:22 +01:00
Sebastian Spaeth
bc142abc55 RIP out mongo
Since sqlalchemy is providing our database abstraction and we have
moved away from Mongo as the underlying database, it is now time to
simplify things and rip out mongo. This provides the bulk of the
changes, and can stand on its own. There are some followup tasks
that can be done, such as removing now unneeded abstraction layers,
e.g. db.sql.fake.py
2012-12-25 20:06:03 +01:00
Elrond
05501c5742 Rewrite routing using new MGRoute class
MGRoute subclasses Rule():
Rule doesn't have a way to tag extra data, like the
controller function, we need. So MGRoute has a new
attribute .gmg_controller, which holds this.

Rewrite everything to use this new Rule variant and drop
all the other stuff that mapped endpoints to controller
functions, mostly.
2012-12-23 12:26:34 +01:00
Elrond
3d91433230 Move things from routing.py to tools/routing.py
This stops a cyclic import.

Move add_route, mount and endpoint_to_controller into
tools/routing.py and change all callers.
2012-12-23 12:26:34 +01:00
Elrond
48cf435d71 Refactor routing in app.py.
Move some things out of app.py into functions in
routing.py. This makes app.py a bit more readable and
allows us to rewrite routing.
2012-12-23 12:26:34 +01:00
Sebastian Spaeth
785b287fcb Provide tools.response.render_http_exception and use that
After the webob->werkzeug transition, controller functions can raise
werkzeug.HttpExceptions. We need to catch these in app.py when calling
the controller and handle them, rendering the corresponding error Response()
object. For consistency, we also want to allow meddleware functions to
raise HttpExceptions (e.g. the csrf meddleware needs to complain about lack
of cookies), so wrap the request and response parts of the meddleware too.

Finally, the urlmap.match() can also raise HttpExceptions, so we give it the
same treatment (render_http_exception). I am not sure, if we do not need to
handle the Redirect exception there in any different way though...

The new function render_http_exception makes use of the render_error infrastructure
to return a nicely templated error page. It also checks if the stock error
messages was used in cases where we have localizations (403, 404) and use those.

It is now possible to do things like "raise Forbidden(_('You suckr'))" or
raise NotFound(_('where is my left show again')) if you want to return
customized error messages to the user.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-23 11:57:45 +01:00
Sebastian Spaeth
573b4305cd Don't dbug log every added plugin route
It is killing testsuite output by drowning out all signals. It should
be sufficient to state in the pluginmanager that routes have been added,
if we need that kind of output.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:59:37 +01:00
Sebastian Spaeth
726896b62a Remove webob compatability
Remove the aliases we provided for webob compatability as webob is
now gone. Grepped the code base to check for occurences of the old
parameters to be safe. Keep request.GET attribute as alias for
request.args as it is often used and django is also using that
attribute.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:12:25 +01:00
Sebastian Spaeth
b745bb50d8 Remove webob from render_to_response
We were still using webob's Response objects for template rendering.
Transition to werkzeug's Response object. One caveat was that it
seemed to have used the default mimetype "text/plain" for all pages,
so we override the default Response class, setting the default mime
type to "text/html".

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:10:48 +01:00
Sebastian Spaeth
6ef75af50e Honor user's browser language (#558)
Previously we would attempt to satisfy the user's first language
preference, immediately falling back to english if that was not
possible. Now, we will get the best match of the user's preferred
languages.

This requires storing the available locales on app startup, so we
have mg_globals.available_locales ready to compare them against the
list of preferred user languages.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-02 00:29:30 +01:00
Sebastian Spaeth
7b9f9d1edb Fix i18n in our browser
We only ever served english pages since the switch to werkzeug's requests.
Fix this by actually checking the accepted languages that our web browser
sends and using that or falling back to english.

This is not optimal, imaging our browser sends "klingon, de" as accepted
languages and we happen to not have a klingon translation ready (a deficiency
that should be corrected immediately anyway!!). We would then fall back
to english rather than sending the sensible and pleasant German language
which the user would understand. This will require more backend work though.

Removing the gettext.find() in mg_globals.py. It looked in the wrong directory
anyway (mediagoblin/translations) and as that does not exist, had always returned
None without anyone noticing.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-01 23:40:10 +01:00
Joar Wandborg
d56e82635f Fixed OAuth access_token duplicate route
Changed route name to "[...]list_connections"
2012-10-15 22:59:53 +02:00
Joar Wandborg
1ec7ff2adb Fixed 404 page under werkzeug.routing
- Removed ?lang=<langcode> feature due to incompatibility with werkzeug
  routes in the current state of the architecture.
2012-10-14 20:05:44 +02:00
Joar Wandborg
7742dcc1fb Switched most stuff over from Routes
Removed the Routes routing functionality and replaced it with
werkzeug.routes. Most views are functional.

Known issues:

 - Translation integration with the request object is not yet figured
   out. This breaks 404 pages.
2012-10-14 13:46:31 +02:00
Joar Wandborg
111a609df5 Replaced all request.POST with request.form, ...
- Fixed error handling in OAuth plugin
- Changed request.POST file fields to request.files
2012-09-29 21:08:20 +02:00
Joar Wandborg
f1d06e1d6c Switch from webob.Request to werkzeug.wrappers.Request 2012-09-29 21:08:20 +02:00
Will Kahn-Greene
05e007c1db Rework plugin infrastructure to nix side-effects
This reworks the plugin infrastructure so as to remove module-loading
side-effects which were making things a pain in the ass to test.

With the new system, there's no auto-registering meta class. Instead
plugins do whatever they want and then specify a hooks dict that maps
hook names to callables for the things they're tying into. The most
common one (and the only one we've implemented so far) is "setup".

This also simplifies the sampleplugin a little by moving the code
to __init__.py.
2012-07-17 21:02:12 -04:00
Will Kahn-Greene
4bd65f69c7 Finish flatpagesplugin; add plugin docs 2012-07-16 09:26:28 -04:00
Will Kahn-Greene
8545dd50f0 Flatpages first pass
This fixes the template loader so that it can load plugin templates.

This adds code for registering template paths so that plugins can add
their own templates.

This adds the base code for the flatpagesfile plugin. It doesn't serve
pages, yet, but it's pretty close.
2012-07-16 09:26:28 -04:00
Christopher Allan Webber
975be468cf Making the register_themes() tool also return the current theme
This will reduce the amount of work reproducing this behavior when
pulling together the theme registry elsewhere.
2012-07-14 12:55:14 -05:00
Christopher Allan Webber
3b47da8eab Themes are now registered and can have their templates loaded properly 2012-07-14 12:55:13 -05:00
Christopher Allan Webber
828fc6300a Early version of theme registry code 2012-07-14 12:55:13 -05:00
Will Kahn-Greene
29b6f91740 401. Plugin infrastructure
* implements installing, loading and setup for plugins
* codifies configuration
* has a sample plugin
* docs
* tests
2012-05-13 00:00:08 -04:00
Elrond
3f36967401 log.debug the used config file.
Might be useful at some point.
2012-04-09 22:49:41 +02:00
Christopher Allan Webber
d9a31a3980 CELERY_ALWAYS_EAGER environment variable only recognized if 'true' now 2012-04-08 10:43:23 -05:00
Christopher Allan Webber
8a0d35e72a Allow users to pass callables in as controllers, not just import paths 2012-04-08 09:54:32 -05:00
Elrond
e824570a23 Cleanup sql session after request. ALWAYS!
The cleanup could be missed if the request handling code in
app.py:__call__ exits early (due to exception, or due to
one of those early "return"s).
So to make sure the sql session is cleaned up for real,
wrap the whole thing in a try: finally:.

Also wrote a short tool to test if the session is actually
empty. The tool is currently disabled, but ready to be
used.
2012-04-07 23:21:59 +02:00
Elrond
2bc8ff0d63 Cleanup Session after each request.
It's good practice to cleanup the SQL session after each
request so that the next request gets a fresh one.

It's an application decision whether one wants a
just-in-case ROLLBACK or COMMIT. There are two ideas behind
it, really. I have decided for ROLLBACK. The idea is "if
you forget to commit your changes yourself, there's
something broken. Maybe you got an exception?".
2012-02-28 20:52:35 +01:00
Elrond
ec97c937b7 Let Main Server emit startup notice including version
There was no place in the software telling the user the
version in use. So start by having the main server emit a
startup notice including the version string. Uses python
logging, so should be easy to reconfigure, etc.
2012-02-26 18:45:35 +01:00
Christopher Allan Webber
cf29e8a824 It's 2012 all up in here 2012-02-02 09:44:13 -06:00
Elrond
d23d4b23da Note reported bug in workaround
So that the workaround can eventually be removed, note the
URL for the relevant bug in a comment.
2011-12-21 00:34:02 +01:00
Elrond
871fc591dd Workaround for Routes/urlgen bug.
This is relevant for fcgi:

Some servers (cherokee for example) put "HTTP":"off" in the
environ. And the following code in urlgen breaks on this:
    if environ.get('HTTPS') or environ.get('wsgi.url_scheme') == 'https' \
       or environ.get('HTTP_X_FORWARDED_PROTO') == 'https':
        hostinfo['protocol'] = 'https'

workaround is to remove HTTPS:off from the environ.
2011-12-21 00:06:38 +01:00
Christopher Allan Webber
1e9d1acc03 We should use the variable local_templates instead of user_template_path 2011-12-02 16:13:14 -06:00
Nathan Yergler
91cf67385a Issue 680: Dispatch meddleware request processing post-routing 2011-11-26 14:34:36 -08:00
Christopher Allan Webber
ce5ae8da19 Rename MediaGoblin middleware to meddleware to avoid confusion w/ wsgi middleware
hehehehehe, "meddleware"
2011-11-25 12:13:56 -06:00
Christopher Allan Webber
ee91c2b88d Merge remote-tracking branch 'remotes/nyergler/pep8-ification'
Conflicts:
	mediagoblin/db/migrations.py
	mediagoblin/db/models.py
	mediagoblin/user_pages/views.py
	mediagoblin/util.py
2011-11-13 20:23:26 -06:00
Christopher Allan Webber
91903aa601 [620] Allow for multiple mediagoblin configs to be set in config.ini, use first
This way we can copy paste.ini into paste_local.ini but not have to
update it to find mediagoblin_local.ini.
2011-10-29 17:04:19 -05:00
Christopher Allan Webber
f693f9af88 Merge remote branch 'remotes/elrond/misc/i592_use_full_path' 2011-10-15 11:07:13 -05:00
Christopher Allan Webber
c0022ecc88 Fixing 404s, related to recent util refactoring. 2011-10-05 20:57:02 -05:00