{"action":"created","comment":{"url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments/25746622","id":25746622,"diff_hunk":"@@ -37,18 +37,50 @@ def edit\n     @key_pair = KeyPair.find(params[:id])\n   end\n \n+  # Given a File object to upload, save it on the file system with\n+  # association to the user_name given.\n+  # Admins are able to save keys under different user names then\n+  # their own.\n+  # Creates the KEY_STORAGE directory if it does not yet exist\n+  def upload_key_file(_file, user_name)\n+    Dir.mkdir(KEY_STORAGE) unless File.exists?(KEY_STORAGE)\n+    uploaded_io = _file\n+\n+    # todo: check current user to see if they have permission to\n+    # use a different user_name then their current one (admins)\n+\n+    File.open(Rails.root.join(KEY_STORAGE, user_name + '.pub'), 'wb') do |f|\n+      f.write(uploaded_io.read)\n+    end\n+\n+  end\n+\n   # POST /key_pairs\n   # POST /key_pairs.json\n   def create\n-    @key_pair = KeyPair.new(key_pair_params)\n+\n+    # Upload the file\n+    upload_key_file(key_pair_params[:file], @current_user.user_name)\n+\n+    # Save the record\n+    @key_pair = KeyPair.new(\n+        key_pair_params.merge(:user_name => @current_user.user_name,\n+                              :file_name => @current_user.user_name + '.pub'))\n \n     respond_to do |format|\n       if @key_pair.save\n-        format.html { redirect_to @key_pair, notice: 'Key pair was successfully created.' }\n-        format.json { render json: @key_pair, status: :created, location: @key_pair }\n+        format.html do redirect_to @key_pair,\n+                      notice: 'Key pair was successfully created.'\n+                    end\n+        format.json do render json: @key_pair,\n+                             status: :created,\n+                             location: @key_pair\n+                    end\n       else\n         format.html { render action: \"new\" }\n-        format.json { render json: @key_pair.errors, status: :unprocessable_entity }\n+        format.json do render json: @key_pair.errors,\n+                             status: :unprocessable_entity\n+                    end","path":"app/controllers/key_pairs_controller.rb","position":60,"original_position":60,"commit_id":"c046dc2300bb7a42ff324aad24add6696c5a6b45","original_commit_id":"c046dc2300bb7a42ff324aad24add6696c5a6b45","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":"`end` at 83, 20 is not aligned with `format.json do render json: @key_pair.errors,` at 81, 8","created_at":"2015-03-04T01:51:52Z","updated_at":"2015-03-04T01:51:52Z","html_url":"https://github.com/MarkUsProject/Markus/pull/2071#discussion_r25746622","pull_request_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071","_links":{"self":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments/25746622"},"html":{"href":"https://github.com/MarkUsProject/Markus/pull/2071#discussion_r25746622"},"pull_request":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071"}}},"pull_request":{"url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071","id":30431082,"html_url":"https://github.com/MarkUsProject/Markus/pull/2071","diff_url":"https://github.com/MarkUsProject/Markus/pull/2071.diff","patch_url":"https://github.com/MarkUsProject/Markus/pull/2071.patch","issue_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/2071","number":2071,"state":"open","locked":false,"title":"Key Pairs Page","user":{"login":"SoftwareDev","id":5432316,"avatar_url":"https://avatars.githubusercontent.com/u/5432316?v=3","gravatar_id":"","url":"https://api.github.com/users/SoftwareDev","html_url":"https://github.com/SoftwareDev","followers_url":"https://api.github.com/users/SoftwareDev/followers","following_url":"https://api.github.com/users/SoftwareDev/following{/other_user}","gists_url":"https://api.github.com/users/SoftwareDev/gists{/gist_id}","starred_url":"https://api.github.com/users/SoftwareDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SoftwareDev/subscriptions","organizations_url":"https://api.github.com/users/SoftwareDev/orgs","repos_url":"https://api.github.com/users/SoftwareDev/repos","events_url":"https://api.github.com/users/SoftwareDev/events{/privacy}","received_events_url":"https://api.github.com/users/SoftwareDev/received_events","type":"User","site_admin":false},"body":"- \"Add a key pair\" page only allows the current user to upload their own public key.\r\n(Sorry about last PR)\r\n\r\n","created_at":"2015-03-04T01:38:59Z","updated_at":"2015-03-04T01:51:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cc15a9057e2bd9e74d38c7c6e57887d54cde87e5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071/commits","review_comments_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071/comments","review_comment_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/2071/comments","statuses_url":"https://api.github.com/repos/MarkUsProject/Markus/statuses/c046dc2300bb7a42ff324aad24add6696c5a6b45","head":{"label":"SoftwareDev:newPage","ref":"newPage","sha":"c046dc2300bb7a42ff324aad24add6696c5a6b45","user":{"login":"SoftwareDev","id":5432316,"avatar_url":"https://avatars.githubusercontent.com/u/5432316?v=3","gravatar_id":"","url":"https://api.github.com/users/SoftwareDev","html_url":"https://github.com/SoftwareDev","followers_url":"https://api.github.com/users/SoftwareDev/followers","following_url":"https://api.github.com/users/SoftwareDev/following{/other_user}","gists_url":"https://api.github.com/users/SoftwareDev/gists{/gist_id}","starred_url":"https://api.github.com/users/SoftwareDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SoftwareDev/subscriptions","organizations_url":"https://api.github.com/users/SoftwareDev/orgs","repos_url":"https://api.github.com/users/SoftwareDev/repos","events_url":"https://api.github.com/users/SoftwareDev/events{/privacy}","received_events_url":"https://api.github.com/users/SoftwareDev/received_events","type":"User","site_admin":false},"repo":{"id":24034862,"name":"Markus","full_name":"SoftwareDev/Markus","owner":{"login":"SoftwareDev","id":5432316,"avatar_url":"https://avatars.githubusercontent.com/u/5432316?v=3","gravatar_id":"","url":"https://api.github.com/users/SoftwareDev","html_url":"https://github.com/SoftwareDev","followers_url":"https://api.github.com/users/SoftwareDev/followers","following_url":"https://api.github.com/users/SoftwareDev/following{/other_user}","gists_url":"https://api.github.com/users/SoftwareDev/gists{/gist_id}","starred_url":"https://api.github.com/users/SoftwareDev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SoftwareDev/subscriptions","organizations_url":"https://api.github.com/users/SoftwareDev/orgs","repos_url":"https://api.github.com/users/SoftwareDev/repos","events_url":"https://api.github.com/users/SoftwareDev/events{/privacy}","received_events_url":"https://api.github.com/users/SoftwareDev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SoftwareDev/Markus","description":"Git repository of MarkUs","fork":true,"url":"https://api.github.com/repos/SoftwareDev/Markus","forks_url":"https://api.github.com/repos/SoftwareDev/Markus/forks","keys_url":"https://api.github.com/repos/SoftwareDev/Markus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SoftwareDev/Markus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SoftwareDev/Markus/teams","hooks_url":"https://api.github.com/repos/SoftwareDev/Markus/hooks","issue_events_url":"https://api.github.com/repos/SoftwareDev/Markus/issues/events{/number}","events_url":"https://api.github.com/repos/SoftwareDev/Markus/events","assignees_url":"https://api.github.com/repos/SoftwareDev/Markus/assignees{/user}","branches_url":"https://api.github.com/repos/SoftwareDev/Markus/branches{/branch}","tags_url":"https://api.github.com/repos/SoftwareDev/Markus/tags","blobs_url":"https://api.github.com/repos/SoftwareDev/Markus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SoftwareDev/Markus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SoftwareDev/Markus/git/refs{/sha}","trees_url":"https://api.github.com/repos/SoftwareDev/Markus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SoftwareDev/Markus/statuses/{sha}","languages_url":"https://api.github.com/repos/SoftwareDev/Markus/languages","stargazers_url":"https://api.github.com/repos/SoftwareDev/Markus/stargazers","contributors_url":"https://api.github.com/repos/SoftwareDev/Markus/contributors","subscribers_url":"https://api.github.com/repos/SoftwareDev/Markus/subscribers","subscription_url":"https://api.github.com/repos/SoftwareDev/Markus/subscription","commits_url":"https://api.github.com/repos/SoftwareDev/Markus/commits{/sha}","git_commits_url":"https://api.github.com/repos/SoftwareDev/Markus/git/commits{/sha}","comments_url":"https://api.github.com/repos/SoftwareDev/Markus/comments{/number}","issue_comment_url":"https://api.github.com/repos/SoftwareDev/Markus/issues/comments{/number}","contents_url":"https://api.github.com/repos/SoftwareDev/Markus/contents/{+path}","compare_url":"https://api.github.com/repos/SoftwareDev/Markus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SoftwareDev/Markus/merges","archive_url":"https://api.github.com/repos/SoftwareDev/Markus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SoftwareDev/Markus/downloads","issues_url":"https://api.github.com/repos/SoftwareDev/Markus/issues{/number}","pulls_url":"https://api.github.com/repos/SoftwareDev/Markus/pulls{/number}","milestones_url":"https://api.github.com/repos/SoftwareDev/Markus/milestones{/number}","notifications_url":"https://api.github.com/repos/SoftwareDev/Markus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SoftwareDev/Markus/labels{/name}","releases_url":"https://api.github.com/repos/SoftwareDev/Markus/releases{/id}","created_at":"2014-09-14T22:18:29Z","updated_at":"2015-02-12T05:26:34Z","pushed_at":"2015-03-04T01:51:42Z","git_url":"git://github.com/SoftwareDev/Markus.git","ssh_url":"git@github.com:SoftwareDev/Markus.git","clone_url":"https://github.com/SoftwareDev/Markus.git","svn_url":"https://github.com/SoftwareDev/Markus","homepage":"http://www.markusproject.org","size":20562,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"MarkUsProject:git","ref":"git","sha":"9ed21e16befe6bb0923a7200a65dce42a7c3d841","user":{"login":"MarkUsProject","id":415874,"avatar_url":"https://avatars.githubusercontent.com/u/415874?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkUsProject","html_url":"https://github.com/MarkUsProject","followers_url":"https://api.github.com/users/MarkUsProject/followers","following_url":"https://api.github.com/users/MarkUsProject/following{/other_user}","gists_url":"https://api.github.com/users/MarkUsProject/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkUsProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkUsProject/subscriptions","organizations_url":"https://api.github.com/users/MarkUsProject/orgs","repos_url":"https://api.github.com/users/MarkUsProject/repos","events_url":"https://api.github.com/users/MarkUsProject/events{/privacy}","received_events_url":"https://api.github.com/users/MarkUsProject/received_events","type":"Organization","site_admin":false},"repo":{"id":940538,"name":"Markus","full_name":"MarkUsProject/Markus","owner":{"login":"MarkUsProject","id":415874,"avatar_url":"https://avatars.githubusercontent.com/u/415874?v=3","gravatar_id":"","url":"https://api.github.com/users/MarkUsProject","html_url":"https://github.com/MarkUsProject","followers_url":"https://api.github.com/users/MarkUsProject/followers","following_url":"https://api.github.com/users/MarkUsProject/following{/other_user}","gists_url":"https://api.github.com/users/MarkUsProject/gists{/gist_id}","starred_url":"https://api.github.com/users/MarkUsProject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarkUsProject/subscriptions","organizations_url":"https://api.github.com/users/MarkUsProject/orgs","repos_url":"https://api.github.com/users/MarkUsProject/repos","events_url":"https://api.github.com/users/MarkUsProject/events{/privacy}","received_events_url":"https://api.github.com/users/MarkUsProject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/MarkUsProject/Markus","description":"Git repository of MarkUs","fork":false,"url":"https://api.github.com/repos/MarkUsProject/Markus","forks_url":"https://api.github.com/repos/MarkUsProject/Markus/forks","keys_url":"https://api.github.com/repos/MarkUsProject/Markus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MarkUsProject/Markus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MarkUsProject/Markus/teams","hooks_url":"https://api.github.com/repos/MarkUsProject/Markus/hooks","issue_events_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/events{/number}","events_url":"https://api.github.com/repos/MarkUsProject/Markus/events","assignees_url":"https://api.github.com/repos/MarkUsProject/Markus/assignees{/user}","branches_url":"https://api.github.com/repos/MarkUsProject/Markus/branches{/branch}","tags_url":"https://api.github.com/repos/MarkUsProject/Markus/tags","blobs_url":"https://api.github.com/repos/MarkUsProject/Markus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MarkUsProject/Markus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MarkUsProject/Markus/git/refs{/sha}","trees_url":"https://api.github.com/repos/MarkUsProject/Markus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MarkUsProject/Markus/statuses/{sha}","languages_url":"https://api.github.com/repos/MarkUsProject/Markus/languages","stargazers_url":"https://api.github.com/repos/MarkUsProject/Markus/stargazers","contributors_url":"https://api.github.com/repos/MarkUsProject/Markus/contributors","subscribers_url":"https://api.github.com/repos/MarkUsProject/Markus/subscribers","subscription_url":"https://api.github.com/repos/MarkUsProject/Markus/subscription","commits_url":"https://api.github.com/repos/MarkUsProject/Markus/commits{/sha}","git_commits_url":"https://api.github.com/repos/MarkUsProject/Markus/git/commits{/sha}","comments_url":"https://api.github.com/repos/MarkUsProject/Markus/comments{/number}","issue_comment_url":"https://api.github.com/repos/MarkUsProject/Markus/issues/comments{/number}","contents_url":"https://api.github.com/repos/MarkUsProject/Markus/contents/{+path}","compare_url":"https://api.github.com/repos/MarkUsProject/Markus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MarkUsProject/Markus/merges","archive_url":"https://api.github.com/repos/MarkUsProject/Markus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MarkUsProject/Markus/downloads","issues_url":"https://api.github.com/repos/MarkUsProject/Markus/issues{/number}","pulls_url":"https://api.github.com/repos/MarkUsProject/Markus/pulls{/number}","milestones_url":"https://api.github.com/repos/MarkUsProject/Markus/milestones{/number}","notifications_url":"https://api.github.com/repos/MarkUsProject/Markus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MarkUsProject/Markus/labels{/name}","releases_url":"https://api.github.com/repos/MarkUsProject/Markus/releases{/id}","created_at":"2010-09-26T16:18:08Z","updated_at":"2015-03-03T17:48:42Z","pushed_at":"2015-03-03T17:48:42Z","git_url":"git://github.com/MarkUsProject/Markus.git","ssh_url":"git@github.com:MarkUsProject/Markus.git","clone_url":"https://github.com/MarkUsProject/Markus.git","svn_url":"https://github.com/MarkUsProject/Markus","homepage":"http://www.markusproject.org","size":45672,"stargazers_count":121,"watchers_count":121,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":150,"mirror_url":null,"open_issues_count":117,"forks":150,"open_issues":117,"watchers":121,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071"},"html":{"href":"https://github.com/MarkUsProject/Markus/pull/2071"},"issue":{"href":"https://api.github.com/repos/MarkUsProject/Markus/issues/2071"},"comments":{"href":"https://api.github.com/repos/MarkUsProject/Markus/issues/2071/comments"},"review_comments":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071/comments"},"review_comment":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MarkUsProject/Markus/pulls/2071/commits"},"statuses":{"href":"https://api.github.com/repos/MarkUsProject/Markus/statuses/c046dc2300bb7a42ff324aad24add6696c5a6b45"}}}}