{"action":"created","comment":{"url":"https://api.github.com/repos/Chorus/chorus/pulls/comments/40391656","id":40391656,"diff_hunk":"@@ -0,0 +1,88 @@\n+class PermissionsMigrator\n+\n+  CLASSES = [\n+      Events::Base,\n+      ChorusScope,\n+      Role,\n+      User,\n+      DataSourceAccount,\n+      Group,\n+      Workspace,\n+      DataSource,\n+      HdfsDataSource,\n+      GnipDataSource,\n+      JdbcHiveDataSource,\n+      Schema,\n+      Comment,\n+      Workfile,\n+      Job,\n+      Milestone,\n+      Tag,\n+      Upload,\n+      Import,\n+      Notification,\n+      CsvFile,\n+      Database,\n+      Dataset\n+  ]\n+\n+  def self.migrate_5_7\n+    insert_chorus_object_rows\n+    assign_workspace_roles\n+    assign_users_to_default_group\n+  end\n+\n+  #private\n+\n+  def self.insert_chorus_object_rows\n+    CLASSES.each do |klass|\n+      rows = create_rows(klass)\n+\n+      ChorusObject.connection.execute \"INSERT INTO chorus_objects #{attribute_columns_string} VALUES #{rows.join(\", \")}\" if rows.any?\n+    end\n+  end\n+\n+  def self.create_rows(klass)\n+    scope_id = ChorusScope.where(:name => 'application_realm').pluck(:id).first\n+    time = Time.now.to_s(:db)\n+\n+    klass.all.map do |object|\n+      chorus_class_id = ChorusClass.where(:name => object.class.name).pluck(:id).first\n+      create_attribte_string(object, chorus_class_id, time, scope_id)\n+    end\n+  end\n+\n+  def self.assign_workspace_roles\n+    project_manager_role = Role.where(:name => 'ProjectManager').first\n+    owner_role = Role.where(:name => 'Owner').first\n+\n+    Workspace.all.each do |ws|\n+      ws.add_user_to_object_role(ws.owner, owner_role)\n+\n+      ws.members.each do |member|\n+        ws.add_user_to_object_role(member, project_manager_role)\n+      end\n+    end\n+  end\n+\n+  def self.create_attribte_string(object, chorus_class_id, time, scope_id)","path":"lib/permissions_migrator.rb","position":68,"original_position":68,"commit_id":"c9ad47e08ee0f5eeb2d1a97ccc2a11fb292196d2","original_commit_id":"c9ad47e08ee0f5eeb2d1a97ccc2a11fb292196d2","user":{"login":"AndrewLngdn","id":1474568,"avatar_url":"https://avatars.githubusercontent.com/u/1474568?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewLngdn","html_url":"https://github.com/AndrewLngdn","followers_url":"https://api.github.com/users/AndrewLngdn/followers","following_url":"https://api.github.com/users/AndrewLngdn/following{/other_user}","gists_url":"https://api.github.com/users/AndrewLngdn/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewLngdn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewLngdn/subscriptions","organizations_url":"https://api.github.com/users/AndrewLngdn/orgs","repos_url":"https://api.github.com/users/AndrewLngdn/repos","events_url":"https://api.github.com/users/AndrewLngdn/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewLngdn/received_events","type":"User","site_admin":false},"body":"Good call, did you change this or should I?","created_at":"2015-09-25T01:01:30Z","updated_at":"2015-09-25T01:01:30Z","html_url":"https://github.com/Chorus/chorus/pull/165#discussion_r40391656","pull_request_url":"https://api.github.com/repos/Chorus/chorus/pulls/165","_links":{"self":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/comments/40391656"},"html":{"href":"https://github.com/Chorus/chorus/pull/165#discussion_r40391656"},"pull_request":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/165"}}},"pull_request":{"url":"https://api.github.com/repos/Chorus/chorus/pulls/165","id":45358528,"html_url":"https://github.com/Chorus/chorus/pull/165","diff_url":"https://github.com/Chorus/chorus/pull/165.diff","patch_url":"https://github.com/Chorus/chorus/pull/165.patch","issue_url":"https://api.github.com/repos/Chorus/chorus/issues/165","number":165,"state":"open","locked":false,"title":"Renables the better version of .filter_by_scope and...","user":{"login":"AndrewLngdn","id":1474568,"avatar_url":"https://avatars.githubusercontent.com/u/1474568?v=3","gravatar_id":"","url":"https://api.github.com/users/AndrewLngdn","html_url":"https://github.com/AndrewLngdn","followers_url":"https://api.github.com/users/AndrewLngdn/followers","following_url":"https://api.github.com/users/AndrewLngdn/following{/other_user}","gists_url":"https://api.github.com/users/AndrewLngdn/gists{/gist_id}","starred_url":"https://api.github.com/users/AndrewLngdn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndrewLngdn/subscriptions","organizations_url":"https://api.github.com/users/AndrewLngdn/orgs","repos_url":"https://api.github.com/users/AndrewLngdn/repos","events_url":"https://api.github.com/users/AndrewLngdn/events{/privacy}","received_events_url":"https://api.github.com/users/AndrewLngdn/received_events","type":"User","site_admin":false},"body":"introduces the better version of the permissions migrator. Also adds tests for every scoped endpoint, and fixes a bunch of broken permissions. \r\n\r\nPermissionsMigrator and filter_by_scope are the biggest things here, the rest is just cleaning stuff up. Both are tested. \r\n\r\nFilter_by_scope looks complicated, and it's harder to read than the old method. However, it performs the minimal amount of SQL queries necessary to get the scoped_object_ids in this architecture, without resorting to pure, nested SQL queries (it's basically the nested query unrolled into AR functions). This is an area where performance is important. Prakash's function performed (user.groups.count * ( objects.count + 1) ) number of queries, which could get into the thousands(!) on large endpoints. The new function performs a constant amount of queries and performs the filtering at the end. We could gain a little speed here by checking set inclusion instead of using Array#include? but I'm not sure if the set creation overhead is worth the benefits. It's pretty fast, but we should test it on ChorusAdmin's notifications endpoint because that is the largest (although it shouldn't be returning a thousand objects...)\r\n\r\nThe PermissionsMigrator is a replacement for the migrate_permissions.rb script. It should be fairly straightforward, especially when compared to [the original](https://github.com/Chorus/chorus/blob/master/db/migrate_permissions.rb)\r\n\r\n@kevin-alpine @midnighteuler please leave a comment on anything that looks weird, confusing, or wrong. I'd like to merge this in by mid-day tomorrow so we can get the new migrator into a real rails migration. ","created_at":"2015-09-18T00:42:31Z","updated_at":"2015-09-25T01:01:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32b5c01c76d5042318c60118ff84fcd0e3b1d68f","assignee":{"login":"kevin-alpine","id":12001313,"avatar_url":"https://avatars.githubusercontent.com/u/12001313?v=3","gravatar_id":"","url":"https://api.github.com/users/kevin-alpine","html_url":"https://github.com/kevin-alpine","followers_url":"https://api.github.com/users/kevin-alpine/followers","following_url":"https://api.github.com/users/kevin-alpine/following{/other_user}","gists_url":"https://api.github.com/users/kevin-alpine/gists{/gist_id}","starred_url":"https://api.github.com/users/kevin-alpine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevin-alpine/subscriptions","organizations_url":"https://api.github.com/users/kevin-alpine/orgs","repos_url":"https://api.github.com/users/kevin-alpine/repos","events_url":"https://api.github.com/users/kevin-alpine/events{/privacy}","received_events_url":"https://api.github.com/users/kevin-alpine/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Chorus/chorus/pulls/165/commits","review_comments_url":"https://api.github.com/repos/Chorus/chorus/pulls/165/comments","review_comment_url":"https://api.github.com/repos/Chorus/chorus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Chorus/chorus/issues/165/comments","statuses_url":"https://api.github.com/repos/Chorus/chorus/statuses/c9ad47e08ee0f5eeb2d1a97ccc2a11fb292196d2","head":{"label":"Chorus:rgp-scopes","ref":"rgp-scopes","sha":"c9ad47e08ee0f5eeb2d1a97ccc2a11fb292196d2","user":{"login":"Chorus","id":5614676,"avatar_url":"https://avatars.githubusercontent.com/u/5614676?v=3","gravatar_id":"","url":"https://api.github.com/users/Chorus","html_url":"https://github.com/Chorus","followers_url":"https://api.github.com/users/Chorus/followers","following_url":"https://api.github.com/users/Chorus/following{/other_user}","gists_url":"https://api.github.com/users/Chorus/gists{/gist_id}","starred_url":"https://api.github.com/users/Chorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chorus/subscriptions","organizations_url":"https://api.github.com/users/Chorus/orgs","repos_url":"https://api.github.com/users/Chorus/repos","events_url":"https://api.github.com/users/Chorus/events{/privacy}","received_events_url":"https://api.github.com/users/Chorus/received_events","type":"Organization","site_admin":false},"repo":{"id":2751440,"name":"chorus","full_name":"Chorus/chorus","owner":{"login":"Chorus","id":5614676,"avatar_url":"https://avatars.githubusercontent.com/u/5614676?v=3","gravatar_id":"","url":"https://api.github.com/users/Chorus","html_url":"https://github.com/Chorus","followers_url":"https://api.github.com/users/Chorus/followers","following_url":"https://api.github.com/users/Chorus/following{/other_user}","gists_url":"https://api.github.com/users/Chorus/gists{/gist_id}","starred_url":"https://api.github.com/users/Chorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chorus/subscriptions","organizations_url":"https://api.github.com/users/Chorus/orgs","repos_url":"https://api.github.com/users/Chorus/repos","events_url":"https://api.github.com/users/Chorus/events{/privacy}","received_events_url":"https://api.github.com/users/Chorus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Chorus/chorus","description":"Chorus allows customers, partners, developers, and data scientists to collaboratively realize the potential of Big Data.","fork":false,"url":"https://api.github.com/repos/Chorus/chorus","forks_url":"https://api.github.com/repos/Chorus/chorus/forks","keys_url":"https://api.github.com/repos/Chorus/chorus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Chorus/chorus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Chorus/chorus/teams","hooks_url":"https://api.github.com/repos/Chorus/chorus/hooks","issue_events_url":"https://api.github.com/repos/Chorus/chorus/issues/events{/number}","events_url":"https://api.github.com/repos/Chorus/chorus/events","assignees_url":"https://api.github.com/repos/Chorus/chorus/assignees{/user}","branches_url":"https://api.github.com/repos/Chorus/chorus/branches{/branch}","tags_url":"https://api.github.com/repos/Chorus/chorus/tags","blobs_url":"https://api.github.com/repos/Chorus/chorus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Chorus/chorus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Chorus/chorus/git/refs{/sha}","trees_url":"https://api.github.com/repos/Chorus/chorus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Chorus/chorus/statuses/{sha}","languages_url":"https://api.github.com/repos/Chorus/chorus/languages","stargazers_url":"https://api.github.com/repos/Chorus/chorus/stargazers","contributors_url":"https://api.github.com/repos/Chorus/chorus/contributors","subscribers_url":"https://api.github.com/repos/Chorus/chorus/subscribers","subscription_url":"https://api.github.com/repos/Chorus/chorus/subscription","commits_url":"https://api.github.com/repos/Chorus/chorus/commits{/sha}","git_commits_url":"https://api.github.com/repos/Chorus/chorus/git/commits{/sha}","comments_url":"https://api.github.com/repos/Chorus/chorus/comments{/number}","issue_comment_url":"https://api.github.com/repos/Chorus/chorus/issues/comments{/number}","contents_url":"https://api.github.com/repos/Chorus/chorus/contents/{+path}","compare_url":"https://api.github.com/repos/Chorus/chorus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Chorus/chorus/merges","archive_url":"https://api.github.com/repos/Chorus/chorus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Chorus/chorus/downloads","issues_url":"https://api.github.com/repos/Chorus/chorus/issues{/number}","pulls_url":"https://api.github.com/repos/Chorus/chorus/pulls{/number}","milestones_url":"https://api.github.com/repos/Chorus/chorus/milestones{/number}","notifications_url":"https://api.github.com/repos/Chorus/chorus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Chorus/chorus/labels{/name}","releases_url":"https://api.github.com/repos/Chorus/chorus/releases{/id}","created_at":"2011-11-10T20:30:13Z","updated_at":"2015-09-16T10:39:46Z","pushed_at":"2015-09-25T00:32:02Z","git_url":"git://github.com/Chorus/chorus.git","ssh_url":"git@github.com:Chorus/chorus.git","clone_url":"https://github.com/Chorus/chorus.git","svn_url":"https://github.com/Chorus/chorus","homepage":"","size":859626,"stargazers_count":160,"watchers_count":160,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":67,"mirror_url":null,"open_issues_count":13,"forks":67,"open_issues":13,"watchers":160,"default_branch":"master"}},"base":{"label":"Chorus:master","ref":"master","sha":"e1200e67a9b55e22b582e1ad217a3eb38ab257c4","user":{"login":"Chorus","id":5614676,"avatar_url":"https://avatars.githubusercontent.com/u/5614676?v=3","gravatar_id":"","url":"https://api.github.com/users/Chorus","html_url":"https://github.com/Chorus","followers_url":"https://api.github.com/users/Chorus/followers","following_url":"https://api.github.com/users/Chorus/following{/other_user}","gists_url":"https://api.github.com/users/Chorus/gists{/gist_id}","starred_url":"https://api.github.com/users/Chorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chorus/subscriptions","organizations_url":"https://api.github.com/users/Chorus/orgs","repos_url":"https://api.github.com/users/Chorus/repos","events_url":"https://api.github.com/users/Chorus/events{/privacy}","received_events_url":"https://api.github.com/users/Chorus/received_events","type":"Organization","site_admin":false},"repo":{"id":2751440,"name":"chorus","full_name":"Chorus/chorus","owner":{"login":"Chorus","id":5614676,"avatar_url":"https://avatars.githubusercontent.com/u/5614676?v=3","gravatar_id":"","url":"https://api.github.com/users/Chorus","html_url":"https://github.com/Chorus","followers_url":"https://api.github.com/users/Chorus/followers","following_url":"https://api.github.com/users/Chorus/following{/other_user}","gists_url":"https://api.github.com/users/Chorus/gists{/gist_id}","starred_url":"https://api.github.com/users/Chorus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Chorus/subscriptions","organizations_url":"https://api.github.com/users/Chorus/orgs","repos_url":"https://api.github.com/users/Chorus/repos","events_url":"https://api.github.com/users/Chorus/events{/privacy}","received_events_url":"https://api.github.com/users/Chorus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Chorus/chorus","description":"Chorus allows customers, partners, developers, and data scientists to collaboratively realize the potential of Big Data.","fork":false,"url":"https://api.github.com/repos/Chorus/chorus","forks_url":"https://api.github.com/repos/Chorus/chorus/forks","keys_url":"https://api.github.com/repos/Chorus/chorus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Chorus/chorus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Chorus/chorus/teams","hooks_url":"https://api.github.com/repos/Chorus/chorus/hooks","issue_events_url":"https://api.github.com/repos/Chorus/chorus/issues/events{/number}","events_url":"https://api.github.com/repos/Chorus/chorus/events","assignees_url":"https://api.github.com/repos/Chorus/chorus/assignees{/user}","branches_url":"https://api.github.com/repos/Chorus/chorus/branches{/branch}","tags_url":"https://api.github.com/repos/Chorus/chorus/tags","blobs_url":"https://api.github.com/repos/Chorus/chorus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Chorus/chorus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Chorus/chorus/git/refs{/sha}","trees_url":"https://api.github.com/repos/Chorus/chorus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Chorus/chorus/statuses/{sha}","languages_url":"https://api.github.com/repos/Chorus/chorus/languages","stargazers_url":"https://api.github.com/repos/Chorus/chorus/stargazers","contributors_url":"https://api.github.com/repos/Chorus/chorus/contributors","subscribers_url":"https://api.github.com/repos/Chorus/chorus/subscribers","subscription_url":"https://api.github.com/repos/Chorus/chorus/subscription","commits_url":"https://api.github.com/repos/Chorus/chorus/commits{/sha}","git_commits_url":"https://api.github.com/repos/Chorus/chorus/git/commits{/sha}","comments_url":"https://api.github.com/repos/Chorus/chorus/comments{/number}","issue_comment_url":"https://api.github.com/repos/Chorus/chorus/issues/comments{/number}","contents_url":"https://api.github.com/repos/Chorus/chorus/contents/{+path}","compare_url":"https://api.github.com/repos/Chorus/chorus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Chorus/chorus/merges","archive_url":"https://api.github.com/repos/Chorus/chorus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Chorus/chorus/downloads","issues_url":"https://api.github.com/repos/Chorus/chorus/issues{/number}","pulls_url":"https://api.github.com/repos/Chorus/chorus/pulls{/number}","milestones_url":"https://api.github.com/repos/Chorus/chorus/milestones{/number}","notifications_url":"https://api.github.com/repos/Chorus/chorus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Chorus/chorus/labels{/name}","releases_url":"https://api.github.com/repos/Chorus/chorus/releases{/id}","created_at":"2011-11-10T20:30:13Z","updated_at":"2015-09-16T10:39:46Z","pushed_at":"2015-09-25T00:32:02Z","git_url":"git://github.com/Chorus/chorus.git","ssh_url":"git@github.com:Chorus/chorus.git","clone_url":"https://github.com/Chorus/chorus.git","svn_url":"https://github.com/Chorus/chorus","homepage":"","size":859626,"stargazers_count":160,"watchers_count":160,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":67,"mirror_url":null,"open_issues_count":13,"forks":67,"open_issues":13,"watchers":160,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/165"},"html":{"href":"https://github.com/Chorus/chorus/pull/165"},"issue":{"href":"https://api.github.com/repos/Chorus/chorus/issues/165"},"comments":{"href":"https://api.github.com/repos/Chorus/chorus/issues/165/comments"},"review_comments":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/165/comments"},"review_comment":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Chorus/chorus/pulls/165/commits"},"statuses":{"href":"https://api.github.com/repos/Chorus/chorus/statuses/c9ad47e08ee0f5eeb2d1a97ccc2a11fb292196d2"}}}}