{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/51590109","id":51590109,"diff_hunk":"@@ -24,32 +124,35 @@ def award_program_certificates(username):\n     This task may also be invoked independently of any course completion status\n     change - for example, to backpopulate missing program credentials for a\n     user.\n-\n-    TODO: this is shelled out and incomplete for now.\n     \"\"\"\n \n+    student = User.objects.get(username=username)\n+\n     # fetch the set of all course runs for which the user has earned a certificate\n-    LOGGER.debug('fetching all completed courses for user %s', username)\n-    user_certs = get_certificates_for_user(username)\n-    course_certs = [\n-        {'course_id': uc['course_id'], 'mode': uc['mode']}\n-        for uc in user_certs\n-        if uc['status'] in ('downloadable', 'generating')\n-    ]\n+    course_certs = get_completed_courses(student)\n \n     # invoke the Programs API completion check endpoint to identify any programs\n     # that are satisfied by these course completions\n-    LOGGER.debug('determining completed programs for courses: %r', course_certs)\n-    program_ids = []  # TODO\n+    programs_client = get_api_client(ProgramsApiConfig.current(), student)\n+    program_ids = get_completed_programs(programs_client, course_certs)\n \n     # determine which program certificates the user has already been awarded, if\n     # any, and remove those, since they already exist.\n-    LOGGER.debug('fetching existing program certificates for %s', username)\n-    existing_program_ids = []  # TODO\n+    existing_program_ids = get_awarded_certificate_programs(student)\n+\n     new_program_ids = list(set(program_ids) - set(existing_program_ids))\n \n     # generate a new certificate for each of the remaining programs.\n-    LOGGER.debug('generating new program certificates for %s in programs: %r', username, new_program_ids)\n-    for program_id in new_program_ids:\n-        LOGGER.debug('calling credentials service to issue certificate for user %s in program %s', username, program_id)\n-        # TODO\n+    if new_program_ids:\n+        LOGGER.debug('generating new program certificates for %s in programs: %r', username, new_program_ids)\n+        credentials_client = get_api_client(\n+            CredentialsApiConfig.current(),\n+            User.objects.get(username='FIXME-NO-SERVICE-USER')\n+        )\n+        for program_id in new_program_ids:\n+            LOGGER.debug(\n+                'calling credentials service to issue certificate for user %s in program %s',\n+                username,\n+                program_id,\n+            )\n+            award_program_certificate(credentials_client, student, program_id)","path":"openedx/core/djangoapps/programs/tasks.py","position":166,"original_position":166,"commit_id":"d59c4fe116a054c8de5aced061c1bda2f1e40400","original_commit_id":"d59c4fe116a054c8de5aced061c1bda2f1e40400","user":{"login":"rlucioni","id":969289,"avatar_url":"https://avatars.githubusercontent.com/u/969289?v=3","gravatar_id":"","url":"https://api.github.com/users/rlucioni","html_url":"https://github.com/rlucioni","followers_url":"https://api.github.com/users/rlucioni/followers","following_url":"https://api.github.com/users/rlucioni/following{/other_user}","gists_url":"https://api.github.com/users/rlucioni/gists{/gist_id}","starred_url":"https://api.github.com/users/rlucioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlucioni/subscriptions","organizations_url":"https://api.github.com/users/rlucioni/orgs","repos_url":"https://api.github.com/users/rlucioni/repos","events_url":"https://api.github.com/users/rlucioni/events{/privacy}","received_events_url":"https://api.github.com/users/rlucioni/received_events","type":"User","site_admin":false},"body":"The student's username is provided as an argument to this task. I'd pass that along here instead of pulling the username off the User object.","created_at":"2016-02-02T16:12:29Z","updated_at":"2016-02-02T16:12:29Z","html_url":"https://github.com/edx/edx-platform/pull/11341#discussion_r51590109","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/11341","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/51590109"},"html":{"href":"https://github.com/edx/edx-platform/pull/11341#discussion_r51590109"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11341"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/11341","id":57270708,"html_url":"https://github.com/edx/edx-platform/pull/11341","diff_url":"https://github.com/edx/edx-platform/pull/11341.diff","patch_url":"https://github.com/edx/edx-platform/pull/11341.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/11341","number":11341,"state":"open","locked":false,"title":"Implement celery task to award program certs.","user":{"login":"jimabramson","id":1349368,"avatar_url":"https://avatars.githubusercontent.com/u/1349368?v=3","gravatar_id":"","url":"https://api.github.com/users/jimabramson","html_url":"https://github.com/jimabramson","followers_url":"https://api.github.com/users/jimabramson/followers","following_url":"https://api.github.com/users/jimabramson/following{/other_user}","gists_url":"https://api.github.com/users/jimabramson/gists{/gist_id}","starred_url":"https://api.github.com/users/jimabramson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimabramson/subscriptions","organizations_url":"https://api.github.com/users/jimabramson/orgs","repos_url":"https://api.github.com/users/jimabramson/repos","events_url":"https://api.github.com/users/jimabramson/events{/privacy}","received_events_url":"https://api.github.com/users/jimabramson/received_events","type":"User","site_admin":false},"body":"ECOM-3354","created_at":"2016-01-26T20:55:45Z","updated_at":"2016-02-02T16:12:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"93ceae251c7867d16a1feaddd1e68e4a51ed7832","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/11341/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/11341/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/11341/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/d59c4fe116a054c8de5aced061c1bda2f1e40400","head":{"label":"edx:jsa/ecom-3354","ref":"jsa/ecom-3354","sha":"d59c4fe116a054c8de5aced061c1bda2f1e40400","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":"The Open edX platform, the software that powers edX!","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}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-02-02T14:33:47Z","pushed_at":"2016-02-02T15:49:45Z","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://open.edx.org/","size":681034,"stargazers_count":2375,"watchers_count":2375,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1447,"mirror_url":null,"open_issues_count":155,"forks":1447,"open_issues":155,"watchers":2375,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"5a8b3d025659053dcc000043eccf878cf0098543","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":"The Open edX platform, the software that powers edX!","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}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-02-02T14:33:47Z","pushed_at":"2016-02-02T15:49:45Z","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://open.edx.org/","size":681034,"stargazers_count":2375,"watchers_count":2375,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1447,"mirror_url":null,"open_issues_count":155,"forks":1447,"open_issues":155,"watchers":2375,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11341"},"html":{"href":"https://github.com/edx/edx-platform/pull/11341"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/11341"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/11341/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/11341/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/11341/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/d59c4fe116a054c8de5aced061c1bda2f1e40400"}}}}