600 Commits

Author SHA1 Message Date
Jessica Tallon
bc75a65327 Add Graveyard model
This adds the Graveyard model which is used when a model is deleted, it
stores the important "shell" information on the model so it can
hard-delete the real object. It also remaps the GenericModelReference
references to the new Graveyard model.

This also moves the soft deletion setting from __model_args__ to
"deletion_mode" on the model.
2015-10-07 14:40:44 +02:00
Jessica Tallon
30852fda1c Add the __model_args__ deletion code
This adds the "deleted" fields to the models as well as a new
__model_args__ section whcih supports the option for changing the
deletion type. Deletion is now handled by choosing a deletion method
based on the __model_args__["deletion"] setting, for example if it's
soft deletion it will call Model.soft_delete()
2015-10-07 14:40:44 +02:00
Jessica Tallon
0f3bf8d4b1 Collection changes and migration for federation
- Adds a "type" column to the Collection object and allows the
CollectionItem model to contain any object.
- Changes "items" to "num_items" as per TODO
- Renames "uploader", "creator" and "user" to a common "actor" in most places
2015-10-07 14:40:44 +02:00
Jessica Tallon
b4997540dc Fix some unit tests and bugs
This fixes a lot of the issues with the LocalUser changes that were
merged recently. There was a problem where the attributes of LocalUser
were not being eagerly loaded and because the Session was detached an
exception was being raised when they were accessed.

This also fixes some typo's which were introduced.

Finally this adds a temporary fix for a potential SQLAlchemy bug, this
is a bug where doing:

    User.query.filter(LocalUser.username == "some_username").first()

does NOT yeild a user with the username "some_username" but all users
on the site. The temp fix is to just query the LocalUser, this should
be resolved when bug is confirmed and fixed upstream.
2015-08-24 21:07:06 +02:00
Jessica Tallon
e9bb5879f7 Fix #5344 - OAuth NotImplemented exception
This introduces a migration which adds a dummy Client, RequestToken
and AccessToken. These are used when an invalid request comes in,
instead of bailing early, it needs dummy data to prevent timing
attacks.

This then implements the methods which get the IDs of the dummy
objects. If these are changed in the future a migration which checks
for the previous dummy object should be created and updates them to
reflect the new IDs/tokens.
2015-08-21 17:57:39 +02:00
Jessica Tallon
de366f735a Fix serialization after model changes
After the recent model changes there were some bugs which were
introduced into the serialization methods of the models. This commit
fixes those issues.
2015-08-20 11:31:50 +02:00
Jessica Tallon
35fbad47d7 Change structure of MediaEntry and add migration
This makes the changes needed for federating MediaEntry objects as well
as adding the migration and necessary methods to get the public_id just
in time (JIT).
2015-08-19 17:18:37 +02:00
Jessica Tallon
d7f35f6fbe Add the user models to the MODELS list
This adds the two new user models (LocalUser and RemoteUser) to the
MODELS list that is in models.py. This stops the strange bug that occurs
if you migrate a fresh database, the two models don't exist however
migrating an existing database would create them as the migrations
exist.
2015-07-31 15:15:24 +02:00
Jessica Tallon
d88fcb03e2 Change codebase to query or create correct User model
The code base had many references to User.username and other
specific to LocalUser attributes as that was the way it use to exist.
This updates those to query on the generic User model but filtering
by attributes on the LocalUser.
2015-07-31 15:15:24 +02:00
Jessica Tallon
283e6d8b9f Add polymorphic properties to User
This adds the ability to search for any user based on the generic
User case and be given back the specific LocalUser or RemoteUser.

This will require any code using the model to look which attributes
they are searching on and specify the specific User model they are
on if they're not on the generic User model. This will also require
new users to be created with LocalUser.
2015-07-31 15:14:41 +02:00
Jessica Tallon
aa9ba3ed80 Add LocalUser and RemoteUser and migration 2015-07-31 15:14:41 +02:00
Jessica Tallon
ddc2db746f Fix removal of ActivityIntermediatory migration
The migration had a problem where other tables still referenced the migration
as well as a typo in an earlier migration. They have both been fixed and tested
on PostgreSQL and SQLite3.

This also fixes a bug where sometimes when creating an activity it'd raise an
Exception as the object hadn't got an ID. This has been fixed globally with a
fix to the create_activity federation tool.
2015-06-24 21:43:16 +02:00
Jessica Tallon
2d73983e8c Fix some problems with activity mixins and migrations 2015-05-26 16:48:59 +02:00
Jessica Tallon
c1d27aa019 Add a more verbose GenericForeignKey implementation 2015-05-26 16:48:59 +02:00
Jessica Tallon
d2256d0b3b Remove deprecated fields and fix activity creation in tools 2015-05-26 16:48:59 +02:00
Jessica Tallon
2e4782ef6d More fixed recommended by Elrond
This fixes the problem where GenericForeignKey could only be used with models
that are in the core of Mediagoblin, it now can be used with any model
that SQLAlchemy knows about, including plugins. This also fixes some small bugs
caused by incorrect ordering of params into a function.
2015-05-26 16:48:59 +02:00
Jessica Tallon
0b405a3ee2 Add some fixes Elrond suggested and doc strings 2015-05-26 16:48:59 +02:00
Jessica Tallon
e8b44d7c09 Add migration to remove ActivityIntermediator
Migration to drop the table and removal of it from the model as it has
now been superseeded by the GenericForeignKey field.
2015-05-26 16:48:59 +02:00
Jessica Tallon
6185a4b9e6 Fix the GenericForeignKey implementation 2015-05-26 16:48:58 +02:00
Jessica Tallon
bfe1e8ce88 Migrate Activity to using the new GenericForeignKey 2015-05-26 16:48:58 +02:00
Jessica Tallon
641ae2f1e1 Add GenericForeignKey field and reference helper model 2015-05-26 16:48:58 +02:00
Christopher Allan Webber
941b9abbb0 Fix the token issues in the migration
There's no .id on access/request token tables, so fixed to use the .token field.

Also switched a reference of client_table -> rt_table
2015-02-17 20:04:15 -06:00
Christopher Allan Webber
d180c131c3 acess_token->access_token 2015-02-17 19:44:58 -06:00
Christopher Allan Webber
f3c5d01199 Fixing typo: notifiction->notification 2015-02-17 19:42:43 -06:00
Christopher Allan Webber
e0713d9ccf This one should be dt_to_utc, not db_to_utc, I believe 2015-02-17 19:42:11 -06:00
Jessica Tallon
d705f3b760 Fix #1065 - Migrate from native datetimes to UTC 2015-02-15 17:17:01 +01:00
Jessica Tallon
4fd520364f Change 'federation' name to 'api' which is more suitable 2015-02-15 17:17:01 +01:00
Jessica Tallon
63d6953774 Fix #1052 - Make activity cascade delete work when deleting a user 2015-01-27 13:31:29 +00:00
Jessica Tallon
7eac1e6d6b Fix 1e0c938 by allowing target to be translatable in Activity.content 2014-12-22 11:48:01 +00:00
Jessica Tallon
1e0c938c63 Allow Activity.content to be fully translatable 2014-12-22 11:00:44 +00:00
Jessica Tallon
9e715bb07f Fix #1077 - Fix updating comment via API and add test 2014-12-16 12:05:18 +00:00
Jessica Tallon
4a09d5956a Fix #1053 - Add height and width attributes and MetadataProcess task
Added "height" and "width" attributes to "image" and "fullImage"
    in the API where possible. The height and width of images wasn't
    being stored anywhere so I've created a task to add or update
    the metadata on images and also started adding those to new images
    when they're submitted in the InitialProcessor.
2014-12-11 11:52:34 +00:00
Jessica Tallon
3588522606 Fix #1054 - Add missing attributes to Activity.serialize 2014-12-08 14:46:48 +00:00
Jessica Tallon
5b7e6bb8c2 Fix #1049 - name renamed to displayName for Location 2014-12-05 14:04:18 +00:00
Christopher Allan Webber
7b808c1fad There's absolutely no reason for a Session().commit object mirrored onto Session() :)
Thanks for catching, Elrond :)
2014-12-03 15:40:58 -06:00
Christopher Allan Webber
ddabf20f25 Make all mixin methods ignore mg_globals and use self._app instead
This commit sponsored by Daniel Lang.  Thank you!
2014-12-03 15:40:58 -06:00
Christopher Allan Webber
7c563e91bf Attach the MediaGoblinApp to the engine, and provide a way for models to access
This allows SQLAlchemy models to gain access to app-level configuration
without the need for global variables.

This commit sponsored by Peter Hogg.  Thank you, Peter!
2014-12-03 15:40:58 -06:00
Christopher Allan Webber
9d82dff6fb Adding query property to DatabaseMaster for forward compatibility 2014-12-03 15:40:57 -06:00
Christopher Allan Webber
f7521cac34 Attach the base models to sessions and the DatabaseMaster for backwards compatibility
Really we should stop relying on that though.
2014-12-03 15:40:57 -06:00
Christopher Allan Webber
5cbdb15cdb Only conditionally import Session in db/util.py 2014-12-03 15:40:57 -06:00
Christopher Allan Webber
2026752120 Move the scoped_session, sessionmaker imports 2014-12-03 15:40:57 -06:00
Christopher Allan Webber
e248e1429a Some docstrings 2014-12-03 15:40:57 -06:00
Christopher Allan Webber
63f6a418d1 Return DatabaseManager or DatabaseMaster depending on DISABLE_GLOBALS
They're both similar!  One sets up sessions, one grabs sessions from a global object.
2014-12-03 15:40:57 -06:00
Christopher Allan Webber
5f3703d545 Oops, got the boolean backwards :P 2014-12-03 15:40:57 -06:00
Christopher Allan Webber
4591af32b3 Adding DatabaseManager as an alternative to DatabaseMaster
This is another step to get to a no-globals configuration.  I'm not
sure if this code works yet or not... :)
2014-12-03 15:40:57 -06:00
Christopher Allan Webber
b88ca698dd An environment variable to transition towards removing global variables 2014-12-03 15:40:56 -06:00
Christopher Allan Webber
15c86f3a57 Give our sqlalchemy objects access to their own session 2014-12-03 15:40:56 -06:00
Jessica Tallon
1c8f52daee Fix #1040 - Comments should have published attribute 2014-11-27 10:13:21 +00:00
Berker Peksag
9d85dcdf11 Fix unicode handling in "gmg addmedia". 2014-11-22 18:12:19 +00:00
Jessica Tallon
9c602458d8 Fix #1025 - Make API IDs IRIs 2014-11-21 13:30:31 +00:00