{"action":"created","comment":{"url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/comments/56342519","id":56342519,"diff_hunk":"@@ -103,15 +98,20 @@ def post_params\n   #or admin within the specific post, user will be redirected to the post they just tried to edit.\n   #Otherwise, the user and/or the admin has the rights to edit/delete said post\n   def authorize_user\n+    action = params['action']\n     post = Post.find(params[:id])\n \n-    if current_user.moderator?\n-      return current_user.moderator!\n-    else\n-      unless current_user == post.user || current_user.admin?\n-        flash[:alert] = \"You must be an admin to do that\"\n-        redirect_to [post.topic, post]\n-      end\n+    # A post owner should be able to do everything.\n+    return true if post.user == current_user\n+\n+    # Only admins may destroy a post.\n+    if action == 'destroy' && !current_user.admin?\n+      flash[:alert] = \"You must be an admin to do that\"\n+      redirect_to [post.topic, post]\n+    # Only admins and moderators may update a post.\n+    elsif action == 'update' && !(current_user.moderator? || current_user.admin?)\n+      flash[:alert] = \"You must be an admin or a moderator to do that\"\n+      redirect_to [post.topic, post]\n     end\n   end","path":"app/controllers/posts_controller.rb","position":45,"original_position":45,"commit_id":"5886f4f8b0a0acbe60b702419f5ffccf1f24d604","original_commit_id":"5886f4f8b0a0acbe60b702419f5ffccf1f24d604","user":{"login":"chikamichi","id":106689,"avatar_url":"https://avatars.githubusercontent.com/u/106689?v=3","gravatar_id":"","url":"https://api.github.com/users/chikamichi","html_url":"https://github.com/chikamichi","followers_url":"https://api.github.com/users/chikamichi/followers","following_url":"https://api.github.com/users/chikamichi/following{/other_user}","gists_url":"https://api.github.com/users/chikamichi/gists{/gist_id}","starred_url":"https://api.github.com/users/chikamichi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chikamichi/subscriptions","organizations_url":"https://api.github.com/users/chikamichi/orgs","repos_url":"https://api.github.com/users/chikamichi/repos","events_url":"https://api.github.com/users/chikamichi/events{/privacy}","received_events_url":"https://api.github.com/users/chikamichi/received_events","type":"User","site_admin":false},"body":"The big picture here is that we want to react differently based on a duo:\r\n\r\n* what role does the current user have?\r\n* what is the current action?\r\n\r\nI first \"respond\" to the latter by grabbing the action from the params: `action = params['action']`. In any request, the `params` hash will expose the controller's name and current action.\r\n\r\nI then \"respond\" to the former question, in combination with the action's name:\r\n\r\n* If the post we are dealing with belongs to the current user, just authorize everything. One may do this by having the filter method return `true`.\r\n* If the action is \"destroy\", the specs say that only admins should be allowed to perform the deletion.\r\n* If the action is \"update\", the specs say that only admins and moderators should be allowed to perform the update.\r\n\r\nThe overall logic is simpler, sticks to the specs, and the code easy to read.","created_at":"2016-03-16T14:29:31Z","updated_at":"2016-03-16T14:29:31Z","html_url":"https://github.com/FrozenMeatloaf/bloccit/pull/32#discussion_r56342519","pull_request_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/comments/56342519"},"html":{"href":"https://github.com/FrozenMeatloaf/bloccit/pull/32#discussion_r56342519"},"pull_request":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32","id":63072347,"html_url":"https://github.com/FrozenMeatloaf/bloccit/pull/32","diff_url":"https://github.com/FrozenMeatloaf/bloccit/pull/32.diff","patch_url":"https://github.com/FrozenMeatloaf/bloccit/pull/32.patch","issue_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/32","number":32,"state":"open","locked":false,"title":"Assignment 40 mentor","user":{"login":"chikamichi","id":106689,"avatar_url":"https://avatars.githubusercontent.com/u/106689?v=3","gravatar_id":"","url":"https://api.github.com/users/chikamichi","html_url":"https://github.com/chikamichi","followers_url":"https://api.github.com/users/chikamichi/followers","following_url":"https://api.github.com/users/chikamichi/following{/other_user}","gists_url":"https://api.github.com/users/chikamichi/gists{/gist_id}","starred_url":"https://api.github.com/users/chikamichi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chikamichi/subscriptions","organizations_url":"https://api.github.com/users/chikamichi/orgs","repos_url":"https://api.github.com/users/chikamichi/repos","events_url":"https://api.github.com/users/chikamichi/events{/privacy}","received_events_url":"https://api.github.com/users/chikamichi/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nI have reworked this assignment as a commit to better demonstrate what was expected. Inline comments below.\r\n\r\n*Edit*: this PR not meant to be merged.","created_at":"2016-03-16T14:23:41Z","updated_at":"2016-03-16T14:29:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32/commits","review_comments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32/comments","review_comment_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/32/comments","statuses_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/statuses/5886f4f8b0a0acbe60b702419f5ffccf1f24d604","head":{"label":"FrozenMeatloaf:assignment-40-mentor","ref":"assignment-40-mentor","sha":"5886f4f8b0a0acbe60b702419f5ffccf1f24d604","user":{"login":"FrozenMeatloaf","id":16764493,"avatar_url":"https://avatars.githubusercontent.com/u/16764493?v=3","gravatar_id":"","url":"https://api.github.com/users/FrozenMeatloaf","html_url":"https://github.com/FrozenMeatloaf","followers_url":"https://api.github.com/users/FrozenMeatloaf/followers","following_url":"https://api.github.com/users/FrozenMeatloaf/following{/other_user}","gists_url":"https://api.github.com/users/FrozenMeatloaf/gists{/gist_id}","starred_url":"https://api.github.com/users/FrozenMeatloaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FrozenMeatloaf/subscriptions","organizations_url":"https://api.github.com/users/FrozenMeatloaf/orgs","repos_url":"https://api.github.com/users/FrozenMeatloaf/repos","events_url":"https://api.github.com/users/FrozenMeatloaf/events{/privacy}","received_events_url":"https://api.github.com/users/FrozenMeatloaf/received_events","type":"User","site_admin":false},"repo":{"id":51555547,"name":"bloccit","full_name":"FrozenMeatloaf/bloccit","owner":{"login":"FrozenMeatloaf","id":16764493,"avatar_url":"https://avatars.githubusercontent.com/u/16764493?v=3","gravatar_id":"","url":"https://api.github.com/users/FrozenMeatloaf","html_url":"https://github.com/FrozenMeatloaf","followers_url":"https://api.github.com/users/FrozenMeatloaf/followers","following_url":"https://api.github.com/users/FrozenMeatloaf/following{/other_user}","gists_url":"https://api.github.com/users/FrozenMeatloaf/gists{/gist_id}","starred_url":"https://api.github.com/users/FrozenMeatloaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FrozenMeatloaf/subscriptions","organizations_url":"https://api.github.com/users/FrozenMeatloaf/orgs","repos_url":"https://api.github.com/users/FrozenMeatloaf/repos","events_url":"https://api.github.com/users/FrozenMeatloaf/events{/privacy}","received_events_url":"https://api.github.com/users/FrozenMeatloaf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/FrozenMeatloaf/bloccit","description":"Bloccit bloc assignments","fork":false,"url":"https://api.github.com/repos/FrozenMeatloaf/bloccit","forks_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/forks","keys_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/teams","hooks_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/hooks","issue_events_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/events{/number}","events_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/events","assignees_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/assignees{/user}","branches_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/branches{/branch}","tags_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/tags","blobs_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/refs{/sha}","trees_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/statuses/{sha}","languages_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/languages","stargazers_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/stargazers","contributors_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/contributors","subscribers_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/subscribers","subscription_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/subscription","commits_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/commits{/sha}","git_commits_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/commits{/sha}","comments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/comments{/number}","issue_comment_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/comments{/number}","contents_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/contents/{+path}","compare_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/merges","archive_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/downloads","issues_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues{/number}","pulls_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls{/number}","milestones_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/milestones{/number}","notifications_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/labels{/name}","releases_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/releases{/id}","deployments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/deployments","created_at":"2016-02-11T23:35:43Z","updated_at":"2016-03-07T06:19:09Z","pushed_at":"2016-03-16T14:23:41Z","git_url":"git://github.com/FrozenMeatloaf/bloccit.git","ssh_url":"git@github.com:FrozenMeatloaf/bloccit.git","clone_url":"https://github.com/FrozenMeatloaf/bloccit.git","svn_url":"https://github.com/FrozenMeatloaf/bloccit","homepage":null,"size":561,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":0,"default_branch":"master"}},"base":{"label":"FrozenMeatloaf:master","ref":"master","sha":"333d208af5397708ebd0885c66d6b4c359f94362","user":{"login":"FrozenMeatloaf","id":16764493,"avatar_url":"https://avatars.githubusercontent.com/u/16764493?v=3","gravatar_id":"","url":"https://api.github.com/users/FrozenMeatloaf","html_url":"https://github.com/FrozenMeatloaf","followers_url":"https://api.github.com/users/FrozenMeatloaf/followers","following_url":"https://api.github.com/users/FrozenMeatloaf/following{/other_user}","gists_url":"https://api.github.com/users/FrozenMeatloaf/gists{/gist_id}","starred_url":"https://api.github.com/users/FrozenMeatloaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FrozenMeatloaf/subscriptions","organizations_url":"https://api.github.com/users/FrozenMeatloaf/orgs","repos_url":"https://api.github.com/users/FrozenMeatloaf/repos","events_url":"https://api.github.com/users/FrozenMeatloaf/events{/privacy}","received_events_url":"https://api.github.com/users/FrozenMeatloaf/received_events","type":"User","site_admin":false},"repo":{"id":51555547,"name":"bloccit","full_name":"FrozenMeatloaf/bloccit","owner":{"login":"FrozenMeatloaf","id":16764493,"avatar_url":"https://avatars.githubusercontent.com/u/16764493?v=3","gravatar_id":"","url":"https://api.github.com/users/FrozenMeatloaf","html_url":"https://github.com/FrozenMeatloaf","followers_url":"https://api.github.com/users/FrozenMeatloaf/followers","following_url":"https://api.github.com/users/FrozenMeatloaf/following{/other_user}","gists_url":"https://api.github.com/users/FrozenMeatloaf/gists{/gist_id}","starred_url":"https://api.github.com/users/FrozenMeatloaf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FrozenMeatloaf/subscriptions","organizations_url":"https://api.github.com/users/FrozenMeatloaf/orgs","repos_url":"https://api.github.com/users/FrozenMeatloaf/repos","events_url":"https://api.github.com/users/FrozenMeatloaf/events{/privacy}","received_events_url":"https://api.github.com/users/FrozenMeatloaf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/FrozenMeatloaf/bloccit","description":"Bloccit bloc assignments","fork":false,"url":"https://api.github.com/repos/FrozenMeatloaf/bloccit","forks_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/forks","keys_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/teams","hooks_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/hooks","issue_events_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/events{/number}","events_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/events","assignees_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/assignees{/user}","branches_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/branches{/branch}","tags_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/tags","blobs_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/refs{/sha}","trees_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/statuses/{sha}","languages_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/languages","stargazers_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/stargazers","contributors_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/contributors","subscribers_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/subscribers","subscription_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/subscription","commits_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/commits{/sha}","git_commits_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/git/commits{/sha}","comments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/comments{/number}","issue_comment_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/comments{/number}","contents_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/contents/{+path}","compare_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/merges","archive_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/downloads","issues_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues{/number}","pulls_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls{/number}","milestones_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/milestones{/number}","notifications_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/labels{/name}","releases_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/releases{/id}","deployments_url":"https://api.github.com/repos/FrozenMeatloaf/bloccit/deployments","created_at":"2016-02-11T23:35:43Z","updated_at":"2016-03-07T06:19:09Z","pushed_at":"2016-03-16T14:23:41Z","git_url":"git://github.com/FrozenMeatloaf/bloccit.git","ssh_url":"git@github.com:FrozenMeatloaf/bloccit.git","clone_url":"https://github.com/FrozenMeatloaf/bloccit.git","svn_url":"https://github.com/FrozenMeatloaf/bloccit","homepage":null,"size":561,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32"},"html":{"href":"https://github.com/FrozenMeatloaf/bloccit/pull/32"},"issue":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/32"},"comments":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/FrozenMeatloaf/bloccit/statuses/5886f4f8b0a0acbe60b702419f5ffccf1f24d604"}}}}