GitHub PullRequestReviewCommentEvent at 2014-09-24 14:50:15
Repository: Panoptes
Actor: edpaget
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/17975526","id":17975526,"diff_hunk":"@@ -48,37 +43,46 @@ def add_owner_ids_filter_param!\n     params.merge!({ owner_ids: owner_ids }) unless owner_ids.blank?\n   end\n \n-  def create_project_response(project)\n-    ProjectSerializer.resource( project,\n-                               nil,\n-                               languages: [ params[:project][:primary_language] ],\n-                               fields: ['title', 'description'] )\n+  def create_response(project)\n+    serializer.resource(project,\n+                        nil,\n+                        languages: [ params[:projects][:primary_language] ],\n+                        fields: ['title', 'description'] )\n   end\n \n-  def project_params\n-    params.require(:project).permit(:display_name, :name, :primary_language)\n+  def content_from_params(params)\n+    title, language = params.values_at(:display_name, :primary_language)\n+    description = params.delete(:description)\n+    {  description: description, title: title, language: language}.select { |k,v| !!v } \n   end\n \n-  def content_params\n-    params.require(:project).permit(:description, :display_name, :primary_language)\n-    .tap do |obj| \n-      obj[:title] = obj.delete(:display_name)\n-      obj[:language] = obj.delete(:primary_language)\n-    end\n+  def create_resource(create_params)\n+    content_params = content_from_params(create_params)\n+    \n+    create_params[:links] ||= Hash.new\n+    create_params[:links][:owner] = owner || api_user.user\n+\n+    project = super(create_params)\n+    project.project_contents.build(**content_params)\n+    project\n   end\n \n-  def create_project(owner)\n-    project = Project.new(project_params)\n-    content = Project.content_model.new(content_params)\n-    project.owner = owner\n+  def update_resource(update_params)\n+    content_params = content_from_params(update_params)\n+    super(update_params)\n+    project.primary_content.update_attributes(content_params)\n+  end\n \n-    ActiveRecord::Base.transaction do\n-      project.save!\n-      content.project = project\n-      content.save!\n+  def update_relation(relation, value, replace=false)","path":"app/controllers/api/v1/projects_controller.rb","position":123,"original_position":123,"commit_id":"ef46992c7d496b5041df849ec80625df894e3109","original_commit_id":"e14e3822171b94bed984b5f5d773c1a0ffc15d97","user":{"login":"edpaget","id":108177,"avatar_url":"https://avatars.githubusercontent.com/u/108177?v=2","gravatar_id":"","url":"https://api.github.com/users/edpaget","html_url":"https://github.com/edpaget","followers_url":"https://api.github.com/users/edpaget/followers","following_url":"https://api.github.com/users/edpaget/following{/other_user}","gists_url":"https://api.github.com/users/edpaget/gists{/gist_id}","starred_url":"https://api.github.com/users/edpaget/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edpaget/subscriptions","organizations_url":"https://api.github.com/users/edpaget/orgs","repos_url":"https://api.github.com/users/edpaget/repos","events_url":"https://api.github.com/users/edpaget/events{/privacy}","received_events_url":"https://api.github.com/users/edpaget/received_events","type":"User","site_admin":false},"body":"Assign to a relation should automatically save when the model is saved. Pushing should actually save as part of the method call (which is why I wrapped everything in transactions). Assigning an attribute on a relation (like you mentioned [here](https://github.com/zooniverse/Panoptes/pull/165#discussion_r17972096)) won't save the relation unless the `autosave: true` argument is part of the relation declaration. ","created_at":"2014-09-24T14:50:15Z","updated_at":"2014-09-24T14:50:15Z","html_url":"https://github.com/zooniverse/Panoptes/pull/165#discussion_r17975526","pull_request_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165","_links":{"self":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/17975526"},"html":{"href":"https://github.com/zooniverse/Panoptes/pull/165#discussion_r17975526"},"pull_request":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165"}}},"pull_request":{"url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165","id":21511344,"html_url":"https://github.com/zooniverse/Panoptes/pull/165","diff_url":"https://github.com/zooniverse/Panoptes/pull/165.diff","patch_url":"https://github.com/zooniverse/Panoptes/pull/165.patch","issue_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/165","number":165,"state":"open","locked":false,"title":"Add update to controllers","user":{"login":"edpaget","id":108177,"avatar_url":"https://avatars.githubusercontent.com/u/108177?v=2","gravatar_id":"","url":"https://api.github.com/users/edpaget","html_url":"https://github.com/edpaget","followers_url":"https://api.github.com/users/edpaget/followers","following_url":"https://api.github.com/users/edpaget/following{/other_user}","gists_url":"https://api.github.com/users/edpaget/gists{/gist_id}","starred_url":"https://api.github.com/users/edpaget/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edpaget/subscriptions","organizations_url":"https://api.github.com/users/edpaget/orgs","repos_url":"https://api.github.com/users/edpaget/repos","events_url":"https://api.github.com/users/edpaget/events{/privacy}","received_events_url":"https://api.github.com/users/edpaget/received_events","type":"User","site_admin":false},"body":"This actually does quite a bit more than adding update. I realized most of our controllers had large amounts of duplicated code due to the requirements for the JSON API format, so I attempted to abstract that code out into the JsonApiController module. \r\n\r\nWith a few differences, that I'll correct soon, this should fully reflect the published apiary api. There are couple more small things I'd like todo, namely: add specs for each JsonApiController submodule and add scopes to the link creation process. While the module should be pretty well tested by the existing controller specs, I think they should also be tested in isolation. The scopes will be necessary to prevent users from linking to otherwise private workflows and subject sets. \r\n\r\nThis closes #147 and #135.","created_at":"2014-09-19T17:21:45Z","updated_at":"2014-09-24T14:50:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"09d1631a36b74b55dacbc2ec86528d0348523b61","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165/commits","review_comments_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165/comments","review_comment_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/{number}","comments_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/165/comments","statuses_url":"https://api.github.com/repos/zooniverse/Panoptes/statuses/ef46992c7d496b5041df849ec80625df894e3109","head":{"label":"edpaget:add-update-to-controllers","ref":"add-update-to-controllers","sha":"ef46992c7d496b5041df849ec80625df894e3109","user":{"login":"edpaget","id":108177,"avatar_url":"https://avatars.githubusercontent.com/u/108177?v=2","gravatar_id":"","url":"https://api.github.com/users/edpaget","html_url":"https://github.com/edpaget","followers_url":"https://api.github.com/users/edpaget/followers","following_url":"https://api.github.com/users/edpaget/following{/other_user}","gists_url":"https://api.github.com/users/edpaget/gists{/gist_id}","starred_url":"https://api.github.com/users/edpaget/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edpaget/subscriptions","organizations_url":"https://api.github.com/users/edpaget/orgs","repos_url":"https://api.github.com/users/edpaget/repos","events_url":"https://api.github.com/users/edpaget/events{/privacy}","received_events_url":"https://api.github.com/users/edpaget/received_events","type":"User","site_admin":false},"repo":{"id":20313194,"name":"Panoptes","full_name":"edpaget/Panoptes","owner":{"login":"edpaget","id":108177,"avatar_url":"https://avatars.githubusercontent.com/u/108177?v=2","gravatar_id":"","url":"https://api.github.com/users/edpaget","html_url":"https://github.com/edpaget","followers_url":"https://api.github.com/users/edpaget/followers","following_url":"https://api.github.com/users/edpaget/following{/other_user}","gists_url":"https://api.github.com/users/edpaget/gists{/gist_id}","starred_url":"https://api.github.com/users/edpaget/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edpaget/subscriptions","organizations_url":"https://api.github.com/users/edpaget/orgs","repos_url":"https://api.github.com/users/edpaget/repos","events_url":"https://api.github.com/users/edpaget/events{/privacy}","received_events_url":"https://api.github.com/users/edpaget/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edpaget/Panoptes","description":"It sees everything","fork":true,"url":"https://api.github.com/repos/edpaget/Panoptes","forks_url":"https://api.github.com/repos/edpaget/Panoptes/forks","keys_url":"https://api.github.com/repos/edpaget/Panoptes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edpaget/Panoptes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edpaget/Panoptes/teams","hooks_url":"https://api.github.com/repos/edpaget/Panoptes/hooks","issue_events_url":"https://api.github.com/repos/edpaget/Panoptes/issues/events{/number}","events_url":"https://api.github.com/repos/edpaget/Panoptes/events","assignees_url":"https://api.github.com/repos/edpaget/Panoptes/assignees{/user}","branches_url":"https://api.github.com/repos/edpaget/Panoptes/branches{/branch}","tags_url":"https://api.github.com/repos/edpaget/Panoptes/tags","blobs_url":"https://api.github.com/repos/edpaget/Panoptes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edpaget/Panoptes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edpaget/Panoptes/git/refs{/sha}","trees_url":"https://api.github.com/repos/edpaget/Panoptes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edpaget/Panoptes/statuses/{sha}","languages_url":"https://api.github.com/repos/edpaget/Panoptes/languages","stargazers_url":"https://api.github.com/repos/edpaget/Panoptes/stargazers","contributors_url":"https://api.github.com/repos/edpaget/Panoptes/contributors","subscribers_url":"https://api.github.com/repos/edpaget/Panoptes/subscribers","subscription_url":"https://api.github.com/repos/edpaget/Panoptes/subscription","commits_url":"https://api.github.com/repos/edpaget/Panoptes/commits{/sha}","git_commits_url":"https://api.github.com/repos/edpaget/Panoptes/git/commits{/sha}","comments_url":"https://api.github.com/repos/edpaget/Panoptes/comments{/number}","issue_comment_url":"https://api.github.com/repos/edpaget/Panoptes/issues/comments/{number}","contents_url":"https://api.github.com/repos/edpaget/Panoptes/contents/{+path}","compare_url":"https://api.github.com/repos/edpaget/Panoptes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edpaget/Panoptes/merges","archive_url":"https://api.github.com/repos/edpaget/Panoptes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edpaget/Panoptes/downloads","issues_url":"https://api.github.com/repos/edpaget/Panoptes/issues{/number}","pulls_url":"https://api.github.com/repos/edpaget/Panoptes/pulls{/number}","milestones_url":"https://api.github.com/repos/edpaget/Panoptes/milestones{/number}","notifications_url":"https://api.github.com/repos/edpaget/Panoptes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edpaget/Panoptes/labels{/name}","releases_url":"https://api.github.com/repos/edpaget/Panoptes/releases{/id}","created_at":"2014-05-30T01:09:54Z","updated_at":"2014-06-25T16:11:06Z","pushed_at":"2014-09-24T14:28:37Z","git_url":"git://github.com/edpaget/Panoptes.git","ssh_url":"git@github.com:edpaget/Panoptes.git","clone_url":"https://github.com/edpaget/Panoptes.git","svn_url":"https://github.com/edpaget/Panoptes","homepage":"","size":3637,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"zooniverse:master","ref":"master","sha":"45fda1b04ae52ae9947e0378512fddbd9e1edee3","user":{"login":"zooniverse","id":106856,"avatar_url":"https://avatars.githubusercontent.com/u/106856?v=2","gravatar_id":"","url":"https://api.github.com/users/zooniverse","html_url":"https://github.com/zooniverse","followers_url":"https://api.github.com/users/zooniverse/followers","following_url":"https://api.github.com/users/zooniverse/following{/other_user}","gists_url":"https://api.github.com/users/zooniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/zooniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooniverse/subscriptions","organizations_url":"https://api.github.com/users/zooniverse/orgs","repos_url":"https://api.github.com/users/zooniverse/repos","events_url":"https://api.github.com/users/zooniverse/events{/privacy}","received_events_url":"https://api.github.com/users/zooniverse/received_events","type":"Organization","site_admin":false},"repo":{"id":19036577,"name":"Panoptes","full_name":"zooniverse/Panoptes","owner":{"login":"zooniverse","id":106856,"avatar_url":"https://avatars.githubusercontent.com/u/106856?v=2","gravatar_id":"","url":"https://api.github.com/users/zooniverse","html_url":"https://github.com/zooniverse","followers_url":"https://api.github.com/users/zooniverse/followers","following_url":"https://api.github.com/users/zooniverse/following{/other_user}","gists_url":"https://api.github.com/users/zooniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/zooniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zooniverse/subscriptions","organizations_url":"https://api.github.com/users/zooniverse/orgs","repos_url":"https://api.github.com/users/zooniverse/repos","events_url":"https://api.github.com/users/zooniverse/events{/privacy}","received_events_url":"https://api.github.com/users/zooniverse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zooniverse/Panoptes","description":"It sees everything","fork":false,"url":"https://api.github.com/repos/zooniverse/Panoptes","forks_url":"https://api.github.com/repos/zooniverse/Panoptes/forks","keys_url":"https://api.github.com/repos/zooniverse/Panoptes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zooniverse/Panoptes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zooniverse/Panoptes/teams","hooks_url":"https://api.github.com/repos/zooniverse/Panoptes/hooks","issue_events_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/events{/number}","events_url":"https://api.github.com/repos/zooniverse/Panoptes/events","assignees_url":"https://api.github.com/repos/zooniverse/Panoptes/assignees{/user}","branches_url":"https://api.github.com/repos/zooniverse/Panoptes/branches{/branch}","tags_url":"https://api.github.com/repos/zooniverse/Panoptes/tags","blobs_url":"https://api.github.com/repos/zooniverse/Panoptes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zooniverse/Panoptes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zooniverse/Panoptes/git/refs{/sha}","trees_url":"https://api.github.com/repos/zooniverse/Panoptes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zooniverse/Panoptes/statuses/{sha}","languages_url":"https://api.github.com/repos/zooniverse/Panoptes/languages","stargazers_url":"https://api.github.com/repos/zooniverse/Panoptes/stargazers","contributors_url":"https://api.github.com/repos/zooniverse/Panoptes/contributors","subscribers_url":"https://api.github.com/repos/zooniverse/Panoptes/subscribers","subscription_url":"https://api.github.com/repos/zooniverse/Panoptes/subscription","commits_url":"https://api.github.com/repos/zooniverse/Panoptes/commits{/sha}","git_commits_url":"https://api.github.com/repos/zooniverse/Panoptes/git/commits{/sha}","comments_url":"https://api.github.com/repos/zooniverse/Panoptes/comments{/number}","issue_comment_url":"https://api.github.com/repos/zooniverse/Panoptes/issues/comments/{number}","contents_url":"https://api.github.com/repos/zooniverse/Panoptes/contents/{+path}","compare_url":"https://api.github.com/repos/zooniverse/Panoptes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zooniverse/Panoptes/merges","archive_url":"https://api.github.com/repos/zooniverse/Panoptes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zooniverse/Panoptes/downloads","issues_url":"https://api.github.com/repos/zooniverse/Panoptes/issues{/number}","pulls_url":"https://api.github.com/repos/zooniverse/Panoptes/pulls{/number}","milestones_url":"https://api.github.com/repos/zooniverse/Panoptes/milestones{/number}","notifications_url":"https://api.github.com/repos/zooniverse/Panoptes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zooniverse/Panoptes/labels{/name}","releases_url":"https://api.github.com/repos/zooniverse/Panoptes/releases{/id}","created_at":"2014-04-22T16:16:02Z","updated_at":"2014-09-02T14:20:56Z","pushed_at":"2014-09-22T18:45:30Z","git_url":"git://github.com/zooniverse/Panoptes.git","ssh_url":"git@github.com:zooniverse/Panoptes.git","clone_url":"https://github.com/zooniverse/Panoptes.git","svn_url":"https://github.com/zooniverse/Panoptes","homepage":"","size":5151,"stargazers_count":2,"watchers_count":2,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":19,"forks":5,"open_issues":19,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165"},"html":{"href":"https://github.com/zooniverse/Panoptes/pull/165"},"issue":{"href":"https://api.github.com/repos/zooniverse/Panoptes/issues/165"},"comments":{"href":"https://api.github.com/repos/zooniverse/Panoptes/issues/165/comments"},"review_comments":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165/comments"},"review_comment":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/zooniverse/Panoptes/pulls/165/commits"},"statuses":{"href":"https://api.github.com/repos/zooniverse/Panoptes/statuses/ef46992c7d496b5041df849ec80625df894e3109"}}}}