{"action":"created","comment":{"url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/comments/39542589","id":39542589,"diff_hunk":"@@ -2,19 +2,78 @@ class Ability\n   include Hydra::Ability\n   include Sufia::Ability\n \n-  \n   # Define any customized permissions here.\n   def custom_permissions\n-    # Limits deleting objects to a the admin user\n-    #\n-    # if current_user.admin?\n-    #   can [:destroy], ActiveFedora::Base\n-    # end\n-\n-    # Limits creating new objects to a specific group\n-    #\n-    # if user_groups.include? 'special_group'\n-    #   can [:create], ActiveFedora::Base\n-    # end\n+    discover_permissions\n+    override_download_permissions\n+  end\n+\n+  private\n+\n+  # TODO: discover_permissions and friends should really be moved into\n+  # hydra_access_controls.  We should fork that gem and make the change\n+  # there instead, then submit it as a PR.\n+  #\n+  # override_download_permissions should stay here, but maybe there's a\n+  # way to not duplicate the code from hydra_access_controls.\n+\n+  def discover_permissions\n+    can :discover, String do |id|\n+      test_discover(id)\n+    end\n+\n+    can :discover, ActiveFedora::Base do |obj|\n+      test_discover(obj.id)\n+    end\n+\n+    can :discover, SolrDocument do |obj|\n+      cache.put(obj.id, obj)\n+      test_discover(obj.id)\n+    end\n+  end\n+\n+  def override_download_permissions\n+    can :download, ActiveFedora::File do |file|\n+      parent_uri = file.uri.to_s.sub(/\\/[^\\/]*$/, '')\n+      parent_id = ActiveFedora::Base.uri_to_id(parent_uri)\n+      if file.uri.end_with?(\"thumbnail\")\n+        can? :discover, parent_id\n+      else\n+        can? :read, parent_id\n+      end\n+    end\n+  end\n+\n+  def test_discover(id)\n+    Rails.logger.debug(\"[CANCAN] Checking discover permissions for user: #{current_user.user_key} with groups: #{user_groups.inspect}\")\n+    group_intersection = user_groups & discover_groups(id)\n+    result = !group_intersection.empty? || discover_users(id).include?(current_user.user_key)\n+    result\n+  end\n+\n+  # read implies discover, so discover_groups is the union of read and discover groups\n+  def discover_groups(id)\n+    doc = permissions_doc(id)\n+    return [] if doc.nil?\n+    dg = read_groups(id) | (doc[self.class.discover_group_field] || [])\n+    Rails.logger.debug(\"[CANCAN] discover_groups: #{dg.inspect}\")\n+    return dg","path":"app/models/ability.rb","position":71,"original_position":71,"commit_id":"c1d062fc87db3ca456512900005ba52890741d21","original_commit_id":"c1d062fc87db3ca456512900005ba52890741d21","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":"Redundant `return` detected.","created_at":"2015-09-15T17:52:57Z","updated_at":"2015-09-15T17:52:57Z","html_url":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38#discussion_r39542589","pull_request_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/comments/39542589"},"html":{"href":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38#discussion_r39542589"},"pull_request":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38","id":44956854,"html_url":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38","diff_url":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38.diff","patch_url":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38.patch","issue_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/38","number":38,"state":"open","locked":false,"title":"[WIP] Allow documents to be discoverable","user":{"login":"randycoulman","id":1406203,"avatar_url":"https://avatars.githubusercontent.com/u/1406203?v=3","gravatar_id":"","url":"https://api.github.com/users/randycoulman","html_url":"https://github.com/randycoulman","followers_url":"https://api.github.com/users/randycoulman/followers","following_url":"https://api.github.com/users/randycoulman/following{/other_user}","gists_url":"https://api.github.com/users/randycoulman/gists{/gist_id}","starred_url":"https://api.github.com/users/randycoulman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randycoulman/subscriptions","organizations_url":"https://api.github.com/users/randycoulman/orgs","repos_url":"https://api.github.com/users/randycoulman/repos","events_url":"https://api.github.com/users/randycoulman/events{/privacy}","received_events_url":"https://api.github.com/users/randycoulman/received_events","type":"User","site_admin":false},"body":"* Change the wording of the Private option description\r\n\r\n* Remove the table of permissions at the bottom of the permissions tab.  They make no sense\r\nwithout the rest of the Share With section from Sufia’s permissions tab.\r\n\r\n\r\n![screen shot 2015-09-14 at 10 20 23 am](https://cloud.githubusercontent.com/assets/1406203/9856693/0fc58b10-5acb-11e5-9822-ec460936d45a.png)\r\n","created_at":"2015-09-14T17:23:22Z","updated_at":"2015-09-15T17:52:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d837b03450d3c778fe0b1344c6f1e18e1d78b3d8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38/commits","review_comments_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38/comments","review_comment_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/38/comments","statuses_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/statuses/c1d062fc87db3ca456512900005ba52890741d21","head":{"label":"OregonShakespeareFestival:features/discoverable","ref":"features/discoverable","sha":"c1d062fc87db3ca456512900005ba52890741d21","user":{"login":"OregonShakespeareFestival","id":7905937,"avatar_url":"https://avatars.githubusercontent.com/u/7905937?v=3","gravatar_id":"","url":"https://api.github.com/users/OregonShakespeareFestival","html_url":"https://github.com/OregonShakespeareFestival","followers_url":"https://api.github.com/users/OregonShakespeareFestival/followers","following_url":"https://api.github.com/users/OregonShakespeareFestival/following{/other_user}","gists_url":"https://api.github.com/users/OregonShakespeareFestival/gists{/gist_id}","starred_url":"https://api.github.com/users/OregonShakespeareFestival/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OregonShakespeareFestival/subscriptions","organizations_url":"https://api.github.com/users/OregonShakespeareFestival/orgs","repos_url":"https://api.github.com/users/OregonShakespeareFestival/repos","events_url":"https://api.github.com/users/OregonShakespeareFestival/events{/privacy}","received_events_url":"https://api.github.com/users/OregonShakespeareFestival/received_events","type":"Organization","site_admin":false},"repo":{"id":39144049,"name":"digital-archives","full_name":"OregonShakespeareFestival/digital-archives","owner":{"login":"OregonShakespeareFestival","id":7905937,"avatar_url":"https://avatars.githubusercontent.com/u/7905937?v=3","gravatar_id":"","url":"https://api.github.com/users/OregonShakespeareFestival","html_url":"https://github.com/OregonShakespeareFestival","followers_url":"https://api.github.com/users/OregonShakespeareFestival/followers","following_url":"https://api.github.com/users/OregonShakespeareFestival/following{/other_user}","gists_url":"https://api.github.com/users/OregonShakespeareFestival/gists{/gist_id}","starred_url":"https://api.github.com/users/OregonShakespeareFestival/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OregonShakespeareFestival/subscriptions","organizations_url":"https://api.github.com/users/OregonShakespeareFestival/orgs","repos_url":"https://api.github.com/users/OregonShakespeareFestival/repos","events_url":"https://api.github.com/users/OregonShakespeareFestival/events{/privacy}","received_events_url":"https://api.github.com/users/OregonShakespeareFestival/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OregonShakespeareFestival/digital-archives","description":"","fork":false,"url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives","forks_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/forks","keys_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/teams","hooks_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/hooks","issue_events_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/events{/number}","events_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/events","assignees_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/assignees{/user}","branches_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/branches{/branch}","tags_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/tags","blobs_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/refs{/sha}","trees_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/statuses/{sha}","languages_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/languages","stargazers_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/stargazers","contributors_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/contributors","subscribers_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/subscribers","subscription_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/subscription","commits_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/commits{/sha}","git_commits_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/commits{/sha}","comments_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/comments{/number}","issue_comment_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/comments{/number}","contents_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/contents/{+path}","compare_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/merges","archive_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/downloads","issues_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues{/number}","pulls_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls{/number}","milestones_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/milestones{/number}","notifications_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/labels{/name}","releases_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/releases{/id}","created_at":"2015-07-15T15:16:15Z","updated_at":"2015-07-17T21:50:01Z","pushed_at":"2015-09-15T17:52:52Z","git_url":"git://github.com/OregonShakespeareFestival/digital-archives.git","ssh_url":"git@github.com:OregonShakespeareFestival/digital-archives.git","clone_url":"https://github.com/OregonShakespeareFestival/digital-archives.git","svn_url":"https://github.com/OregonShakespeareFestival/digital-archives","homepage":null,"size":1456,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"OregonShakespeareFestival:master","ref":"master","sha":"9915e2900cb93e34fe3f7d9bf6e275720eb6bb70","user":{"login":"OregonShakespeareFestival","id":7905937,"avatar_url":"https://avatars.githubusercontent.com/u/7905937?v=3","gravatar_id":"","url":"https://api.github.com/users/OregonShakespeareFestival","html_url":"https://github.com/OregonShakespeareFestival","followers_url":"https://api.github.com/users/OregonShakespeareFestival/followers","following_url":"https://api.github.com/users/OregonShakespeareFestival/following{/other_user}","gists_url":"https://api.github.com/users/OregonShakespeareFestival/gists{/gist_id}","starred_url":"https://api.github.com/users/OregonShakespeareFestival/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OregonShakespeareFestival/subscriptions","organizations_url":"https://api.github.com/users/OregonShakespeareFestival/orgs","repos_url":"https://api.github.com/users/OregonShakespeareFestival/repos","events_url":"https://api.github.com/users/OregonShakespeareFestival/events{/privacy}","received_events_url":"https://api.github.com/users/OregonShakespeareFestival/received_events","type":"Organization","site_admin":false},"repo":{"id":39144049,"name":"digital-archives","full_name":"OregonShakespeareFestival/digital-archives","owner":{"login":"OregonShakespeareFestival","id":7905937,"avatar_url":"https://avatars.githubusercontent.com/u/7905937?v=3","gravatar_id":"","url":"https://api.github.com/users/OregonShakespeareFestival","html_url":"https://github.com/OregonShakespeareFestival","followers_url":"https://api.github.com/users/OregonShakespeareFestival/followers","following_url":"https://api.github.com/users/OregonShakespeareFestival/following{/other_user}","gists_url":"https://api.github.com/users/OregonShakespeareFestival/gists{/gist_id}","starred_url":"https://api.github.com/users/OregonShakespeareFestival/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OregonShakespeareFestival/subscriptions","organizations_url":"https://api.github.com/users/OregonShakespeareFestival/orgs","repos_url":"https://api.github.com/users/OregonShakespeareFestival/repos","events_url":"https://api.github.com/users/OregonShakespeareFestival/events{/privacy}","received_events_url":"https://api.github.com/users/OregonShakespeareFestival/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OregonShakespeareFestival/digital-archives","description":"","fork":false,"url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives","forks_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/forks","keys_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/teams","hooks_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/hooks","issue_events_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/events{/number}","events_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/events","assignees_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/assignees{/user}","branches_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/branches{/branch}","tags_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/tags","blobs_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/refs{/sha}","trees_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/statuses/{sha}","languages_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/languages","stargazers_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/stargazers","contributors_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/contributors","subscribers_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/subscribers","subscription_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/subscription","commits_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/commits{/sha}","git_commits_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/git/commits{/sha}","comments_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/comments{/number}","issue_comment_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/comments{/number}","contents_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/contents/{+path}","compare_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/merges","archive_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/downloads","issues_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues{/number}","pulls_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls{/number}","milestones_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/milestones{/number}","notifications_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/labels{/name}","releases_url":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/releases{/id}","created_at":"2015-07-15T15:16:15Z","updated_at":"2015-07-17T21:50:01Z","pushed_at":"2015-09-15T17:52:52Z","git_url":"git://github.com/OregonShakespeareFestival/digital-archives.git","ssh_url":"git@github.com:OregonShakespeareFestival/digital-archives.git","clone_url":"https://github.com/OregonShakespeareFestival/digital-archives.git","svn_url":"https://github.com/OregonShakespeareFestival/digital-archives","homepage":null,"size":1456,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38"},"html":{"href":"https://github.com/OregonShakespeareFestival/digital-archives/pull/38"},"issue":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/38"},"comments":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/OregonShakespeareFestival/digital-archives/statuses/c1d062fc87db3ca456512900005ba52890741d21"}}}}