43 Commits

Author SHA1 Message Date
Boris Bobrov
54b4b28f84 Add new hook for two-step media type checking
Before uploaded media files were checked by extension. This led to
situations when a plugin can support file with specific extension but
doesn't due to lack of codecs, for example. Since the plugin reported
that it supports uploaded file type, the upload was being declared
successful, but transcoding failed.

The failures were not easy to debug.

The change adds a new hook that could allow two-step checking of the
content. The result of the hook execution returns a tuple with
media type name, manager and a callable sniffer, that can be used to
perform probably expensive checks of the content.

Also the change adds implementation of the hook for video.
2015-02-16 13:41:09 +03:00
Christopher Allan Webber
f6bad0eb26 Merge branch 'master' into merge-python3-port
Has some issues, will iteratively fix!

Conflicts:
	mediagoblin/gmg_commands/__init__.py
	mediagoblin/gmg_commands/deletemedia.py
	mediagoblin/gmg_commands/users.py
	mediagoblin/oauth/views.py
	mediagoblin/plugins/api/views.py
	mediagoblin/tests/test_api.py
	mediagoblin/tests/test_edit.py
	mediagoblin/tests/test_oauth1.py
	mediagoblin/tests/test_util.py
	mediagoblin/tools/mail.py
	mediagoblin/webfinger/views.py
	setup.py
2014-09-16 14:01:43 -05:00
Berker Peksag
6fa9782415 Make sort_keys True to avoid hash randomize feature in Python 3. 2014-08-04 22:06:40 +03:00
Tryggvi Bjorgvinsson
71d31dda07 Tags can now be passed in for media entries submitted via the api plugin 2014-07-10 11:05:29 -05:00
Berker Peksag
e49b7e02b2 Use six.text_type instead of unicode().
I will be switch to use ``from __future__ import unicode_literals`` later.
2014-06-02 20:59:28 +03:00
Berker Peksag
fd19da346b Use six.moves.urllib.parse instead of the urlparse module. 2014-05-26 19:52:18 +03:00
Christopher Allan Webber
131b749529 Making the API make use of the new submit tooling.
This commit sponsored by Zakkai Kauffman-Rogoff.  Thanks! :)
2013-11-14 14:04:32 -06:00
xray7224
1c694fbec5 Fixes tests 2013-07-14 19:00:52 +01:00
xray7224
04e08d422a Moves json_response into tools/json.py 2013-07-11 18:21:43 +01:00
Elrond
6c1467d570 Refactor submit util new_upload_entry
This tool creates an initial media entry for a given user.
No magic. It just prefills the license with the user's
default license and adds the user as uploader.
2013-05-21 00:28:37 +02:00
Christopher Allan Webber
230b5eb2eb Fixing API setup with new plugin "config spec" world
It shouldn't reference the config until in the setup_plugin() method,
else there's a race condition.
2013-05-08 15:20:27 -05:00
Elrond
2ef2f46e73 Refactor file field checking.
When uploading, the file field needs some checks, it seems.
So refactor them into check_file_field and use around.
2013-03-29 12:01:23 +01:00
Runar Petursson
9b2cd962af plugins/api: fix for cross origin requests
The response headers were never getting set because of a bug in the 7c552c0
commit.  This expands the loop into a more readable form and results in the
headers getting set.
2013-02-20 23:41:36 +01:00
Sebastian Spaeth
c7b3d070b6 Don't pass request into run_process_media
People(tm) want to start run_process_media from the CLI and might not
have a request object handy. So pass in the feed_url into
run_process_media rather than the request object and allow the feed url
to be empty (resulting in no PuSH notification at all then).

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 15:03:00 +01:00
Sebastian Spaeth
2cfffd5ed8 Make PuSHing the Pubhubsubbub server an async task (#436, #585)
Notifying the PuSH servers had 3 problems. 

1) it was done immediately after sending of the processing task to celery. So if celery was run in a separate
process we would notify the PuSH servers before the new media was processed/
visible. (#436)

2) Notification code was called in submit/views.py, so submitting via the
   API never resulted in notifications. (#585)

3) If Notifying the PuSH server failed, we would never retry.

The solution was to make the PuSH notification an asynchronous subtask. This
way: 1) it will only be called once async processing has finished, 2) it
is in the main processing code path, so even API calls will result in
notifications, and 3) We retry 3 times in case of failure before giving up.
If the server is in a separate process, we will wait 3x 2 minutes before
retrying the notification.

The only downside is that the celery server needs to have access to the internet
to ping the PuSH server. If that is a problem, we need to make the task belong
to a special group of celery servers that has access to the internet.

As a side effect, I believe I removed the limitation that prevented us from
upgrading celery.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 14:53:08 +01:00
Joar Wandborg
78fa73bcd5 Made api_test use @require_active_login 2013-01-02 20:05:07 +01:00
Elrond
b228d89715 prepare_queue_task: Take app not request.
First rename prepare_entry to prepare_queue_task, because
this is really more like what this thing does.

Thanks to Velmont for noting that we do not need a request
in here, but an "app" is good enough. Which means, that
this stuff can be called from tool scripts too.
2012-12-26 23:42:26 +01:00
Elrond
01986008f6 upload refactor: Use prepare_entry in api. 2012-12-26 23:42:26 +01:00
Elrond
37f90b435d Use run_process_media in the api.
Now refactor in the api. Start with run_process_media.
2012-12-26 23:42:26 +01:00
Elrond
ac8212fe65 Remove mongo style .id = ObjectId()
On SQL we can't generate the primary key on our own. So
just remove this stuff.
2012-12-24 00:07:24 +01:00
Elrond
b39d1f2351 Mongo removal: Remove the validate=True arg to obj.save()
all callers were forced to use validate=True anyway. So
remove this useless stuff.
2012-12-24 00:07:24 +01:00
Joar Wandborg
57c6473aa2 Added API tests 2012-12-23 21:45:46 +01:00
Sebastian Spaeth
cfa922295e Convert return HttpException to raise HttpException
controllers (view function) raise HttpException's and do not return them.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-23 11:58:51 +01:00
Sebastian Spaeth
cc195d5b82 plugins/api: webob.Response -> werkzeug.Response 2012-12-21 08:12:25 +01:00
Sebastian Spaeth
7c552c0bd7 plugins/api: use headers.set(), not headers.update()
The werkzeug.Response().headers do not offer an update() method as
the same key can be twice in the header 'dict'. Thus, iterate over
the header keys and use header.set(key, value) which replaces an
existing header key.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:12:25 +01:00
Sebastian Spaeth
74af60bb32 replace webob.Response with werkzeug Response
Replace webob usage in one more file. Document a TODO that should
be clarified, we should probably be using json_response rather than
Response() here.

Modify the TestMeddleware to not rely on the content_type attribute
being present, while werkzeug.wrappers Response() has it the BaseResponse()
object which is often returned in tests does not have it.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:12:25 +01:00
Sebastian Spaeth
62d14bf50b Transition webob.HttpForbidden to webob's exceptions Forbidden
Also the BadRequest exception.
2012-12-21 08:11:40 +01:00
Sebastian Spaeth
5c2b84869f Move DBModel._id -> DBModel.id
We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.

It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.

This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)

I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 00:30:48 +01:00
Joar Wandborg
5b60ec41ee Removed Routes dependency, added admin routes 2012-10-20 12:35:03 +02: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
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
5354f954dc Added support for http callbacks on processing
Sends an HTTP POST request back to an URL given on submission to the API
submit view.
2012-09-26 23:53:51 +02:00
Joar Wandborg
88a9662be4 Added client registration caps to OAuth plugin
THE MIGRATIONS SUPPLIED WITH THIS COMMIT WILL DROP AND RE-CREATE YOUR
oauth__tokens AND oauth__codes TABLES. ALL YOUR OAUTH CODES AND TOKENS
WILL BE LOST.

- Fixed pylint issues in db/sql/migrations.
- Added __repr__ to the User model.
- Added _disable_cors option to json_response.
- Added crude error handling to the api.tools.api_auth decorator
- Updated the OAuth README.
- Added client registration, client overview, connection overview,
  client authorization views and templates.
- Added error handling to the OAuthAuth Auth object.
- Added AuthorizationForm, ClientRegistrationForm in oauth/forms.
- Added migrations for OAuth, added client registration migration.
- Added OAuthClient, OAuthUserClient models.
- Added oauth/tools with require_client_auth decorator method.
2012-09-21 13:09:42 +02:00
Joar Wandborg
09e528acbb Fixed validation in API post_entry.
Added state to API get_entry_serializable
2012-09-17 23:54:27 +02:00
Joar Wandborg
c92aa0d0b2 API: Fixed media file URLs, limits
- Added default limit and limit arg to get_entries
- Fixed URL generation for BasicFileStorage files in API
2012-09-15 22:34:34 +02:00
Joar Wandborg
965b39a84f Added CORS headers to API json_response 2012-09-15 22:18:49 +02:00
Joar Wandborg
3a1993288f Fixed ?next=<url> argument for require_active_login
It now includes the full URI, including GET args, not just the path.
2012-09-15 21:07:24 +02:00
Joar Wandborg
999f91eb8a Fixed typo in API post_entry 2012-09-15 16:54:14 +02:00
Joar Wandborg
4504dbba9b Added post_entry at /api/submit 2012-09-15 16:51:29 +02:00
Joar Wandborg
85726f7360 Added fields to /api/entries, wrote docstrings for api.tools 2012-09-15 15:54:22 +02:00
Joar Wandborg
42c837523e Added /api/entries view 2012-09-15 15:25:26 +02:00
Joar Wandborg
a062149e90 Created API plugin, moved api_auth to the API plugin 2012-09-13 20:59:00 +02:00