{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/27527465","id":27527465,"diff_hunk":"@@ -320,21 +343,50 @@ def refresh_children(self, request=None, suffix=None):  # pylint: disable=unused\n         the version number of the libraries used, so we easily determine if\n         this block is up to date or not.\n         \"\"\"\n-        lib_tools = self.runtime.service(self, 'library_tools')\n-        if not lib_tools:\n-            # This error is diagnostic. The user won't see it, but it may be helpful\n-            # during debugging.\n-            return Response(_(u\"Course does not support Library tools.\"), status=400)\n-        user_service = self.runtime.service(self, 'user')\n+        lib_tools = self.get_tools()\n         user_perms = self.runtime.service(self, 'studio_user_permissions')\n-        if user_service:\n-            # May be None when creating bok choy test fixtures\n-            user_id = user_service.get_current_user().opt_attrs.get('edx-platform.user_id', None)\n-        else:\n-            user_id = None\n+        user_id = self.get_user_id()\n         lib_tools.update_children(self, user_id, user_perms)\n         return Response()\n \n+    # pylint: disable=unused-argument\n+    def studio_post_duplicate(self, store, parent_usage_key, source_block):\n+        \"\"\"\n+        Used by the studio after basic duplication of a source block. We handle the children\n+        ourselves, because we have to properly reference the library upstream and set the overrides.\n+\n+        Otherwise we'll end up losing data on the next refresh.\n+        \"\"\"\n+        # The first task will be to refresh our copy of the library to generate the children.\n+        # We must do this at the currently set version of the library block. Otherwise we may not have\n+        # exactly the same children-- someone may be duplicating an out of date block, after all.\n+        lib_tools = self.get_tools()\n+        user_id = self.get_user_id()\n+        user_perms = self.runtime.service(self, 'studio_user_permissions')\n+        # pylint: disable=no-member\n+        lib_tools.update_children(self, user_id, user_perms, version=self.source_library_version)\n+\n+        # Copy over any overridden settings the course author may have applied to the blocks.\n+        def copy_overrides(source, dest):\n+            \"\"\"\n+            Copy any overrides the user has made on blocks in this library.\n+            \"\"\"\n+            for field_name in source.fields.keys():\n+                field = dest.fields[field_name]\n+                if field.scope == Scope.settings and field.is_set_on(source):\n+                    setattr(dest, field_name, getattr(source, field_name))\n+            if source.has_children:\n+                source_children = [store.get_item(source_key) for source_key in source.children]\n+                dest_children = [store.get_item(dest_key) for dest_key in dest.children]","path":"common/lib/xmodule/xmodule/library_content_module.py","position":79,"original_position":79,"commit_id":"21ee9d59edeaf44fdbe44881d2a6f539678a9531","original_commit_id":"21ee9d59edeaf44fdbe44881d2a6f539678a9531","user":{"login":"bradenmacdonald","id":945577,"avatar_url":"https://avatars.githubusercontent.com/u/945577?v=3","gravatar_id":"","url":"https://api.github.com/users/bradenmacdonald","html_url":"https://github.com/bradenmacdonald","followers_url":"https://api.github.com/users/bradenmacdonald/followers","following_url":"https://api.github.com/users/bradenmacdonald/following{/other_user}","gists_url":"https://api.github.com/users/bradenmacdonald/gists{/gist_id}","starred_url":"https://api.github.com/users/bradenmacdonald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradenmacdonald/subscriptions","organizations_url":"https://api.github.com/users/bradenmacdonald/orgs","repos_url":"https://api.github.com/users/bradenmacdonald/repos","events_url":"https://api.github.com/users/bradenmacdonald/events{/privacy}","received_events_url":"https://api.github.com/users/bradenmacdonald/received_events","type":"User","site_admin":false},"body":"Nit: Probably better to use `self.runtime.get_block(blah_key)` here, since that is the pure XBlock API.","created_at":"2015-03-31T21:57:42Z","updated_at":"2015-03-31T21:57:42Z","html_url":"https://github.com/edx/edx-platform/pull/7482#discussion_r27527465","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/7482","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/27527465"},"html":{"href":"https://github.com/edx/edx-platform/pull/7482#discussion_r27527465"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7482"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/7482","id":31966393,"html_url":"https://github.com/edx/edx-platform/pull/7482","diff_url":"https://github.com/edx/edx-platform/pull/7482.diff","patch_url":"https://github.com/edx/edx-platform/pull/7482.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/7482","number":7482,"state":"open","locked":false,"title":"Fix duplication of Randomized Content Blocks","user":{"login":"Kelketek","id":1099483,"avatar_url":"https://avatars.githubusercontent.com/u/1099483?v=3","gravatar_id":"","url":"https://api.github.com/users/Kelketek","html_url":"https://github.com/Kelketek","followers_url":"https://api.github.com/users/Kelketek/followers","following_url":"https://api.github.com/users/Kelketek/following{/other_user}","gists_url":"https://api.github.com/users/Kelketek/gists{/gist_id}","starred_url":"https://api.github.com/users/Kelketek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kelketek/subscriptions","organizations_url":"https://api.github.com/users/Kelketek/orgs","repos_url":"https://api.github.com/users/Kelketek/repos","events_url":"https://api.github.com/users/Kelketek/events{/privacy}","received_events_url":"https://api.github.com/users/Kelketek/received_events","type":"User","site_admin":false},"body":"**Description**: Fixes data loss issues when copying a Randomized Content Block\r\n**Jira Ticket**: [SOL-549](https://openedx.atlassian.net/browse/SOL-549)\r\n**Partner Information**: 3rd party-hosted open edX instance, for an edX solutions client.","created_at":"2015-03-25T21:11:31Z","updated_at":"2015-03-31T21:57:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d93ca32103662b19858dc2d332dc204e01386f4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/7482/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/7482/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/7482/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/21ee9d59edeaf44fdbe44881d2a6f539678a9531","head":{"label":"open-craft:fix_duplicate_rcb","ref":"fix_duplicate_rcb","sha":"21ee9d59edeaf44fdbe44881d2a6f539678a9531","user":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"repo":{"id":19940883,"name":"edx-platform","full_name":"open-craft/edx-platform","owner":{"login":"open-craft","id":7414786,"avatar_url":"https://avatars.githubusercontent.com/u/7414786?v=3","gravatar_id":"","url":"https://api.github.com/users/open-craft","html_url":"https://github.com/open-craft","followers_url":"https://api.github.com/users/open-craft/followers","following_url":"https://api.github.com/users/open-craft/following{/other_user}","gists_url":"https://api.github.com/users/open-craft/gists{/gist_id}","starred_url":"https://api.github.com/users/open-craft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/open-craft/subscriptions","organizations_url":"https://api.github.com/users/open-craft/orgs","repos_url":"https://api.github.com/users/open-craft/repos","events_url":"https://api.github.com/users/open-craft/events{/privacy}","received_events_url":"https://api.github.com/users/open-craft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/open-craft/edx-platform","description":"the edX learning management system (LMS) and course authoring tool, Studio","fork":true,"url":"https://api.github.com/repos/open-craft/edx-platform","forks_url":"https://api.github.com/repos/open-craft/edx-platform/forks","keys_url":"https://api.github.com/repos/open-craft/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/open-craft/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/open-craft/edx-platform/teams","hooks_url":"https://api.github.com/repos/open-craft/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/open-craft/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/open-craft/edx-platform/events","assignees_url":"https://api.github.com/repos/open-craft/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/open-craft/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/open-craft/edx-platform/tags","blobs_url":"https://api.github.com/repos/open-craft/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/open-craft/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/open-craft/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/open-craft/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/open-craft/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/open-craft/edx-platform/languages","stargazers_url":"https://api.github.com/repos/open-craft/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/open-craft/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/open-craft/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/open-craft/edx-platform/subscription","commits_url":"https://api.github.com/repos/open-craft/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/open-craft/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/open-craft/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/open-craft/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/open-craft/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/open-craft/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/open-craft/edx-platform/merges","archive_url":"https://api.github.com/repos/open-craft/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/open-craft/edx-platform/downloads","issues_url":"https://api.github.com/repos/open-craft/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/open-craft/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/open-craft/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/open-craft/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/open-craft/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/open-craft/edx-platform/releases{/id}","created_at":"2014-05-19T12:28:25Z","updated_at":"2014-12-10T07:44:28Z","pushed_at":"2015-03-31T18:40:49Z","git_url":"git://github.com/open-craft/edx-platform.git","ssh_url":"git@github.com:open-craft/edx-platform.git","clone_url":"https://github.com/open-craft/edx-platform.git","svn_url":"https://github.com/open-craft/edx-platform","homepage":"http://code.edx.org/","size":408083,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"c5e198f754bda1e4f1f283972901606e977ef40b","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-03-31T19:19:45Z","pushed_at":"2015-03-31T21:55:33Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://openedx.org/","size":1868224,"stargazers_count":1833,"watchers_count":1833,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1032,"mirror_url":null,"open_issues_count":137,"forks":1032,"open_issues":137,"watchers":1833,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7482"},"html":{"href":"https://github.com/edx/edx-platform/pull/7482"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7482"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7482/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7482/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7482/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/21ee9d59edeaf44fdbe44881d2a6f539678a9531"}}}}