diff options
author | Jessica Tallon <jessica@megworld.co.uk> | 2014-12-16 12:05:18 +0000 |
---|---|---|
committer | Jessica Tallon <jessica@megworld.co.uk> | 2014-12-16 12:05:18 +0000 |
commit | 9e715bb07f9a09f5594ed865d3dbd204c71feb50 (patch) | |
tree | 822f4d098b5f1f98caf9217166d491199d69e450 /mediagoblin/db/models.py | |
parent | 9a51bf1ebcee16169c7dc8ab950b23f7b4a06a22 (diff) | |
download | mediagoblin-9e715bb07f9a09f5594ed865d3dbd204c71feb50.tar.lz mediagoblin-9e715bb07f9a09f5594ed865d3dbd204c71feb50.tar.xz mediagoblin-9e715bb07f9a09f5594ed865d3dbd204c71feb50.zip |
Fix #1077 - Fix updating comment via API and add test
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r-- | mediagoblin/db/models.py | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 440aa682..fba58ca8 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -803,31 +803,25 @@ class MediaComment(Base, MediaCommentMixin): def unserialize(self, data, request): """ 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: + # Handle changing the reply ID + if "inReplyTo" in data: + # Validate that the ID is correct + try: + media_id = int(extract_url_arguments( + url=data["inReplyTo"]["id"], + urlmap=request.app.url_map + )["id"]) + except ValueError: return False - # Validate inReplyTo has ID - if "id" not in data["inReplyTo"]: - return False + media = MediaEntry.query.filter_by(id=media_id).first() + if media is None: + return False - # Validate that the ID is correct - try: - media_id = int(extract_url_arguments( - url=data["inReplyTo"]["id"], - urlmap=request.app.url_map - )["id"]) - except ValueError: - return False - - media = MediaEntry.query.filter_by(id=media_id).first() - if media is None: - return False - - self.media_entry = media.id - self.content = data["content"] + self.media_entry = media.id + + if "content" in data: + self.content = data["content"] if "location" in data: Location.create(data["location"], self) |