{"action":"created","comment":{"url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments/333653292","pull_request_review_id":300243878,"id":333653292,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMzMzY1MzI5Mg==","diff_hunk":"@@ -0,0 +1,25 @@\n+class Policies::ScriptActivity\n+  def self.completed?(user, script)\n+    return false unless user\n+    return false unless script\n+    user_script = user.user_scripts.find_by(script: script)\n+    return false unless user_script\n+    !!user_script.completed_at || user.completed_progression_levels?(script)\n+  end\n+\n+  def self.passed_any_level?(user, script)\n+    user_levels = UserLevels.\n+      where(user: user, script: script).\n+      index_by(&:level_id)\n+\n+    script.script_levels.detect do |script_level|\n+      user_level = user_levels[script_level.level_id]\n+      is_passed = (user_level && user_level.passing?)\n+      script_level.valid_progression_level? && is_passed\n+    end\n+  end\n+\n+  def self.not_started?(user, script)\n+    !completed?(user, script) && !passed_any_level?(user, script)","path":"dashboard/lib/policies/script_activity.rb","position":23,"original_position":23,"commit_id":"bfb509e42afd907082712a6cc55c65df5939208d","original_commit_id":"bfb509e42afd907082712a6cc55c65df5939208d","user":{"login":"Hamms","id":244100,"node_id":"MDQ6VXNlcjI0NDEwMA==","avatar_url":"https://avatars0.githubusercontent.com/u/244100?v=4","gravatar_id":"","url":"https://api.github.com/users/Hamms","html_url":"https://github.com/Hamms","followers_url":"https://api.github.com/users/Hamms/followers","following_url":"https://api.github.com/users/Hamms/following{/other_user}","gists_url":"https://api.github.com/users/Hamms/gists{/gist_id}","starred_url":"https://api.github.com/users/Hamms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hamms/subscriptions","organizations_url":"https://api.github.com/users/Hamms/orgs","repos_url":"https://api.github.com/users/Hamms/repos","events_url":"https://api.github.com/users/Hamms/events{/privacy}","received_events_url":"https://api.github.com/users/Hamms/received_events","type":"User","site_admin":false},"body":"The problem I've run into before is that the internal logic of the Policy Object becomes cleaner, but calling it turns from \r\n\r\n```ruby\r\nPolicies::ScriptActivity.not_started?(user, script)\r\n```\r\n\r\ninto\r\n\r\n```ruby\r\nPolicies::ScriptActivity.new(user, script).not_started?\r\n```\r\n\r\nWhich is only slightly less clean for this case, but is a pattern that can become unwieldy in other cases. See https://github.com/code-dot-org/code-dot-org/pull/30752 for more discussion.","created_at":"2019-10-10T17:48:22Z","updated_at":"2019-10-10T17:48:22Z","html_url":"https://github.com/code-dot-org/code-dot-org/pull/31004#discussion_r333653292","pull_request_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments/333653292"},"html":{"href":"https://github.com/code-dot-org/code-dot-org/pull/31004#discussion_r333653292"},"pull_request":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004"}},"in_reply_to_id":332754395},"pull_request":{"url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004","id":322301553,"node_id":"MDExOlB1bGxSZXF1ZXN0MzIyMzAxNTUz","html_url":"https://github.com/code-dot-org/code-dot-org/pull/31004","diff_url":"https://github.com/code-dot-org/code-dot-org/pull/31004.diff","patch_url":"https://github.com/code-dot-org/code-dot-org/pull/31004.patch","issue_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/31004","number":31004,"state":"open","locked":false,"title":"extract script activity methods from user.rb onto policy and query objects","user":{"login":"Hamms","id":244100,"node_id":"MDQ6VXNlcjI0NDEwMA==","avatar_url":"https://avatars0.githubusercontent.com/u/244100?v=4","gravatar_id":"","url":"https://api.github.com/users/Hamms","html_url":"https://github.com/Hamms","followers_url":"https://api.github.com/users/Hamms/followers","following_url":"https://api.github.com/users/Hamms/following{/other_user}","gists_url":"https://api.github.com/users/Hamms/gists{/gist_id}","starred_url":"https://api.github.com/users/Hamms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hamms/subscriptions","organizations_url":"https://api.github.com/users/Hamms/orgs","repos_url":"https://api.github.com/users/Hamms/repos","events_url":"https://api.github.com/users/Hamms/events{/privacy}","received_events_url":"https://api.github.com/users/Hamms/received_events","type":"User","site_admin":false},"body":"# Description\r\n\r\nMove all methods related to retrieving scripts for which the user either does or does not have activity onto a new `Queries::ScriptActivity` object, and all methods related to identifying activity state for a given user and script onto a new `Policies::ScriptActivity` object.\r\n\r\n<!--\r\n  A summary of the change, including any relevant motivation and context.\r\n\r\n  If relevant, include a description both of the existing behavior and of the new behavior.\r\n-->\r\n\r\n<!--\r\n  Other aspects to consider. uncomment and add detail for any that seem necessary:\r\n-->\r\n\r\n### Background\r\n\r\nPart of our ongoing \"clean up the user model\" effort\r\n\r\n<!-- ### Privacy -->\r\n<!-- ### Security -->\r\n<!-- ### Caching -->\r\n<!-- ### Testing -->\r\n<!-- ### Deployment strategy -->\r\n<!-- ### Future work -->\r\n\r\n## Links\r\n\r\n<!--\r\n  Any relevant links to external resources; ie, specification documents, jira\r\n  items, related PRs, honeybadger errors, etc\r\n-->\r\n\r\n- [jira](https://codedotorg.atlassian.net/browse/FND-714)\r\n\r\n## Testing story\r\n\r\nAlso moved relevant tests out of `user_test.rb` and into new test classes\r\n\r\n# Reviewer Checklist:\r\n\r\n- [ ] Tests provide adequate coverage\r\n- [ ] Code is well-commented\r\n- [ ] New features are translatable or updates will not break translations\r\n- [ ] Relevant documentation has been added or updated\r\n- [ ] User impact is well-understood and desirable\r\n- [x] Pull Request is labeled appropriately\r\n- [ ] Follow-up work items (including potential tech debt) are tracked and linked\r\n","created_at":"2019-09-27T19:43:23Z","updated_at":"2019-10-10T17:48:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c2c23dea2e394387eefb4fde15b119bfb92cfb8a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":399384770,"node_id":"MDU6TGFiZWwzOTkzODQ3NzA=","url":"https://api.github.com/repos/code-dot-org/code-dot-org/labels/code-hygiene","name":"code-hygiene","color":"4d575f","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004/commits","review_comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004/comments","review_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/31004/comments","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/bfb509e42afd907082712a6cc55c65df5939208d","head":{"label":"code-dot-org:extract-script-activity","ref":"extract-script-activity","sha":"bfb509e42afd907082712a6cc55c65df5939208d","user":{"login":"code-dot-org","id":5124627,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxMjQ2Mjc=","avatar_url":"https://avatars2.githubusercontent.com/u/5124627?v=4","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"repo":{"id":24250009,"node_id":"MDEwOlJlcG9zaXRvcnkyNDI1MDAwOQ==","name":"code-dot-org","full_name":"code-dot-org/code-dot-org","private":false,"owner":{"login":"code-dot-org","id":5124627,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxMjQ2Mjc=","avatar_url":"https://avatars2.githubusercontent.com/u/5124627?v=4","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/code-dot-org/code-dot-org","description":"The code powering code.org and studio.code.org","fork":false,"url":"https://api.github.com/repos/code-dot-org/code-dot-org","forks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/forks","keys_url":"https://api.github.com/repos/code-dot-org/code-dot-org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/code-dot-org/code-dot-org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/code-dot-org/code-dot-org/teams","hooks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/hooks","issue_events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/events{/number}","events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/events","assignees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/assignees{/user}","branches_url":"https://api.github.com/repos/code-dot-org/code-dot-org/branches{/branch}","tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/tags","blobs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/refs{/sha}","trees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/{sha}","languages_url":"https://api.github.com/repos/code-dot-org/code-dot-org/languages","stargazers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/stargazers","contributors_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contributors","subscribers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscribers","subscription_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscription","commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/commits{/sha}","git_commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/commits{/sha}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/comments{/number}","issue_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/comments{/number}","contents_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contents/{+path}","compare_url":"https://api.github.com/repos/code-dot-org/code-dot-org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/code-dot-org/code-dot-org/merges","archive_url":"https://api.github.com/repos/code-dot-org/code-dot-org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/code-dot-org/code-dot-org/downloads","issues_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues{/number}","pulls_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls{/number}","milestones_url":"https://api.github.com/repos/code-dot-org/code-dot-org/milestones{/number}","notifications_url":"https://api.github.com/repos/code-dot-org/code-dot-org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/code-dot-org/code-dot-org/labels{/name}","releases_url":"https://api.github.com/repos/code-dot-org/code-dot-org/releases{/id}","deployments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/deployments","created_at":"2014-09-20T00:46:11Z","updated_at":"2019-10-10T17:24:02Z","pushed_at":"2019-10-10T17:47:42Z","git_url":"git://github.com/code-dot-org/code-dot-org.git","ssh_url":"git@github.com:code-dot-org/code-dot-org.git","clone_url":"https://github.com/code-dot-org/code-dot-org.git","svn_url":"https://github.com/code-dot-org/code-dot-org","homepage":"http://code.org","size":10159241,"stargazers_count":497,"watchers_count":497,"language":"JavaScript","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":290,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":186,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":290,"open_issues":186,"watchers":497,"default_branch":"staging"}},"base":{"label":"code-dot-org:staging","ref":"staging","sha":"3df13ef21e30b5d1278e89c415e3bf49f77fc7e6","user":{"login":"code-dot-org","id":5124627,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxMjQ2Mjc=","avatar_url":"https://avatars2.githubusercontent.com/u/5124627?v=4","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"repo":{"id":24250009,"node_id":"MDEwOlJlcG9zaXRvcnkyNDI1MDAwOQ==","name":"code-dot-org","full_name":"code-dot-org/code-dot-org","private":false,"owner":{"login":"code-dot-org","id":5124627,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxMjQ2Mjc=","avatar_url":"https://avatars2.githubusercontent.com/u/5124627?v=4","gravatar_id":"","url":"https://api.github.com/users/code-dot-org","html_url":"https://github.com/code-dot-org","followers_url":"https://api.github.com/users/code-dot-org/followers","following_url":"https://api.github.com/users/code-dot-org/following{/other_user}","gists_url":"https://api.github.com/users/code-dot-org/gists{/gist_id}","starred_url":"https://api.github.com/users/code-dot-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/code-dot-org/subscriptions","organizations_url":"https://api.github.com/users/code-dot-org/orgs","repos_url":"https://api.github.com/users/code-dot-org/repos","events_url":"https://api.github.com/users/code-dot-org/events{/privacy}","received_events_url":"https://api.github.com/users/code-dot-org/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/code-dot-org/code-dot-org","description":"The code powering code.org and studio.code.org","fork":false,"url":"https://api.github.com/repos/code-dot-org/code-dot-org","forks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/forks","keys_url":"https://api.github.com/repos/code-dot-org/code-dot-org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/code-dot-org/code-dot-org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/code-dot-org/code-dot-org/teams","hooks_url":"https://api.github.com/repos/code-dot-org/code-dot-org/hooks","issue_events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/events{/number}","events_url":"https://api.github.com/repos/code-dot-org/code-dot-org/events","assignees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/assignees{/user}","branches_url":"https://api.github.com/repos/code-dot-org/code-dot-org/branches{/branch}","tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/tags","blobs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/refs{/sha}","trees_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/{sha}","languages_url":"https://api.github.com/repos/code-dot-org/code-dot-org/languages","stargazers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/stargazers","contributors_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contributors","subscribers_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscribers","subscription_url":"https://api.github.com/repos/code-dot-org/code-dot-org/subscription","commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/commits{/sha}","git_commits_url":"https://api.github.com/repos/code-dot-org/code-dot-org/git/commits{/sha}","comments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/comments{/number}","issue_comment_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/comments{/number}","contents_url":"https://api.github.com/repos/code-dot-org/code-dot-org/contents/{+path}","compare_url":"https://api.github.com/repos/code-dot-org/code-dot-org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/code-dot-org/code-dot-org/merges","archive_url":"https://api.github.com/repos/code-dot-org/code-dot-org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/code-dot-org/code-dot-org/downloads","issues_url":"https://api.github.com/repos/code-dot-org/code-dot-org/issues{/number}","pulls_url":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls{/number}","milestones_url":"https://api.github.com/repos/code-dot-org/code-dot-org/milestones{/number}","notifications_url":"https://api.github.com/repos/code-dot-org/code-dot-org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/code-dot-org/code-dot-org/labels{/name}","releases_url":"https://api.github.com/repos/code-dot-org/code-dot-org/releases{/id}","deployments_url":"https://api.github.com/repos/code-dot-org/code-dot-org/deployments","created_at":"2014-09-20T00:46:11Z","updated_at":"2019-10-10T17:24:02Z","pushed_at":"2019-10-10T17:47:42Z","git_url":"git://github.com/code-dot-org/code-dot-org.git","ssh_url":"git@github.com:code-dot-org/code-dot-org.git","clone_url":"https://github.com/code-dot-org/code-dot-org.git","svn_url":"https://github.com/code-dot-org/code-dot-org","homepage":"http://code.org","size":10159241,"stargazers_count":497,"watchers_count":497,"language":"JavaScript","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":290,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":186,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":290,"open_issues":186,"watchers":497,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004"},"html":{"href":"https://github.com/code-dot-org/code-dot-org/pull/31004"},"issue":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/31004"},"comments":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/issues/31004/comments"},"review_comments":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004/comments"},"review_comment":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/pulls/31004/commits"},"statuses":{"href":"https://api.github.com/repos/code-dot-org/code-dot-org/statuses/bfb509e42afd907082712a6cc55c65df5939208d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"Hamms"}}