diff options
author | Jessica Tallon <tsyesika@tsyesika.se> | 2015-08-24 18:28:41 +0200 |
---|---|---|
committer | Jessica Tallon <tsyesika@tsyesika.se> | 2015-08-24 21:07:06 +0200 |
commit | b4997540dcc7b75441e9b10ee6dcac32cc2708be (patch) | |
tree | e543baf0acc77214c44bad9f826d9187459539a9 /mediagoblin/db/models.py | |
parent | e9bb5879f772e4d546aadb4bb6f935c7c55b8000 (diff) | |
download | mediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.tar.lz mediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.tar.xz mediagoblin-b4997540dcc7b75441e9b10ee6dcac32cc2708be.zip |
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.
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r-- | mediagoblin/db/models.py | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index f1449667..8c8e42e5 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -250,9 +250,29 @@ class User(Base, UserMixin): __mapper_args__ = { 'polymorphic_identity': 'user', - 'polymorphic_on': type + 'polymorphic_on': type, } + def delete(self, **kwargs): + """Deletes a User and all related entries/comments/files/...""" + # Collections get deleted by relationships. + + media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id) + for media in media_entries: + # TODO: Make sure that "MediaEntry.delete()" also deletes + # all related files/Comments + media.delete(del_orphan_tags=False, commit=False) + + # Delete now unused tags + # TODO: import here due to cyclic imports!!! This cries for refactoring + from mediagoblin.db.util import clean_orphan_tags + clean_orphan_tags(commit=False) + + # Delete user, pass through commit=False/True in kwargs + username = self.username + super(User, self).delete(**kwargs) + _log.info('Deleted user "{0}" account'.format(username)) + def has_privilege(self, privilege, allow_admin=True): """ This method checks to make sure a user has all the correct privileges @@ -335,7 +355,7 @@ class LocalUser(User): upload_limit = Column(Integer) __mapper_args__ = { - 'polymorphic_identity': 'user_local' + "polymorphic_identity": "user_local", } ## TODO @@ -349,25 +369,6 @@ class LocalUser(User): 'admin' if self.has_privilege(u'admin') else 'user', self.username) - def delete(self, **kwargs): - """Deletes a User and all related entries/comments/files/...""" - # Collections get deleted by relationships. - - media_entries = MediaEntry.query.filter(MediaEntry.uploader == self.id) - for media in media_entries: - # TODO: Make sure that "MediaEntry.delete()" also deletes - # all related files/Comments - media.delete(del_orphan_tags=False, commit=False) - - # Delete now unused tags - # TODO: import here due to cyclic imports!!! This cries for refactoring - from mediagoblin.db.util import clean_orphan_tags - clean_orphan_tags(commit=False) - - # Delete user, pass through commit=False/True in kwargs - super(User, self).delete(**kwargs) - _log.info('Deleted user "{0}" account'.format(self.username)) - def serialize(self, request): user = { "id": "acct:{0}@{1}".format(self.username, request.host), |