{"action":"created","comment":{"url":"https://api.github.com/repos/projecthydra/sufia/pulls/comments/28651864","id":28651864,"diff_hunk":"@@ -0,0 +1,74 @@\n+module API\n+  class ItemsController < ApplicationController\n+    before_filter :validate_item, only: [:create, :update]\n+    before_filter :authorize_token\n+    before_filter :my_load_and_authorize_resource, only: [:update, :destroy, :show]\n+\n+    attr_reader :item\n+\n+    def create\n+      head :created, location: sufia.api_item_path(actor.create_file_from_item)\n+    end\n+\n+    def update\n+      actor.update_file_from_item(@file)\n+      head :no_content\n+    end\n+\n+    def destroy\n+      actor.destroy_file(@file)\n+      head :no_content\n+    end\n+\n+    def show\n+      head :no_content\n+    end\n+\n+    private\n+\n+      def my_load_and_authorize_resource\n+        @file = GenericFile.find(params[:id])\n+\n+        unless user.can? :edit, @file\n+          return render plain: \"#{user} lacks access to #{@file}\", status: :unauthorized\n+        end\n+\n+        if @file.arkivo_checksum.nil?\n+          return render plain: \"Forbidden: #{@file} not deposited via Arkivo\", status: :forbidden\n+        end\n+      rescue ActiveFedora::ObjectNotFoundError\n+        return render plain: \"id '#{params[:id]}' not found\", status: :not_found\n+      end\n+\n+      def actor\n+        Sufia::Arkivo::Actor.new(user, item)\n+      end\n+\n+      def token\n+        (request.get? || request.delete?) ? params[:token] : item['token']\n+      end\n+\n+      def user\n+        User.find_by(arkivo_token: token)\n+      end\n+\n+      def validate_item\n+        return render plain: 'no item parameter', status: :bad_request if params[:item].blank?\n+        Sufia::Arkivo::SchemaValidator.new(params[:item]).call\n+      rescue Sufia::Arkivo::InvalidItem => exception\n+        return render plain: \"invalid item parameter: #{exception.message}\", status: :bad_request\n+      else\n+        @item = JSON.parse(params[:item])","path":"app/controllers/api/items_controller.rb","position":61,"original_position":61,"commit_id":"7b87ee91c6dda962a8c4ab38bbe588efe9b9d76c","original_commit_id":"7b87ee91c6dda962a8c4ab38bbe588efe9b9d76c","user":{"login":"inukshuk","id":325102,"avatar_url":"https://avatars.githubusercontent.com/u/325102?v=3","gravatar_id":"","url":"https://api.github.com/users/inukshuk","html_url":"https://github.com/inukshuk","followers_url":"https://api.github.com/users/inukshuk/followers","following_url":"https://api.github.com/users/inukshuk/following{/other_user}","gists_url":"https://api.github.com/users/inukshuk/gists{/gist_id}","starred_url":"https://api.github.com/users/inukshuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inukshuk/subscriptions","organizations_url":"https://api.github.com/users/inukshuk/orgs","repos_url":"https://api.github.com/users/inukshuk/repos","events_url":"https://api.github.com/users/inukshuk/events{/privacy}","received_events_url":"https://api.github.com/users/inukshuk/received_events","type":"User","site_admin":false},"body":"@mjgiarlo this fails for me -- does JSON.parse work with Parameters as input? I worked around it with `params[:item].to_unsafe_hash` for the time being.","created_at":"2015-04-19T11:14:03Z","updated_at":"2015-04-19T11:14:03Z","html_url":"https://github.com/projecthydra/sufia/pull/1022#discussion_r28651864","pull_request_url":"https://api.github.com/repos/projecthydra/sufia/pulls/1022","_links":{"self":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/comments/28651864"},"html":{"href":"https://github.com/projecthydra/sufia/pull/1022#discussion_r28651864"},"pull_request":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/1022"}}},"pull_request":{"url":"https://api.github.com/repos/projecthydra/sufia/pulls/1022","id":32277860,"html_url":"https://github.com/projecthydra/sufia/pull/1022","diff_url":"https://github.com/projecthydra/sufia/pull/1022.diff","patch_url":"https://github.com/projecthydra/sufia/pull/1022.patch","issue_url":"https://api.github.com/repos/projecthydra/sufia/issues/1022","number":1022,"state":"open","locked":false,"title":"Add Arkivo API integration","user":{"login":"mjgiarlo","id":131982,"avatar_url":"https://avatars.githubusercontent.com/u/131982?v=3","gravatar_id":"","url":"https://api.github.com/users/mjgiarlo","html_url":"https://github.com/mjgiarlo","followers_url":"https://api.github.com/users/mjgiarlo/followers","following_url":"https://api.github.com/users/mjgiarlo/following{/other_user}","gists_url":"https://api.github.com/users/mjgiarlo/gists{/gist_id}","starred_url":"https://api.github.com/users/mjgiarlo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjgiarlo/subscriptions","organizations_url":"https://api.github.com/users/mjgiarlo/orgs","repos_url":"https://api.github.com/users/mjgiarlo/repos","events_url":"https://api.github.com/users/mjgiarlo/events{/privacy}","received_events_url":"https://api.github.com/users/mjgiarlo/received_events","type":"User","site_admin":false},"body":"**NOTE**: Do not merge this PR.  There are three outstanding bits of work to do:\r\n\r\n1. The Zotero new publications URL is currently hard-coded to a bogus value because the Zotero data server does not yet support this feature.\r\n2. Improve documentation of this feature in the README\r\n3. Create a better commit message\r\n\r\nThat said, this is a large PR and I'd appreciate multiple reviewers having a look at this so that while I'm working on 1-3 above I can also work through community feedback.","created_at":"2015-03-30T23:28:36Z","updated_at":"2015-04-19T11:14:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"35a98bdbcdfc2ab3d31aaa694e23d6fba4ae922e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/projecthydra/sufia/pulls/1022/commits","review_comments_url":"https://api.github.com/repos/projecthydra/sufia/pulls/1022/comments","review_comment_url":"https://api.github.com/repos/projecthydra/sufia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/projecthydra/sufia/issues/1022/comments","statuses_url":"https://api.github.com/repos/projecthydra/sufia/statuses/7b87ee91c6dda962a8c4ab38bbe588efe9b9d76c","head":{"label":"projecthydra:add_arkivo_api","ref":"add_arkivo_api","sha":"7b87ee91c6dda962a8c4ab38bbe588efe9b9d76c","user":{"login":"projecthydra","id":109426,"avatar_url":"https://avatars.githubusercontent.com/u/109426?v=3","gravatar_id":"","url":"https://api.github.com/users/projecthydra","html_url":"https://github.com/projecthydra","followers_url":"https://api.github.com/users/projecthydra/followers","following_url":"https://api.github.com/users/projecthydra/following{/other_user}","gists_url":"https://api.github.com/users/projecthydra/gists{/gist_id}","starred_url":"https://api.github.com/users/projecthydra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/projecthydra/subscriptions","organizations_url":"https://api.github.com/users/projecthydra/orgs","repos_url":"https://api.github.com/users/projecthydra/repos","events_url":"https://api.github.com/users/projecthydra/events{/privacy}","received_events_url":"https://api.github.com/users/projecthydra/received_events","type":"Organization","site_admin":false},"repo":{"id":7653178,"name":"sufia","full_name":"projecthydra/sufia","owner":{"login":"projecthydra","id":109426,"avatar_url":"https://avatars.githubusercontent.com/u/109426?v=3","gravatar_id":"","url":"https://api.github.com/users/projecthydra","html_url":"https://github.com/projecthydra","followers_url":"https://api.github.com/users/projecthydra/followers","following_url":"https://api.github.com/users/projecthydra/following{/other_user}","gists_url":"https://api.github.com/users/projecthydra/gists{/gist_id}","starred_url":"https://api.github.com/users/projecthydra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/projecthydra/subscriptions","organizations_url":"https://api.github.com/users/projecthydra/orgs","repos_url":"https://api.github.com/users/projecthydra/repos","events_url":"https://api.github.com/users/projecthydra/events{/privacy}","received_events_url":"https://api.github.com/users/projecthydra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/projecthydra/sufia","description":"Sufia is a Rails engine for creating a self-deposit institutional repository. A web application for ingest, curation, search, and display of digital assets. Powered by Hydra technologies (Rails, Hydra-head, Blacklight, Solr, Fedora Commons, etc.)","fork":false,"url":"https://api.github.com/repos/projecthydra/sufia","forks_url":"https://api.github.com/repos/projecthydra/sufia/forks","keys_url":"https://api.github.com/repos/projecthydra/sufia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/projecthydra/sufia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/projecthydra/sufia/teams","hooks_url":"https://api.github.com/repos/projecthydra/sufia/hooks","issue_events_url":"https://api.github.com/repos/projecthydra/sufia/issues/events{/number}","events_url":"https://api.github.com/repos/projecthydra/sufia/events","assignees_url":"https://api.github.com/repos/projecthydra/sufia/assignees{/user}","branches_url":"https://api.github.com/repos/projecthydra/sufia/branches{/branch}","tags_url":"https://api.github.com/repos/projecthydra/sufia/tags","blobs_url":"https://api.github.com/repos/projecthydra/sufia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/projecthydra/sufia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/projecthydra/sufia/git/refs{/sha}","trees_url":"https://api.github.com/repos/projecthydra/sufia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/projecthydra/sufia/statuses/{sha}","languages_url":"https://api.github.com/repos/projecthydra/sufia/languages","stargazers_url":"https://api.github.com/repos/projecthydra/sufia/stargazers","contributors_url":"https://api.github.com/repos/projecthydra/sufia/contributors","subscribers_url":"https://api.github.com/repos/projecthydra/sufia/subscribers","subscription_url":"https://api.github.com/repos/projecthydra/sufia/subscription","commits_url":"https://api.github.com/repos/projecthydra/sufia/commits{/sha}","git_commits_url":"https://api.github.com/repos/projecthydra/sufia/git/commits{/sha}","comments_url":"https://api.github.com/repos/projecthydra/sufia/comments{/number}","issue_comment_url":"https://api.github.com/repos/projecthydra/sufia/issues/comments{/number}","contents_url":"https://api.github.com/repos/projecthydra/sufia/contents/{+path}","compare_url":"https://api.github.com/repos/projecthydra/sufia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/projecthydra/sufia/merges","archive_url":"https://api.github.com/repos/projecthydra/sufia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/projecthydra/sufia/downloads","issues_url":"https://api.github.com/repos/projecthydra/sufia/issues{/number}","pulls_url":"https://api.github.com/repos/projecthydra/sufia/pulls{/number}","milestones_url":"https://api.github.com/repos/projecthydra/sufia/milestones{/number}","notifications_url":"https://api.github.com/repos/projecthydra/sufia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/projecthydra/sufia/labels{/name}","releases_url":"https://api.github.com/repos/projecthydra/sufia/releases{/id}","created_at":"2013-01-16T20:23:18Z","updated_at":"2015-04-17T16:12:00Z","pushed_at":"2015-04-17T16:11:59Z","git_url":"git://github.com/projecthydra/sufia.git","ssh_url":"git@github.com:projecthydra/sufia.git","clone_url":"https://github.com/projecthydra/sufia.git","svn_url":"https://github.com/projecthydra/sufia","homepage":"","size":60905,"stargazers_count":57,"watchers_count":57,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":49,"mirror_url":null,"open_issues_count":75,"forks":49,"open_issues":75,"watchers":57,"default_branch":"master"}},"base":{"label":"projecthydra:master","ref":"master","sha":"20c2a5efa7edf84bddca598411551b41f5cc0175","user":{"login":"projecthydra","id":109426,"avatar_url":"https://avatars.githubusercontent.com/u/109426?v=3","gravatar_id":"","url":"https://api.github.com/users/projecthydra","html_url":"https://github.com/projecthydra","followers_url":"https://api.github.com/users/projecthydra/followers","following_url":"https://api.github.com/users/projecthydra/following{/other_user}","gists_url":"https://api.github.com/users/projecthydra/gists{/gist_id}","starred_url":"https://api.github.com/users/projecthydra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/projecthydra/subscriptions","organizations_url":"https://api.github.com/users/projecthydra/orgs","repos_url":"https://api.github.com/users/projecthydra/repos","events_url":"https://api.github.com/users/projecthydra/events{/privacy}","received_events_url":"https://api.github.com/users/projecthydra/received_events","type":"Organization","site_admin":false},"repo":{"id":7653178,"name":"sufia","full_name":"projecthydra/sufia","owner":{"login":"projecthydra","id":109426,"avatar_url":"https://avatars.githubusercontent.com/u/109426?v=3","gravatar_id":"","url":"https://api.github.com/users/projecthydra","html_url":"https://github.com/projecthydra","followers_url":"https://api.github.com/users/projecthydra/followers","following_url":"https://api.github.com/users/projecthydra/following{/other_user}","gists_url":"https://api.github.com/users/projecthydra/gists{/gist_id}","starred_url":"https://api.github.com/users/projecthydra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/projecthydra/subscriptions","organizations_url":"https://api.github.com/users/projecthydra/orgs","repos_url":"https://api.github.com/users/projecthydra/repos","events_url":"https://api.github.com/users/projecthydra/events{/privacy}","received_events_url":"https://api.github.com/users/projecthydra/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/projecthydra/sufia","description":"Sufia is a Rails engine for creating a self-deposit institutional repository. A web application for ingest, curation, search, and display of digital assets. Powered by Hydra technologies (Rails, Hydra-head, Blacklight, Solr, Fedora Commons, etc.)","fork":false,"url":"https://api.github.com/repos/projecthydra/sufia","forks_url":"https://api.github.com/repos/projecthydra/sufia/forks","keys_url":"https://api.github.com/repos/projecthydra/sufia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/projecthydra/sufia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/projecthydra/sufia/teams","hooks_url":"https://api.github.com/repos/projecthydra/sufia/hooks","issue_events_url":"https://api.github.com/repos/projecthydra/sufia/issues/events{/number}","events_url":"https://api.github.com/repos/projecthydra/sufia/events","assignees_url":"https://api.github.com/repos/projecthydra/sufia/assignees{/user}","branches_url":"https://api.github.com/repos/projecthydra/sufia/branches{/branch}","tags_url":"https://api.github.com/repos/projecthydra/sufia/tags","blobs_url":"https://api.github.com/repos/projecthydra/sufia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/projecthydra/sufia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/projecthydra/sufia/git/refs{/sha}","trees_url":"https://api.github.com/repos/projecthydra/sufia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/projecthydra/sufia/statuses/{sha}","languages_url":"https://api.github.com/repos/projecthydra/sufia/languages","stargazers_url":"https://api.github.com/repos/projecthydra/sufia/stargazers","contributors_url":"https://api.github.com/repos/projecthydra/sufia/contributors","subscribers_url":"https://api.github.com/repos/projecthydra/sufia/subscribers","subscription_url":"https://api.github.com/repos/projecthydra/sufia/subscription","commits_url":"https://api.github.com/repos/projecthydra/sufia/commits{/sha}","git_commits_url":"https://api.github.com/repos/projecthydra/sufia/git/commits{/sha}","comments_url":"https://api.github.com/repos/projecthydra/sufia/comments{/number}","issue_comment_url":"https://api.github.com/repos/projecthydra/sufia/issues/comments{/number}","contents_url":"https://api.github.com/repos/projecthydra/sufia/contents/{+path}","compare_url":"https://api.github.com/repos/projecthydra/sufia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/projecthydra/sufia/merges","archive_url":"https://api.github.com/repos/projecthydra/sufia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/projecthydra/sufia/downloads","issues_url":"https://api.github.com/repos/projecthydra/sufia/issues{/number}","pulls_url":"https://api.github.com/repos/projecthydra/sufia/pulls{/number}","milestones_url":"https://api.github.com/repos/projecthydra/sufia/milestones{/number}","notifications_url":"https://api.github.com/repos/projecthydra/sufia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/projecthydra/sufia/labels{/name}","releases_url":"https://api.github.com/repos/projecthydra/sufia/releases{/id}","created_at":"2013-01-16T20:23:18Z","updated_at":"2015-04-17T16:12:00Z","pushed_at":"2015-04-17T16:11:59Z","git_url":"git://github.com/projecthydra/sufia.git","ssh_url":"git@github.com:projecthydra/sufia.git","clone_url":"https://github.com/projecthydra/sufia.git","svn_url":"https://github.com/projecthydra/sufia","homepage":"","size":60905,"stargazers_count":57,"watchers_count":57,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":49,"mirror_url":null,"open_issues_count":75,"forks":49,"open_issues":75,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/1022"},"html":{"href":"https://github.com/projecthydra/sufia/pull/1022"},"issue":{"href":"https://api.github.com/repos/projecthydra/sufia/issues/1022"},"comments":{"href":"https://api.github.com/repos/projecthydra/sufia/issues/1022/comments"},"review_comments":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/1022/comments"},"review_comment":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/projecthydra/sufia/pulls/1022/commits"},"statuses":{"href":"https://api.github.com/repos/projecthydra/sufia/statuses/7b87ee91c6dda962a8c4ab38bbe588efe9b9d76c"}}}}