From 2dd966b5e2c6c406d153e2d4cdf886e30198a1d3 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Thu, 6 Feb 2014 15:15:57 -0500 Subject: In this commit, I added a new column which will be used for RDFa metadata of media. --- mediagoblin/db/models.py | 1 + 1 file changed, 1 insertion(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b750375d..ac69d040 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -420,6 +420,7 @@ class MediaFile(Base): name_id = Column(SmallInteger, ForeignKey(FileKeynames.id), nullable=False) file_path = Column(PathTupleWithSlashes) file_metadata = Column(MutationDict.as_mutable(JSONEncoded)) + work_metadata = Column(MutationDict.as_mutable(JSONEncoded)) __table_args__ = ( PrimaryKeyConstraint('media_entry', 'name_id'), -- cgit v1.2.3 From 9f3dc83a6cec48379972b1f99f955b9525e77c32 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 15 Apr 2014 13:51:27 -0400 Subject: Moved the metadata column to MediaEntry rather than MediaFile --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index ac69d040..7c0f0bf3 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -264,6 +264,7 @@ class MediaEntry(Base, MediaEntryMixin): cascade="all, delete-orphan" ) collections = association_proxy("collections_helper", "in_collection") + metadata = Column(MutationDict.as_mutable(JSONEncoded)) ## TODO # fail_error @@ -420,7 +421,6 @@ class MediaFile(Base): name_id = Column(SmallInteger, ForeignKey(FileKeynames.id), nullable=False) file_path = Column(PathTupleWithSlashes) file_metadata = Column(MutationDict.as_mutable(JSONEncoded)) - work_metadata = Column(MutationDict.as_mutable(JSONEncoded)) __table_args__ = ( PrimaryKeyConstraint('media_entry', 'name_id'), -- cgit v1.2.3 From 0bfb4089cc187113a7808eed6643a73c86bb01cb Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 15 Apr 2014 14:17:43 -0400 Subject: Changed the name of the metadata column --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 7c0f0bf3..defa0849 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -264,7 +264,7 @@ class MediaEntry(Base, MediaEntryMixin): cascade="all, delete-orphan" ) collections = association_proxy("collections_helper", "in_collection") - metadata = Column(MutationDict.as_mutable(JSONEncoded)) + media_metadata = Column(MutationDict.as_mutable(JSONEncoded)) ## TODO # fail_error -- cgit v1.2.3 From 7918f86ac0dd55a7be863bf29a074b4edbe4b656 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 22 Apr 2014 13:32:47 -0400 Subject: Renamed the columns on core__privileges_users table so that they are unique and will not cause any more problems. --- mediagoblin/db/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b750375d..58635419 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -876,12 +876,12 @@ class PrivilegeUserAssociation(Base): __tablename__ = 'core__privileges_users' privilege_id = Column( - 'core__privilege_id', + 'id_of_privilege', Integer, ForeignKey(User.id), primary_key=True) user_id = Column( - 'core__user_id', + 'id_of_user', Integer, ForeignKey(Privilege.id), primary_key=True) -- cgit v1.2.3 From 9adef07e8f0d169e57776bcefc03f2ae17c8920e Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Wed, 23 Apr 2014 14:59:53 -0400 Subject: Made the columns properly referenced in models and migrations. --- mediagoblin/db/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 58635419..f03cf615 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -875,13 +875,11 @@ class PrivilegeUserAssociation(Base): __tablename__ = 'core__privileges_users' - privilege_id = Column( - 'id_of_privilege', + user_id = Column( Integer, ForeignKey(User.id), primary_key=True) - user_id = Column( - 'id_of_user', + privilege_id = Column( Integer, ForeignKey(Privilege.id), primary_key=True) -- cgit v1.2.3 From c8abeb58afd36c56af705a69a2d3ebec90002e74 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Wed, 14 May 2014 11:56:59 -0400 Subject: Set a default value to MediaEntry.media_metadata --- mediagoblin/db/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index defa0849..8499ea3f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -264,7 +264,8 @@ class MediaEntry(Base, MediaEntryMixin): cascade="all, delete-orphan" ) collections = association_proxy("collections_helper", "in_collection") - media_metadata = Column(MutationDict.as_mutable(JSONEncoded)) + media_metadata = Column(MutationDict.as_mutable(JSONEncoded), + default=MutationDict()) ## TODO # fail_error -- cgit v1.2.3 From c56a88b43e168196c8c4b3778fccde2497d2e32b Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 10 Jun 2014 18:02:34 -0500 Subject: Switch "user_id" to "privilege" and "privilege_id" to "user". This builds on the previous code Natalie wrote, but makes some changes: - More direct alterations for non-sqlite code - In both cases, I've made it so that we switched the field names from privilege_id and user_id to user and privilege respectively. This way we can do the name swap, but in one case it's "easy": just changing the name. (In the sqlite case it's still tricky though.) --- mediagoblin/db/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 77bfe14e..efc98b3b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -877,11 +877,11 @@ class PrivilegeUserAssociation(Base): __tablename__ = 'core__privileges_users' - user_id = Column( + user = Column( Integer, ForeignKey(User.id), primary_key=True) - privilege_id = Column( + privilege = Column( Integer, ForeignKey(Privilege.id), primary_key=True) -- cgit v1.2.3 From 987a63514ff3c9c436084eaca8524dc577ae1a6e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 11 Jun 2014 11:01:17 -0500 Subject: Explicitly set the column names to "user" and "privilege" --- mediagoblin/db/models.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index efc98b3b..e388bd5b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -878,10 +878,12 @@ class PrivilegeUserAssociation(Base): __tablename__ = 'core__privileges_users' user = Column( + "user", Integer, ForeignKey(User.id), primary_key=True) privilege = Column( + "privilege", Integer, ForeignKey(Privilege.id), primary_key=True) -- cgit v1.2.3 From 892eed590fb30131ea2e8612da5ba22fa24f690c Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Thu, 17 Jul 2014 14:58:24 +0100 Subject: Fix #894 - index User.username field This commit sponsored by Emily O'Leary. Thank you! --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index e388bd5b..643d5d41 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -57,7 +57,7 @@ class User(Base, UserMixin): __tablename__ = "core__users" id = Column(Integer, primary_key=True) - username = Column(Unicode, nullable=False, unique=True) + username = Column(Unicode, nullable=False, unique=True, index=True) # Note: no db uniqueness constraint on email because it's not # reliable (many email systems case insensitive despite against # the RFC) and because it would be a mess to implement at this -- cgit v1.2.3 From 09bed9a7328c806873405bd2ec5a5cf72930e89c Mon Sep 17 00:00:00 2001 From: Tryggvi Bjorgvinsson Date: Fri, 28 Feb 2014 23:25:02 +0000 Subject: Use unicode for logging comments The comment problems detailed in issue 791 are related to logging of comments creation. The log tries to format unicode comments into an ascii string (that is the unicode comment content). This also creates problems with mark seen functionality since that also logs the comments which breaks and you end up with a lot of international comments in your message queue. This commit makes both log messages unicode as well as the representation of the comment. --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 643d5d41..4c9345fc 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -666,7 +666,7 @@ class Notification(Base): } def __repr__(self): - return '<{klass} #{id}: {user}: {subject} ({seen})>'.format( + return u'<{klass} #{id}: {user}: {subject} ({seen})>'.format( id=self.id, klass=self.__class__.__name__, user=self.user, -- cgit v1.2.3 From 637b966ac20e448d17b310ccbf29389410d7cdf2 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 29 Jul 2013 17:31:42 +0100 Subject: Adds seralize on user --- mediagoblin/db/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4c9345fc..b96129ae 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -136,6 +136,16 @@ class User(Base, UserMixin): return UserBan.query.get(self.id) is not None + def serialize(self, request): + user = { + "preferredUsername": self.username, + "displayName": "{username}@{server}".format(username=self.username, server=request.url) + "objectType": "person", + "url": self.url, + "links": { + }, + } + class Client(Base): """ Model representing a client - Used for API Auth -- cgit v1.2.3 From d7b3805f2dde435e211560ba6500cc30780739eb Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 29 Jul 2013 21:53:08 +0100 Subject: Starts the user (profile) endpoint and lays groundwork for inbox and feed endpoint --- mediagoblin/db/models.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b96129ae..61a7f251 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -138,13 +138,37 @@ class User(Base, UserMixin): def serialize(self, request): user = { + "id": "acct:{0}@{1}".format(self.username, request.url), "preferredUsername": self.username, - "displayName": "{username}@{server}".format(username=self.username, server=request.url) + "displayName": "{0}@{1}".format(self.username, request.url), "objectType": "person", "url": self.url, + "summary": self.bio, "links": { + "self": { + "href": request.urlgen( + "mediagoblin.federation.profile", + username=self.username, + qualified=True + ), + }, + "activity-inbox": { + "href": request.urlgen( + "mediagoblin.federation.inbox", + username=self.username, + qualified=True + ) + }, + "activity-outbox": { + "href": request.urlgen( + "mediagoblin.federation.feed", + username=self.username, + qualified=True + ) + }, }, } + return user class Client(Base): """ -- cgit v1.2.3 From e590179ab61c873acfa291f93cba7cc412432a58 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 15:41:02 +0100 Subject: Adds migration on MediaEntry to add uuid --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 61a7f251..02392792 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -20,6 +20,7 @@ TODO: indexes on foreignkeys, where useful. import logging import datetime +import base64 from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \ Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \ @@ -422,7 +423,6 @@ class MediaEntry(Base, MediaEntryMixin): # pass through commit=False/True in kwargs super(MediaEntry, self).delete(**kwargs) - class FileKeynames(Base): """ keywords for various places. -- cgit v1.2.3 From 2b7b9de32e53d34635059afc571ac1a318e41071 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 16:16:49 +0100 Subject: Make sure new media has a new uuid added on --- mediagoblin/db/models.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 02392792..e1b37aa0 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -237,6 +237,10 @@ class NonceTimestamp(Base): timestamp = Column(DateTime, nullable=False, primary_key=True) +def create_uuid(): + """ Creates a new uuid which is suitable for use in a URL """ + return base64.urlsafe_b64encode(uuid.uuid4().bytes).strip("=") + class MediaEntry(Base, MediaEntryMixin): """ TODO: Consider fetching the media_files using join -- cgit v1.2.3 From bdde87a4b3a584a2dde5803b1a069496aee73daf Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 17:51:36 +0100 Subject: Changes serialization to .serialize method on object - MediaEntry --- mediagoblin/db/models.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index e1b37aa0..404aaa94 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -427,6 +427,37 @@ class MediaEntry(Base, MediaEntryMixin): # pass through commit=False/True in kwargs super(MediaEntry, self).delete(**kwargs) + @property + def objectType(self): + """ Converts media_type to pump-like type - don't use internally """ + return self.media_type.split(".")[-1] + + def serialize(self, request): + """ Unserialize MediaEntry to object """ + author = self.get_uploader + url = request.urlgen( + "mediagoblin.user_pages.media_home", + user=author.username, + media=self.slug, + qualified=True + ) + + id = request.urlgen( + "mediagoblin.federation.object", + objectType=self.objectType, + uuid=self.uuid, + qualified=True + ) + + context = { + "id": id, + "author": author.serialize(request), + "displayName": self.title, + "objectType": self.objectType, + "url": url, + } + return context + class FileKeynames(Base): """ keywords for various places. @@ -573,6 +604,18 @@ class MediaComment(Base, MediaCommentMixin): cascade="all, delete-orphan")) + def serialize(self, request): + """ Unserialize to python dictionary for API """ + media = MediaEntry.query.filter_by(self.media_entry).first() + context = { + "objectType": "comment", + "content": self.content, + "inReplyTo": media.unserialize(request), + "author": self.get_author.unserialize(request) + } + + return context + class Collection(Base, CollectionMixin): """An 'album' or 'set' of media by a user. -- cgit v1.2.3 From a840d2a848743fe36fc800557de7bb7a6e693b57 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 18:23:52 +0100 Subject: Adds comments for the MediaEntry api --- mediagoblin/db/models.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 404aaa94..6d6b2032 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -432,7 +432,7 @@ class MediaEntry(Base, MediaEntryMixin): """ Converts media_type to pump-like type - don't use internally """ return self.media_type.split(".")[-1] - def serialize(self, request): + def serialize(self, request, show_comments=True): """ Unserialize MediaEntry to object """ author = self.get_uploader url = request.urlgen( @@ -456,6 +456,17 @@ class MediaEntry(Base, MediaEntryMixin): "objectType": self.objectType, "url": url, } + + if show_comments: + comments = [comment.serialize(request) for comment in self.get_comments()] + total = len(comments) + if total > 0: + # we only want to include replies if there are any. + context["replies"] = { + "totalItems": total, + "items": comments + } + return context class FileKeynames(Base): @@ -603,15 +614,15 @@ class MediaComment(Base, MediaCommentMixin): lazy="dynamic", cascade="all, delete-orphan")) - def serialize(self, request): """ Unserialize to python dictionary for API """ - media = MediaEntry.query.filter_by(self.media_entry).first() + media = MediaEntry.query.filter_by(id=self.media_entry).first() + author = self.get_author context = { "objectType": "comment", "content": self.content, - "inReplyTo": media.unserialize(request), - "author": self.get_author.unserialize(request) + "inReplyTo": media.serialize(request, show_comments=False), + "author": author.serialize(request) } return context -- cgit v1.2.3 From c8bd2542d7b8face6033884fccfb898be1d12989 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 18:32:27 +0100 Subject: Fixes where User id in API would return url rather than host --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 6d6b2032..281c09d9 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -139,7 +139,7 @@ class User(Base, UserMixin): def serialize(self, request): user = { - "id": "acct:{0}@{1}".format(self.username, request.url), + "id": "acct:{0}@{1}".format(self.username, request.host), "preferredUsername": self.username, "displayName": "{0}@{1}".format(self.username, request.url), "objectType": "person", -- cgit v1.2.3 From 5b014a08661f718bd92971e71d173a0ea4b62c40 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 14 Aug 2013 19:58:01 +0100 Subject: Add image URL's (thumb & full) --- mediagoblin/db/models.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 281c09d9..925f0d24 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -455,6 +455,12 @@ class MediaEntry(Base, MediaEntryMixin): "displayName": self.title, "objectType": self.objectType, "url": url, + "image": { + "url": request.host_url + self.thumb_url[1:], + }, + "fullImage":{ + "url": request.host_url + self.original_url[1:], + } } if show_comments: -- cgit v1.2.3 From d461fbe5cb20ed56c3c1e3696464c3d323e5b4b0 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Mon, 2 Sep 2013 16:22:24 +0100 Subject: Use the the slug as the UUID instead of a newly generated UUID --- mediagoblin/db/models.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 925f0d24..ca4efdd1 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -236,11 +236,6 @@ class NonceTimestamp(Base): nonce = Column(Unicode, nullable=False, primary_key=True) timestamp = Column(DateTime, nullable=False, primary_key=True) - -def create_uuid(): - """ Creates a new uuid which is suitable for use in a URL """ - return base64.urlsafe_b64encode(uuid.uuid4().bytes).strip("=") - class MediaEntry(Base, MediaEntryMixin): """ TODO: Consider fetching the media_files using join @@ -445,7 +440,7 @@ class MediaEntry(Base, MediaEntryMixin): id = request.urlgen( "mediagoblin.federation.object", objectType=self.objectType, - uuid=self.uuid, + uuid=self.slug, qualified=True ) -- cgit v1.2.3 From 37f070b06786c20f320231bc467b35ccab6270dc Mon Sep 17 00:00:00 2001 From: xray7224 Date: Mon, 2 Sep 2013 16:23:40 +0100 Subject: Fixes problem where full URL was being used inplace of host --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index ca4efdd1..91efc0b6 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -141,7 +141,7 @@ class User(Base, UserMixin): user = { "id": "acct:{0}@{1}".format(self.username, request.host), "preferredUsername": self.username, - "displayName": "{0}@{1}".format(self.username, request.url), + "displayName": "{0}@{1}".format(self.username, request.host), "objectType": "person", "url": self.url, "summary": self.bio, -- cgit v1.2.3 From 98596dd072597c5d9c474e882f57407817d049f5 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Mon, 2 Sep 2013 19:25:24 +0100 Subject: Support for the comments endpoint --- mediagoblin/db/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 91efc0b6..4377f60f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -455,7 +455,9 @@ class MediaEntry(Base, MediaEntryMixin): }, "fullImage":{ "url": request.host_url + self.original_url[1:], - } + }, + "published": self.created.isoformat(), + "updated": self.created.isoformat(), } if show_comments: @@ -465,7 +467,13 @@ class MediaEntry(Base, MediaEntryMixin): # we only want to include replies if there are any. context["replies"] = { "totalItems": total, - "items": comments + "items": comments, + "url": request.urlgen( + "mediagoblin.federation.object.comments", + objectType=self.objectType, + uuid=self.slug, + qualified=True + ), } return context -- cgit v1.2.3 From a5682e89602ddc266d05c760a319d7647755f0b4 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Tue, 3 Sep 2013 17:17:07 +0100 Subject: Support some webfinger API's and real profile and /api/user// --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4377f60f..4f5182d6 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -148,7 +148,7 @@ class User(Base, UserMixin): "links": { "self": { "href": request.urlgen( - "mediagoblin.federation.profile", + "mediagoblin.federation.user.profile", username=self.username, qualified=True ), -- cgit v1.2.3 From c434fc31c9b4195dabfb9c323bf13aca3337e5f9 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 4 Sep 2013 16:32:49 +0100 Subject: Add static pump_io to API and fix problem where null appeared in profile --- mediagoblin/db/models.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 4f5182d6..cc22450f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -143,8 +143,10 @@ class User(Base, UserMixin): "preferredUsername": self.username, "displayName": "{0}@{1}".format(self.username, request.host), "objectType": "person", - "url": self.url, - "summary": self.bio, + "pump_io": { + "shared": False, + "followed": False, + }, "links": { "self": { "href": request.urlgen( @@ -169,6 +171,12 @@ class User(Base, UserMixin): }, }, } + + if self.bio: + user.update({"summary": self.bio}) + if self.url: + user.update({"url": self.url}) + return user class Client(Base): @@ -458,6 +466,9 @@ class MediaEntry(Base, MediaEntryMixin): }, "published": self.created.isoformat(), "updated": self.created.isoformat(), + "pump_io": { + "shared": False, + }, } if show_comments: -- cgit v1.2.3 From c894b4246a1211e7d8e63e7c51b8d7095482a10c Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 4 Sep 2013 19:34:29 +0100 Subject: Add basic comment support and flesh out some other endpoints --- mediagoblin/db/models.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index cc22450f..215e7552 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -445,15 +445,8 @@ class MediaEntry(Base, MediaEntryMixin): qualified=True ) - id = request.urlgen( - "mediagoblin.federation.object", - objectType=self.objectType, - uuid=self.slug, - qualified=True - ) - context = { - "id": id, + "id": self.id, "author": author.serialize(request), "displayName": self.title, "objectType": self.objectType, -- cgit v1.2.3 From 7810817caf73bcc0dcdfe1cec249c86e3e77c148 Mon Sep 17 00:00:00 2001 From: xray7224 Date: Thu, 10 Oct 2013 20:19:58 +0100 Subject: Refactors api uploading to media managers --- mediagoblin/db/models.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 215e7552..cc5d0afa 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -467,18 +467,16 @@ class MediaEntry(Base, MediaEntryMixin): if show_comments: comments = [comment.serialize(request) for comment in self.get_comments()] total = len(comments) - if total > 0: - # we only want to include replies if there are any. - context["replies"] = { - "totalItems": total, - "items": comments, - "url": request.urlgen( - "mediagoblin.federation.object.comments", - objectType=self.objectType, - uuid=self.slug, - qualified=True - ), - } + context["replies"] = { + "totalItems": total, + "items": comments, + "url": request.urlgen( + "mediagoblin.federation.object.comments", + objectType=self.objectType, + uuid=self.slug, + qualified=True + ), + } return context -- cgit v1.2.3 From 51ab51921e5104f1b71402d38928651562c7134a Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Fri, 11 Jul 2014 15:23:55 +0100 Subject: Add more tests for federation APIs --- mediagoblin/db/models.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index cc5d0afa..27ca74e0 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -446,9 +446,8 @@ class MediaEntry(Base, MediaEntryMixin): ) context = { - "id": self.id, + "id": self.id, "author": author.serialize(request), - "displayName": self.title, "objectType": self.objectType, "url": url, "image": { @@ -464,6 +463,15 @@ class MediaEntry(Base, MediaEntryMixin): }, } + if self.title: + context["displayName"] = self.title + + if self.description: + context["content"] = self.description + + if self.license: + context["license"] = self.license + if show_comments: comments = [comment.serialize(request) for comment in self.get_comments()] total = len(comments) @@ -478,7 +486,7 @@ class MediaEntry(Base, MediaEntryMixin): ), } - return context + return context class FileKeynames(Base): """ @@ -630,6 +638,7 @@ class MediaComment(Base, MediaCommentMixin): media = MediaEntry.query.filter_by(id=self.media_entry).first() author = self.get_author context = { + "id": self.id, "objectType": "comment", "content": self.content, "inReplyTo": media.serialize(request, show_comments=False), -- cgit v1.2.3 From 3c8bd177b24cbc53dba9ebc8a03f83370e409c4f Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Sat, 12 Jul 2014 08:42:39 +0100 Subject: Add test for API object endpoint --- mediagoblin/db/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 27ca74e0..0507161e 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -461,6 +461,17 @@ class MediaEntry(Base, MediaEntryMixin): "pump_io": { "shared": False, }, + "links": { + "self": { + "href": request.urlgen( + "mediagoblin.federation.object", + objectType=self.objectType, + slug=self.slug, + qualified=True + ), + }, + + } } if self.title: -- cgit v1.2.3 From d8f55f2b412507d4c75ebd249a824fdaee66c6dd Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 16 Jul 2014 17:59:03 +0100 Subject: Add unseralize for API objects --- mediagoblin/db/models.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 0507161e..8ea16b80 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -499,6 +499,19 @@ class MediaEntry(Base, MediaEntryMixin): return context + def unserialize(self, data): + """ Takes API objects and unserializes on existing MediaEntry """ + if "displayName" in data: + self.title = data["displayName"] + + if "content" in data: + self.description = data["content"] + + if "license" in data: + self.license = data["license"] + + return True + class FileKeynames(Base): """ keywords for various places. @@ -658,6 +671,24 @@ class MediaComment(Base, MediaCommentMixin): return context + def unserialize(self, data): + """ Takes API objects and unserializes on existing comment """ + # Do initial checks to verify the object is correct + required_attributes = ["content", "inReplyTo"] + for attr in required_attributes: + if attr not in data: + return False + + # Validate inReplyTo has ID + if "id" not in data["inReplyTo"]: + return False + + self.media_entry = data["inReplyTo"]["id"] + self.content = data["content"] + return True + + + class Collection(Base, CollectionMixin): """An 'album' or 'set' of media by a user. -- cgit v1.2.3 From a14d90c2db5ff96bdd72009a07f1afc0e8ef3595 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 21 Jul 2014 18:32:47 +0100 Subject: Switch from slug to ID and clean up style to conform to PEP-8 --- mediagoblin/db/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 8ea16b80..aaceb599 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -466,7 +466,7 @@ class MediaEntry(Base, MediaEntryMixin): "href": request.urlgen( "mediagoblin.federation.object", objectType=self.objectType, - slug=self.slug, + id=self.id, qualified=True ), }, @@ -492,7 +492,7 @@ class MediaEntry(Base, MediaEntryMixin): "url": request.urlgen( "mediagoblin.federation.object.comments", objectType=self.objectType, - uuid=self.slug, + id=self.id, qualified=True ), } -- cgit v1.2.3 From dc19e98d98bc53d983d2fab73be53cbf95b42ffa Mon Sep 17 00:00:00 2001 From: Tryggvi Bjorgvinsson Date: Sat, 19 Jul 2014 12:35:50 +0000 Subject: Add __unicode__ representation to Notification and MediaCommentMixin Instead of having __repr__ return a unicode object which it should not do, we use the __unicode__ method to allow use of Notification and MediaCommentMixin objects in unicode strings. --- mediagoblin/db/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index aaceb599..c2d101ac 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -820,6 +820,14 @@ class Notification(Base): } def __repr__(self): + return '<{klass} #{id}: {user}: {subject} ({seen})>'.format( + id=self.id, + klass=self.__class__.__name__, + user=self.user, + subject=getattr(self, 'subject', None), + seen='unseen' if not self.seen else 'seen') + + def __unicode__(self): return u'<{klass} #{id}: {user}: {subject} ({seen})>'.format( id=self.id, klass=self.__class__.__name__, -- cgit v1.2.3 From 7bfc81b21af65c91dcbd9d33deae2f020d8bbbee Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Fri, 25 Jul 2014 18:58:57 +0100 Subject: Fix #923 - add allow_admin to user_has_privilege decorator --- mediagoblin/db/models.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index c2d101ac..c6424e71 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -106,25 +106,26 @@ class User(Base, UserMixin): super(User, self).delete(**kwargs) _log.info('Deleted user "{0}" account'.format(self.username)) - def has_privilege(self,*priv_names): + def has_privilege(self, privilege, allow_admin=True): """ This method checks to make sure a user has all the correct privileges to access a piece of content. - :param priv_names A variable number of unicode objects which rep- - -resent the different privileges which may give - the user access to this content. If you pass - multiple arguments, the user will be granted - access if they have ANY of the privileges - passed. + :param privilege A unicode object which represent the different + privileges which may give the user access to + content. + + :param allow_admin If this is set to True the then if the user is + an admin, then this will always return True + even if the user hasn't been given the + privilege. (defaults to True) """ - if len(priv_names) == 1: - priv = Privilege.query.filter( - Privilege.privilege_name==priv_names[0]).one() - return (priv in self.all_privileges) - elif len(priv_names) > 1: - return self.has_privilege(priv_names[0]) or \ - self.has_privilege(*priv_names[1:]) + priv = Privilege.query.filter_by(privilege_name=privilege).one() + if priv in self.all_privileges: + return True + elif allow_admin and self.has_privilege(u'admin', allow_admin=False): + return True + return False def is_banned(self): -- cgit v1.2.3 From 5e5d445890c6c555dff48b1613c285da983d71c8 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Mon, 28 Jul 2014 23:36:39 +0100 Subject: Fix #927 - Clean up federation code after Elrond's review - Add json_error and use inplace of json_response where appropriate. - Add garbage_collection to config spec file. - Fix bugs in both garbage collection task and test - Handle /api/whoami when no user logged in and a test for such a case. - Validate ID is correct and user has comment privilege to comment. --- mediagoblin/db/models.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index c6424e71..b3f7e23d 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -683,8 +683,18 @@ class MediaComment(Base, MediaCommentMixin): # Validate inReplyTo has ID if "id" not in data["inReplyTo"]: return False + + # Validate that the ID is correct + try: + media_id = int(data["inReplyTo"]["id"]) + except ValueError: + return False + + media = MediaEntry.query.filter_by(id=media_id).first() + if media is None: + return False - self.media_entry = data["inReplyTo"]["id"] + self.media_entry = media.id self.content = data["content"] return True -- cgit v1.2.3 From bb12fb807e59cbe124c32c0b4fa2a74e0b81aade Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 7 Aug 2014 13:24:07 -0500 Subject: Add a new migration which removes/fixes the old migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous migration, as it turns out, was not needed, and there were many inconsistencies put in place by adding it. See issue #920. This commit sponsored by Gergő Tisza. Thank you! --- mediagoblin/db/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b3f7e23d..932ba074 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -58,7 +58,7 @@ class User(Base, UserMixin): __tablename__ = "core__users" id = Column(Integer, primary_key=True) - username = Column(Unicode, nullable=False, unique=True, index=True) + username = Column(Unicode, nullable=False, unique=True) # Note: no db uniqueness constraint on email because it's not # reliable (many email systems case insensitive despite against # the RFC) and because it would be a mess to implement at this -- cgit v1.2.3 From 9246a6ba89ab22a07e06b673e9eb0f135d2079a6 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Tue, 5 Aug 2014 22:04:50 +0100 Subject: Tidy up federation code and add tests to cover more of the APIs --- mediagoblin/db/models.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 932ba074..b910e522 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -439,18 +439,11 @@ class MediaEntry(Base, MediaEntryMixin): def serialize(self, request, show_comments=True): """ Unserialize MediaEntry to object """ author = self.get_uploader - url = request.urlgen( - "mediagoblin.user_pages.media_home", - user=author.username, - media=self.slug, - qualified=True - ) - context = { "id": self.id, "author": author.serialize(request), "objectType": self.objectType, - "url": url, + "url": self.url_for_self(request.urlgen), "image": { "url": request.host_url + self.thumb_url[1:], }, @@ -683,13 +676,13 @@ class MediaComment(Base, MediaCommentMixin): # Validate inReplyTo has ID if "id" not in data["inReplyTo"]: return False - + # Validate that the ID is correct try: media_id = int(data["inReplyTo"]["id"]) except ValueError: return False - + media = MediaEntry.query.filter_by(id=media_id).first() if media is None: return False -- cgit v1.2.3 From 4f1a5148cb9b64f7086d047359f612a84f3d4c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odin=20H=C3=B8rthe=20Omdal?= Date: Sun, 7 Sep 2014 12:56:13 +0200 Subject: Add __repr__ for Collection and CollectionItem --- mediagoblin/db/models.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'mediagoblin/db/models.py') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index b910e522..2ff30d22 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -20,7 +20,6 @@ TODO: indexes on foreignkeys, where useful. import logging import datetime -import base64 from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \ Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \ @@ -727,6 +726,14 @@ class Collection(Base, CollectionMixin): return CollectionItem.query.filter_by( collection=self.id).order_by(order_col) + def __repr__(self): + safe_title = self.title.encode('ascii', 'replace') + return '<{classname} #{id}: {title} by {creator}>'.format( + id=self.id, + classname=self.__class__.__name__, + creator=self.creator, + title=safe_title) + class CollectionItem(Base, CollectionItemMixin): __tablename__ = "core__collection_items" @@ -756,6 +763,13 @@ class CollectionItem(Base, CollectionItemMixin): """A dict like view on this object""" return DictReadAttrProxy(self) + def __repr__(self): + return '<{classname} #{id}: Entry {entry} in {collection}>'.format( + id=self.id, + classname=self.__class__.__name__, + collection=self.collection, + entry=self.media_entry) + class ProcessingMetaData(Base): __tablename__ = 'core__processing_metadata' -- cgit v1.2.3