{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/39959839","id":39959839,"diff_hunk":"@@ -0,0 +1,97 @@\n+# encoding: utf-8\n+\n+require_relative '../spec_helper'\n+require_relative './database_configuration_contexts'\n+\n+shared_context 'organization with users helper' do\n+  include CacheHelper\n+  include_context 'database configuration'\n+\n+  before(:each) do\n+    bypass_named_maps\n+  end\n+\n+  def test_organization\n+    organization = Organization.new\n+    organization.name = org_name = \"org#{rand(9999)}\"\n+    organization.quota_in_bytes = 1234567890\n+    organization.seats = 5\n+    organization\n+  end\n+\n+  def create_test_user(username, organization = nil)\n+    user = create_user(\n+      username: username,\n+      email: \"#{username}@example.com\",\n+      password: username,\n+      private_tables_enabled: true,\n+      organization: organization\n+    )\n+    user.save.reload\n+    organization.reload if organization\n+    user\n+  end\n+\n+  before(:all) do\n+    @organization = test_organization.save\n+    @organization_2 = test_organization.save\n+\n+    @org_user_owner = create_test_user(\"o#{random_username}\")\n+    user_org = CartoDB::UserOrganization.new(@organization.id, @org_user_owner.id)\n+    user_org.promote_user_to_admin\n+    @organization.reload\n+    @org_user_owner.reload\n+\n+    @org_user_1 = create_test_user(\"a#{random_username}\", @organization)\n+    @org_user_2 = create_test_user(\"b#{random_username}\", @organization)\n+\n+    @organization.reload\n+  end\n+\n+  before(:each) do\n+    bypass_named_maps\n+    delete_user_data @org_user_owner\n+    delete_user_data @org_user_1\n+    delete_user_data @org_user_2\n+  end\n+\n+  after(:all) do\n+    bypass_named_maps\n+    delete_user_data @org_user_owner if @org_user_owner\n+    @organization.destroy_cascade\n+  end\n+\n+  def share_table(table, owner, user)\n+    bypass_named_maps\n+    headers = {'CONTENT_TYPE'  => 'application/json'}\n+    perm_id = table.table_visualization.permission.id\n+\n+    put api_v1_permissions_update_url(user_domain: owner.username, api_key: owner.api_key, id: perm_id),\n+        {acl: [{\n+                 type: CartoDB::Permission::TYPE_USER,\n+                 entity: {\n+                   id:   user.id,\n+                 },\n+                 access: CartoDB::Permission::ACCESS_READONLY\n+               }]}.to_json, headers\n+    response.status.should == 200\n+  end\n+\n+  def share_table_with_organization(table, owner, organization)\n+    bypass_named_maps\n+    headers = {'CONTENT_TYPE'  => 'application/json'}\n+    perm_id = table.table_visualization.permission.id\n+\n+    put api_v1_permissions_update_url(user_domain: owner.username, api_key: owner.api_key, id: perm_id),\n+        {acl: [{","path":"spec/factories/organizations_contexts.rb","position":86,"original_position":86,"commit_id":"5fe343cb69c0adc2754fc5f4224e1ac7469c7877","original_commit_id":"5fe343cb69c0adc2754fc5f4224e1ac7469c7877","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Space inside { missing.","created_at":"2015-09-21T11:08:34Z","updated_at":"2015-09-21T11:08:34Z","html_url":"https://github.com/CartoDB/cartodb/pull/5077#discussion_r39959839","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/39959839"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/5077#discussion_r39959839"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077","id":42681296,"html_url":"https://github.com/CartoDB/cartodb/pull/5077","diff_url":"https://github.com/CartoDB/cartodb/pull/5077.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/5077.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/5077","number":5077,"state":"open","locked":false,"title":"4924 group metadata api endpoints","user":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"body":"This closes #4924. Depends on CartoDB/cartodb-postgresql#104. @Kartones , could you CR this, please?\r\n\r\nThis won't be merged this milestone.","created_at":"2015-08-18T10:06:59Z","updated_at":"2015-09-21T11:08:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c2fe617e0431512a98166c8aa65c2182db37243","assignee":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/CartoDB/cartodb/milestones/48","html_url":"https://github.com/CartoDB/cartodb/milestones/Cabra%20del%20Santo%20Cristo","labels_url":"https://api.github.com/repos/CartoDB/cartodb/milestones/48/labels","id":1262219,"number":48,"title":"Cabra del Santo Cristo","description":"- [ ] Public data library section (@matallo)\r\n- [ ] Backend issues (@kartones)\r\n- [ ] Frontend small features/fixes (@javierarce)\r\n- [ ] Groups release v1 (@juanignaciosl and @viddo)\r\n- [ ] Cluster renderer torque (@fdansv)\r\n- [ ] Advanced Map creation on Import (@rtorre)\r\n- [ ] CTM (@rochoa)\r\n- [ ] Ogr2ogr new version (@rtorre)\r\n- [ ] Data Services Revamp - WIP (@iriberri)\r\n- [ ] Test optimization (@jesusvazquez)\r\n- [ ] Wizards refactor (@pabloalonso)","creator":{"login":"fdansv","id":3707222,"avatar_url":"https://avatars.githubusercontent.com/u/3707222?v=3","gravatar_id":"","url":"https://api.github.com/users/fdansv","html_url":"https://github.com/fdansv","followers_url":"https://api.github.com/users/fdansv/followers","following_url":"https://api.github.com/users/fdansv/following{/other_user}","gists_url":"https://api.github.com/users/fdansv/gists{/gist_id}","starred_url":"https://api.github.com/users/fdansv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdansv/subscriptions","organizations_url":"https://api.github.com/users/fdansv/orgs","repos_url":"https://api.github.com/users/fdansv/repos","events_url":"https://api.github.com/users/fdansv/events{/privacy}","received_events_url":"https://api.github.com/users/fdansv/received_events","type":"User","site_admin":false},"open_issues":129,"closed_issues":13,"state":"open","created_at":"2015-08-19T09:13:00Z","updated_at":"2015-09-21T11:05:45Z","due_on":"2015-09-29T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/5077/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/5fe343cb69c0adc2754fc5f4224e1ac7469c7877","head":{"label":"CartoDB:4924-Group_metadata_API_endpoints","ref":"4924-Group_metadata_API_endpoints","sha":"5fe343cb69c0adc2754fc5f4224e1ac7469c7877","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","created_at":"2012-07-05T15:23:45Z","updated_at":"2015-09-21T10:07:01Z","pushed_at":"2015-09-21T11:08:14Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":508933,"stargazers_count":932,"watchers_count":932,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":219,"mirror_url":null,"open_issues_count":807,"forks":219,"open_issues":807,"watchers":932,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"273ce5232a9b7bf34a84b9b3045121d381200feb","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","created_at":"2012-07-05T15:23:45Z","updated_at":"2015-09-21T10:07:01Z","pushed_at":"2015-09-21T11:08:14Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":508933,"stargazers_count":932,"watchers_count":932,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":219,"mirror_url":null,"open_issues_count":807,"forks":219,"open_issues":807,"watchers":932,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/5077"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/5077"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/5077/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/5077/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/5fe343cb69c0adc2754fc5f4224e1ac7469c7877"}}}}