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
This commit is contained in:
Jessica Tallon
2015-09-17 13:47:56 +02:00
parent 80ba8ad1d1
commit 0f3bf8d4b1
48 changed files with 437 additions and 250 deletions

View File

@@ -190,7 +190,7 @@ class TestAPI(object):
# and self._upload_image.
id = int(data["object"]["id"].split("/")[-2])
media = MediaEntry.query.filter_by(id=id).first()
media.uploader = self.other_user.id
media.actor = self.other_user.id
media.save()
# Now lets try and edit the image as self.user, this should produce a 403 error.
@@ -324,7 +324,7 @@ class TestAPI(object):
comment = media.get_comments()[0]
# Tests that it matches in the database
assert comment.author == self.user.id
assert comment.actor == self.user.id
assert comment.content == content
# Test that the response is what we should be given
@@ -384,7 +384,7 @@ class TestAPI(object):
# change who uploaded the comment as it's easier than changing
comment_id = int(comment_data["object"]["id"].split("/")[-2])
comment = MediaComment.query.filter_by(id=comment_id).first()
comment.author = self.other_user.id
comment.actor = self.other_user.id
comment.save()
# Update the comment as someone else.
@@ -597,4 +597,3 @@ class TestAPI(object):
model = MediaComment.query.filter_by(id=comment_id).first()
assert model.content == activity["object"]["content"]

View File

@@ -50,7 +50,7 @@ def test_user_deletes_other_comments(test_app):
for m_id in (media_a.id, media_b.id):
cmt = MediaComment()
cmt.media_entry = m_id
cmt.author = u_id
cmt.actor = u_id
cmt.content = u"Some Comment"
Session.add(cmt)

View File

@@ -56,7 +56,7 @@ class TestMediaEntrySlugs(object):
entry.title = title or u"Some title"
entry.slug = slug
entry.id = this_id
entry.uploader = uploader or self.chris_user.id
entry.actor = uploader or self.chris_user.id
entry.media_type = u'image'
if save:

View File

@@ -158,7 +158,7 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
fixture_add_comment(author=self.user.id,
comment=u'Comment will be removed')
test_comment = MediaComment.query.filter(
MediaComment.author==self.user.id).first()
MediaComment.actor==self.user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=self.user)
comment_report = CommentReport.query.filter(
@@ -177,7 +177,7 @@ VGhpcyBpcyB5b3VyIGxhc3Qgd2FybmluZywgcmVndWxhci4uLi4=\n',
UserBan.user_id == self.user.id).first()
assert test_user_ban is not None
test_comment = MediaComment.query.filter(
MediaComment.author==self.user.id).first()
MediaComment.actor==self.user.id).first()
assert test_comment is None
# Then, test what happens when a moderator attempts to punish an admin

View File

@@ -112,7 +112,7 @@ class TestNotifications:
assert type(notification) == CommentNotification
assert notification.seen == False
assert notification.user_id == user.id
assert notification.subject.get_author.id == self.test_user.id
assert notification.subject.get_actor.id == self.test_user.id
assert notification.subject.content == u'Test comment #42'
if wants_email == True:

View File

@@ -133,7 +133,7 @@ class TestReportFiling:
fixture_add_comment(author=allie_user.id,
comment=u'Comment will be removed')
test_comment = MediaComment.query.filter(
MediaComment.author==allie_user.id).first()
MediaComment.actor==allie_user.id).first()
fixture_add_comment_report(comment=test_comment,
reported_user=allie_user,
report_content=u'Testing Archived Reports #1',
@@ -165,4 +165,3 @@ class TestReportFiling:
natalie banned user allie indefinitely.
natalie deleted the comment.'''
assert archived_report.discriminator == 'comment_report'

View File

@@ -204,12 +204,12 @@ def fixture_add_user(username=u'chris', password=u'toast',
def fixture_comment_subscription(entry, notify=True, send_email=None):
if send_email is None:
uploader = LocalUser.query.filter_by(id=entry.uploader).first()
send_email = uploader.wants_comment_notification
actor = LocalUser.query.filter_by(id=entry.actor).first()
send_email = actor.wants_comment_notification
cs = CommentSubscription(
media_entry_id=entry.id,
user_id=entry.uploader,
user_id=entry.actor,
notify=notify,
send_email=send_email)
@@ -254,7 +254,7 @@ def fixture_media_entry(title=u"Some title", slug=None,
entry = MediaEntry()
entry.title = title
entry.slug = slug
entry.uploader = uploader
entry.actor = uploader
entry.media_type = u'image'
entry.state = state
@@ -278,15 +278,21 @@ def fixture_media_entry(title=u"Some title", slug=None,
return entry
def fixture_add_collection(name=u"My first Collection", user=None):
def fixture_add_collection(name=u"My first Collection", user=None,
collection_type=Collection.USER_DEFINED_TYPE):
if user is None:
user = fixture_add_user()
coll = Collection.query.filter_by(creator=user.id, title=name).first()
coll = Collection.query.filter_by(
actor=user.id,
title=name,
type=collection_type
).first()
if coll is not None:
return coll
coll = Collection()
coll.creator = user.id
coll.actor = user.id
coll.title = name
coll.type = collection_type
coll.generate_slug()
coll.save()
@@ -310,7 +316,7 @@ def fixture_add_comment(author=None, media_entry=None, comment=None):
'Auto-generated test comment by user #{0} on media #{0}'.format(
author, media_entry)
comment = MediaComment(author=author,
comment = MediaComment(actor=author,
media_entry=media_entry,
content=comment)
@@ -373,4 +379,4 @@ def fixture_add_activity(obj, verb="post", target=None, generator=None, actor=No
activity.set_target(target)
activity.save()
return activity
return activity