{"action":"created","comment":{"url":"https://api.github.com/repos/superdesk/superdesk/pulls/comments/34849686","id":34849686,"diff_hunk":"@@ -137,14 +130,39 @@ def on_fetched(self, result):\n                 url_parts.query\n             )\n \n+    def _process_fetched_object(self, document):\n+        \"\"\"Does some processing on the raw document fetched from database.\n+\n+        It sets the item's `uri` field and removes all the fields added by the\n+        `Eve` framework that are not part of the NINJS standard (except for\n+        the HATEOAS `_links` object).\n+        It also sets the URLs for all externally referenced media content.\n+\n+        :param dict document: MongoDB document to process\n+        \"\"\"\n+        document['uri'] = self._get_uri(document)\n+\n+        for field_name in ('_id', '_etag', '_created', '_updated'):\n+            document.pop(field_name, None)\n+\n+        if 'renditions' in document:\n+            for k, v in document['renditions'].items():\n+                if 'media' in v:\n+                    v['href'] = url_for_media(v['media'])\n+\n     def _get_uri(self, document):\n         \"\"\"Return the given document's `uri`.\n \n         :param dict document: MongoDB document fetched from database\n         \"\"\"\n+        if document.get('type') == 'composite':\n+            endpoint_name = 'packages'\n+        else:\n+            endpoint_name = 'items'\n+\n         resource_url = '{api_url}/{endpoint}/'.format(\n             api_url=app.config['PUBLICAPI_URL'],\n-            endpoint=app.config['URLS'][self.datasource]\n+            endpoint=app.config['URLS'][endpoint_name]","path":"server/publicapi/items/service.py","position":81,"original_position":81,"commit_id":"c5886d4be1d9753a703bc243ed75ea4235018ff9","original_commit_id":"c5886d4be1d9753a703bc243ed75ea4235018ff9","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"body":"**Explanation:** `self.datasource` is not used anymore, because `PackagesService` might use this method to generate links for the _items_ it references, resulting in invalid URLs (i.e. with correct item ID, but using the `/packages` endpoint instead of  `/items`).","created_at":"2015-07-16T23:29:50Z","updated_at":"2015-07-16T23:29:50Z","html_url":"https://github.com/superdesk/superdesk/pull/846#discussion_r34849686","pull_request_url":"https://api.github.com/repos/superdesk/superdesk/pulls/846","_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/comments/34849686"},"html":{"href":"https://github.com/superdesk/superdesk/pull/846#discussion_r34849686"},"pull_request":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/846"}}},"pull_request":{"url":"https://api.github.com/repos/superdesk/superdesk/pulls/846","id":40186932,"html_url":"https://github.com/superdesk/superdesk/pull/846","diff_url":"https://github.com/superdesk/superdesk/pull/846.diff","patch_url":"https://github.com/superdesk/superdesk/pull/846.patch","issue_url":"https://api.github.com/repos/superdesk/superdesk/issues/846","number":846,"state":"open","locked":false,"title":"Fix fetching packages from public API using demo data","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"body":"Resolves [SD-2720](https://dev.sourcefabric.org/browse/SD-2720).\r\n\r\nThings changed:\r\n* Change demo data so that composite items only contain references to associated objects and not the objects themselves.\r\n* Fix an issue with `uri` field generation for associated objects.\r\n* Add/update docstrings, add quite a few tests that were missing.\r\n","created_at":"2015-07-16T23:24:15Z","updated_at":"2015-07-16T23:29:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0b95e4acf44173f1049675f380ed1fee7133072","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/superdesk/superdesk/pulls/846/commits","review_comments_url":"https://api.github.com/repos/superdesk/superdesk/pulls/846/comments","review_comment_url":"https://api.github.com/repos/superdesk/superdesk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/superdesk/superdesk/issues/846/comments","statuses_url":"https://api.github.com/repos/superdesk/superdesk/statuses/c5886d4be1d9753a703bc243ed75ea4235018ff9","head":{"label":"plamut:sd-2720","ref":"sd-2720","sha":"c5886d4be1d9753a703bc243ed75ea4235018ff9","user":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"repo":{"id":30860876,"name":"superdesk","full_name":"plamut/superdesk","owner":{"login":"plamut","id":1235663,"avatar_url":"https://avatars.githubusercontent.com/u/1235663?v=3","gravatar_id":"","url":"https://api.github.com/users/plamut","html_url":"https://github.com/plamut","followers_url":"https://api.github.com/users/plamut/followers","following_url":"https://api.github.com/users/plamut/following{/other_user}","gists_url":"https://api.github.com/users/plamut/gists{/gist_id}","starred_url":"https://api.github.com/users/plamut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plamut/subscriptions","organizations_url":"https://api.github.com/users/plamut/orgs","repos_url":"https://api.github.com/users/plamut/repos","events_url":"https://api.github.com/users/plamut/events{/privacy}","received_events_url":"https://api.github.com/users/plamut/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/plamut/superdesk","description":"","fork":true,"url":"https://api.github.com/repos/plamut/superdesk","forks_url":"https://api.github.com/repos/plamut/superdesk/forks","keys_url":"https://api.github.com/repos/plamut/superdesk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plamut/superdesk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plamut/superdesk/teams","hooks_url":"https://api.github.com/repos/plamut/superdesk/hooks","issue_events_url":"https://api.github.com/repos/plamut/superdesk/issues/events{/number}","events_url":"https://api.github.com/repos/plamut/superdesk/events","assignees_url":"https://api.github.com/repos/plamut/superdesk/assignees{/user}","branches_url":"https://api.github.com/repos/plamut/superdesk/branches{/branch}","tags_url":"https://api.github.com/repos/plamut/superdesk/tags","blobs_url":"https://api.github.com/repos/plamut/superdesk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plamut/superdesk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plamut/superdesk/git/refs{/sha}","trees_url":"https://api.github.com/repos/plamut/superdesk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plamut/superdesk/statuses/{sha}","languages_url":"https://api.github.com/repos/plamut/superdesk/languages","stargazers_url":"https://api.github.com/repos/plamut/superdesk/stargazers","contributors_url":"https://api.github.com/repos/plamut/superdesk/contributors","subscribers_url":"https://api.github.com/repos/plamut/superdesk/subscribers","subscription_url":"https://api.github.com/repos/plamut/superdesk/subscription","commits_url":"https://api.github.com/repos/plamut/superdesk/commits{/sha}","git_commits_url":"https://api.github.com/repos/plamut/superdesk/git/commits{/sha}","comments_url":"https://api.github.com/repos/plamut/superdesk/comments{/number}","issue_comment_url":"https://api.github.com/repos/plamut/superdesk/issues/comments{/number}","contents_url":"https://api.github.com/repos/plamut/superdesk/contents/{+path}","compare_url":"https://api.github.com/repos/plamut/superdesk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plamut/superdesk/merges","archive_url":"https://api.github.com/repos/plamut/superdesk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plamut/superdesk/downloads","issues_url":"https://api.github.com/repos/plamut/superdesk/issues{/number}","pulls_url":"https://api.github.com/repos/plamut/superdesk/pulls{/number}","milestones_url":"https://api.github.com/repos/plamut/superdesk/milestones{/number}","notifications_url":"https://api.github.com/repos/plamut/superdesk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plamut/superdesk/labels{/name}","releases_url":"https://api.github.com/repos/plamut/superdesk/releases{/id}","created_at":"2015-02-16T09:09:52Z","updated_at":"2015-07-15T11:40:47Z","pushed_at":"2015-07-16T23:20:28Z","git_url":"git://github.com/plamut/superdesk.git","ssh_url":"git@github.com:plamut/superdesk.git","clone_url":"https://github.com/plamut/superdesk.git","svn_url":"https://github.com/plamut/superdesk","homepage":null,"size":55193,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"superdesk:master","ref":"master","sha":"ef65d7829da4b114163dcd44fb7d824e72ea803e","user":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"repo":{"id":23570030,"name":"superdesk","full_name":"superdesk/superdesk","owner":{"login":"superdesk","id":5527298,"avatar_url":"https://avatars.githubusercontent.com/u/5527298?v=3","gravatar_id":"","url":"https://api.github.com/users/superdesk","html_url":"https://github.com/superdesk","followers_url":"https://api.github.com/users/superdesk/followers","following_url":"https://api.github.com/users/superdesk/following{/other_user}","gists_url":"https://api.github.com/users/superdesk/gists{/gist_id}","starred_url":"https://api.github.com/users/superdesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superdesk/subscriptions","organizations_url":"https://api.github.com/users/superdesk/orgs","repos_url":"https://api.github.com/users/superdesk/repos","events_url":"https://api.github.com/users/superdesk/events{/privacy}","received_events_url":"https://api.github.com/users/superdesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/superdesk/superdesk","description":"The open source end-to-end news platform.","fork":false,"url":"https://api.github.com/repos/superdesk/superdesk","forks_url":"https://api.github.com/repos/superdesk/superdesk/forks","keys_url":"https://api.github.com/repos/superdesk/superdesk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/superdesk/superdesk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/superdesk/superdesk/teams","hooks_url":"https://api.github.com/repos/superdesk/superdesk/hooks","issue_events_url":"https://api.github.com/repos/superdesk/superdesk/issues/events{/number}","events_url":"https://api.github.com/repos/superdesk/superdesk/events","assignees_url":"https://api.github.com/repos/superdesk/superdesk/assignees{/user}","branches_url":"https://api.github.com/repos/superdesk/superdesk/branches{/branch}","tags_url":"https://api.github.com/repos/superdesk/superdesk/tags","blobs_url":"https://api.github.com/repos/superdesk/superdesk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/superdesk/superdesk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/superdesk/superdesk/git/refs{/sha}","trees_url":"https://api.github.com/repos/superdesk/superdesk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/superdesk/superdesk/statuses/{sha}","languages_url":"https://api.github.com/repos/superdesk/superdesk/languages","stargazers_url":"https://api.github.com/repos/superdesk/superdesk/stargazers","contributors_url":"https://api.github.com/repos/superdesk/superdesk/contributors","subscribers_url":"https://api.github.com/repos/superdesk/superdesk/subscribers","subscription_url":"https://api.github.com/repos/superdesk/superdesk/subscription","commits_url":"https://api.github.com/repos/superdesk/superdesk/commits{/sha}","git_commits_url":"https://api.github.com/repos/superdesk/superdesk/git/commits{/sha}","comments_url":"https://api.github.com/repos/superdesk/superdesk/comments{/number}","issue_comment_url":"https://api.github.com/repos/superdesk/superdesk/issues/comments{/number}","contents_url":"https://api.github.com/repos/superdesk/superdesk/contents/{+path}","compare_url":"https://api.github.com/repos/superdesk/superdesk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/superdesk/superdesk/merges","archive_url":"https://api.github.com/repos/superdesk/superdesk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/superdesk/superdesk/downloads","issues_url":"https://api.github.com/repos/superdesk/superdesk/issues{/number}","pulls_url":"https://api.github.com/repos/superdesk/superdesk/pulls{/number}","milestones_url":"https://api.github.com/repos/superdesk/superdesk/milestones{/number}","notifications_url":"https://api.github.com/repos/superdesk/superdesk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/superdesk/superdesk/labels{/name}","releases_url":"https://api.github.com/repos/superdesk/superdesk/releases{/id}","created_at":"2014-09-02T07:56:17Z","updated_at":"2015-07-15T09:21:30Z","pushed_at":"2015-07-16T23:24:15Z","git_url":"git://github.com/superdesk/superdesk.git","ssh_url":"git@github.com:superdesk/superdesk.git","clone_url":"https://github.com/superdesk/superdesk.git","svn_url":"https://github.com/superdesk/superdesk","homepage":"","size":64337,"stargazers_count":14,"watchers_count":14,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":32,"mirror_url":null,"open_issues_count":11,"forks":32,"open_issues":11,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/846"},"html":{"href":"https://github.com/superdesk/superdesk/pull/846"},"issue":{"href":"https://api.github.com/repos/superdesk/superdesk/issues/846"},"comments":{"href":"https://api.github.com/repos/superdesk/superdesk/issues/846/comments"},"review_comments":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/846/comments"},"review_comment":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/superdesk/superdesk/pulls/846/commits"},"statuses":{"href":"https://api.github.com/repos/superdesk/superdesk/statuses/c5886d4be1d9753a703bc243ed75ea4235018ff9"}}}}