{"action":"created","comment":{"url":"https://api.github.com/repos/aviabird/snitch/pulls/comments/199684096","pull_request_review_id":133849486,"id":199684096,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5OTY4NDA5Ng==","diff_hunk":"@@ -0,0 +1,22 @@\n+defmodule AdminAppWeb.RoleHelper do\n+  @moduledoc false\n+\n+  def load_role_permissions do\n+    File.cwd!()\n+    |> Path.join(\"/priv/role_manifest.yaml\")\n+    |> YamlElixir.read_from_file()\n+  end\n+\n+  def check_role_permission(\"admin\", _, _, _), do: true\n+\n+  def check_role_permission(_role, user_permissions, controller, action) do\n+    {:ok, permissions} = load_role_permissions()\n+\n+    for user_permission <- user_permissions,\n+        permission <- permissions,\n+        Map.has_key?(permission, user_permission),\n+        Map.has_key?(permission[user_permission], controller) do\n+      Enum.member?(permission[user_permission][controller], action)","path":"apps/admin_app/lib/admin_app_web/auth_pipeline/role_helper.ex","position":19,"original_position":19,"commit_id":"f12d057aa379858e9d040fedf69d37ab886b0944","original_commit_id":"f12d057aa379858e9d040fedf69d37ab886b0944","user":{"login":"pkrawat1","id":3807725,"node_id":"MDQ6VXNlcjM4MDc3MjU=","avatar_url":"https://avatars2.githubusercontent.com/u/3807725?v=4","gravatar_id":"","url":"https://api.github.com/users/pkrawat1","html_url":"https://github.com/pkrawat1","followers_url":"https://api.github.com/users/pkrawat1/followers","following_url":"https://api.github.com/users/pkrawat1/following{/other_user}","gists_url":"https://api.github.com/users/pkrawat1/gists{/gist_id}","starred_url":"https://api.github.com/users/pkrawat1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkrawat1/subscriptions","organizations_url":"https://api.github.com/users/pkrawat1/orgs","repos_url":"https://api.github.com/users/pkrawat1/repos","events_url":"https://api.github.com/users/pkrawat1/events{/privacy}","received_events_url":"https://api.github.com/users/pkrawat1/received_events","type":"User","site_admin":false},"body":"@doc please","created_at":"2018-07-03T05:02:29Z","updated_at":"2018-07-03T05:02:30Z","html_url":"https://github.com/aviabird/snitch/pull/115#discussion_r199684096","pull_request_url":"https://api.github.com/repos/aviabird/snitch/pulls/115","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/comments/199684096"},"html":{"href":"https://github.com/aviabird/snitch/pull/115#discussion_r199684096"},"pull_request":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/aviabird/snitch/pulls/115","id":198580618,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk4NTgwNjE4","html_url":"https://github.com/aviabird/snitch/pull/115","diff_url":"https://github.com/aviabird/snitch/pull/115.diff","patch_url":"https://github.com/aviabird/snitch/pull/115.patch","issue_url":"https://api.github.com/repos/aviabird/snitch/issues/115","number":115,"state":"open","locked":false,"title":"Roles, Permissions and Authorisation","user":{"login":"arjun289","id":9413385,"node_id":"MDQ6VXNlcjk0MTMzODU=","avatar_url":"https://avatars0.githubusercontent.com/u/9413385?v=4","gravatar_id":"","url":"https://api.github.com/users/arjun289","html_url":"https://github.com/arjun289","followers_url":"https://api.github.com/users/arjun289/followers","following_url":"https://api.github.com/users/arjun289/following{/other_user}","gists_url":"https://api.github.com/users/arjun289/gists{/gist_id}","starred_url":"https://api.github.com/users/arjun289/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arjun289/subscriptions","organizations_url":"https://api.github.com/users/arjun289/orgs","repos_url":"https://api.github.com/users/arjun289/repos","events_url":"https://api.github.com/users/arjun289/events{/privacy}","received_events_url":"https://api.github.com/users/arjun289/received_events","type":"User","site_admin":false},"body":"## Motivation\r\n[Pivotal story](https://www.pivotaltracker.com/story/show/158439773): Create [Role Based Access Control](https://en.wikipedia.org/wiki/Role-based_access_control) in admin application.\r\n\r\nThe admin app has no authorisation functionality. We imagine that typically, people will want to administer their backend with a team comprising of users with varying access levels or ability to access certain areas of the admin app.\r\n\r\n## Description\r\nAn admin can do the usual CRUD for `Roles` and `Permissions`.\r\n`Role`s can now be associated with the (**new**) `Permission`s schema!\r\n```\r\nUser --- (has one) --> Role --- (many) --> Permission\r\n```\r\n\r\n### `AuthorizePlug` and seeding\r\nPermissions also need to be associated with controllers and in turn with the functions in them to create rules for authorization. This is created using `role_manifest.yaml`.\r\nConsider  a _permission_  `manages_orders`. This can be related with OrderController as:\r\n```\r\nmanages_orders:\r\n  - OrderController\r\n    - view\r\n    - edit\r\n    - list\r\n```\r\nThis will allow a role having the permission `manage_orders` to carry out the functions listed (`view`, `list`, `edit`).\r\n\r\n------\r\n\r\n## Checklist\r\n<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->\r\n<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->\r\n- [ ] I have read [CONTRIBUTING.md][contributing].\r\n- [ ] My code follows the [style guidelines][contributing] of this project.\r\n- [x] I have commented my code, particularly in hard-to-understand areas.\r\n- [x] My code does not generate any (new) [`credo`][credo] and compile-time warnings.\r\n- [x] I have updated the documentation wherever necessary.\r\n- [x] I have added tests to cover my changes.\r\n\r\n[contributing]: https://github.com/aviabird/snitch/CONTRIBUTING.md\r\n[credo]: https://github.com/rrrene/credo\r\n\r\n<!--- DO NOT REMOVE SECTION BELOW -->\r\n------\r\nDear Gatekeeper,\r\n\r\nPlease make sure that the commits that will be merged or rebased into the base\r\nbranch are [formatted according to our standards][commit-style].\r\n\r\n> The only additional requirement is that the the PR number must appear in the\r\n> commit title in brackets: `(#XXX)`\r\n\r\n[commit-style]: https://github.com/aviabird/snitch/blob/develop/CONTRIBUTING.md#styling\r\n","created_at":"2018-07-02T06:08:26Z","updated_at":"2018-07-03T05:02:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6b2d338976fa54174a805e6ae067d404b6bedba","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":839033828,"node_id":"MDU6TGFiZWw4MzkwMzM4Mjg=","url":"https://api.github.com/repos/aviabird/snitch/labels/PR%20state:%20review%20and%20merge","name":"PR state: review and merge","color":"8bf977","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/aviabird/snitch/pulls/115/commits","review_comments_url":"https://api.github.com/repos/aviabird/snitch/pulls/115/comments","review_comment_url":"https://api.github.com/repos/aviabird/snitch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aviabird/snitch/issues/115/comments","statuses_url":"https://api.github.com/repos/aviabird/snitch/statuses/f12d057aa379858e9d040fedf69d37ab886b0944","head":{"label":"aviabird:manage-permission","ref":"manage-permission","sha":"f12d057aa379858e9d040fedf69d37ab886b0944","user":{"login":"aviabird","id":22424801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyNDI0ODAx","avatar_url":"https://avatars3.githubusercontent.com/u/22424801?v=4","gravatar_id":"","url":"https://api.github.com/users/aviabird","html_url":"https://github.com/aviabird","followers_url":"https://api.github.com/users/aviabird/followers","following_url":"https://api.github.com/users/aviabird/following{/other_user}","gists_url":"https://api.github.com/users/aviabird/gists{/gist_id}","starred_url":"https://api.github.com/users/aviabird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviabird/subscriptions","organizations_url":"https://api.github.com/users/aviabird/orgs","repos_url":"https://api.github.com/users/aviabird/repos","events_url":"https://api.github.com/users/aviabird/events{/privacy}","received_events_url":"https://api.github.com/users/aviabird/received_events","type":"Organization","site_admin":false},"repo":{"id":121001913,"node_id":"MDEwOlJlcG9zaXRvcnkxMjEwMDE5MTM=","name":"snitch","full_name":"aviabird/snitch","owner":{"login":"aviabird","id":22424801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyNDI0ODAx","avatar_url":"https://avatars3.githubusercontent.com/u/22424801?v=4","gravatar_id":"","url":"https://api.github.com/users/aviabird","html_url":"https://github.com/aviabird","followers_url":"https://api.github.com/users/aviabird/followers","following_url":"https://api.github.com/users/aviabird/following{/other_user}","gists_url":"https://api.github.com/users/aviabird/gists{/gist_id}","starred_url":"https://api.github.com/users/aviabird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviabird/subscriptions","organizations_url":"https://api.github.com/users/aviabird/orgs","repos_url":"https://api.github.com/users/aviabird/repos","events_url":"https://api.github.com/users/aviabird/events{/privacy}","received_events_url":"https://api.github.com/users/aviabird/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aviabird/snitch","description":"E-Commerce re-invented in Elixir","fork":false,"url":"https://api.github.com/repos/aviabird/snitch","forks_url":"https://api.github.com/repos/aviabird/snitch/forks","keys_url":"https://api.github.com/repos/aviabird/snitch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aviabird/snitch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aviabird/snitch/teams","hooks_url":"https://api.github.com/repos/aviabird/snitch/hooks","issue_events_url":"https://api.github.com/repos/aviabird/snitch/issues/events{/number}","events_url":"https://api.github.com/repos/aviabird/snitch/events","assignees_url":"https://api.github.com/repos/aviabird/snitch/assignees{/user}","branches_url":"https://api.github.com/repos/aviabird/snitch/branches{/branch}","tags_url":"https://api.github.com/repos/aviabird/snitch/tags","blobs_url":"https://api.github.com/repos/aviabird/snitch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aviabird/snitch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aviabird/snitch/git/refs{/sha}","trees_url":"https://api.github.com/repos/aviabird/snitch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aviabird/snitch/statuses/{sha}","languages_url":"https://api.github.com/repos/aviabird/snitch/languages","stargazers_url":"https://api.github.com/repos/aviabird/snitch/stargazers","contributors_url":"https://api.github.com/repos/aviabird/snitch/contributors","subscribers_url":"https://api.github.com/repos/aviabird/snitch/subscribers","subscription_url":"https://api.github.com/repos/aviabird/snitch/subscription","commits_url":"https://api.github.com/repos/aviabird/snitch/commits{/sha}","git_commits_url":"https://api.github.com/repos/aviabird/snitch/git/commits{/sha}","comments_url":"https://api.github.com/repos/aviabird/snitch/comments{/number}","issue_comment_url":"https://api.github.com/repos/aviabird/snitch/issues/comments{/number}","contents_url":"https://api.github.com/repos/aviabird/snitch/contents/{+path}","compare_url":"https://api.github.com/repos/aviabird/snitch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aviabird/snitch/merges","archive_url":"https://api.github.com/repos/aviabird/snitch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aviabird/snitch/downloads","issues_url":"https://api.github.com/repos/aviabird/snitch/issues{/number}","pulls_url":"https://api.github.com/repos/aviabird/snitch/pulls{/number}","milestones_url":"https://api.github.com/repos/aviabird/snitch/milestones{/number}","notifications_url":"https://api.github.com/repos/aviabird/snitch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aviabird/snitch/labels{/name}","releases_url":"https://api.github.com/repos/aviabird/snitch/releases{/id}","deployments_url":"https://api.github.com/repos/aviabird/snitch/deployments","created_at":"2018-02-10T09:24:32Z","updated_at":"2018-07-02T18:38:14Z","pushed_at":"2018-07-02T22:26:22Z","git_url":"git://github.com/aviabird/snitch.git","ssh_url":"git@github.com:aviabird/snitch.git","clone_url":"https://github.com/aviabird/snitch.git","svn_url":"https://github.com/aviabird/snitch","homepage":"","size":914,"stargazers_count":14,"watchers_count":14,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"archived":false,"open_issues_count":21,"license":null,"forks":7,"open_issues":21,"watchers":14,"default_branch":"develop"}},"base":{"label":"aviabird:develop","ref":"develop","sha":"59132a591e8ba77455347c7281dc87b7cb57be80","user":{"login":"aviabird","id":22424801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyNDI0ODAx","avatar_url":"https://avatars3.githubusercontent.com/u/22424801?v=4","gravatar_id":"","url":"https://api.github.com/users/aviabird","html_url":"https://github.com/aviabird","followers_url":"https://api.github.com/users/aviabird/followers","following_url":"https://api.github.com/users/aviabird/following{/other_user}","gists_url":"https://api.github.com/users/aviabird/gists{/gist_id}","starred_url":"https://api.github.com/users/aviabird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviabird/subscriptions","organizations_url":"https://api.github.com/users/aviabird/orgs","repos_url":"https://api.github.com/users/aviabird/repos","events_url":"https://api.github.com/users/aviabird/events{/privacy}","received_events_url":"https://api.github.com/users/aviabird/received_events","type":"Organization","site_admin":false},"repo":{"id":121001913,"node_id":"MDEwOlJlcG9zaXRvcnkxMjEwMDE5MTM=","name":"snitch","full_name":"aviabird/snitch","owner":{"login":"aviabird","id":22424801,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyNDI0ODAx","avatar_url":"https://avatars3.githubusercontent.com/u/22424801?v=4","gravatar_id":"","url":"https://api.github.com/users/aviabird","html_url":"https://github.com/aviabird","followers_url":"https://api.github.com/users/aviabird/followers","following_url":"https://api.github.com/users/aviabird/following{/other_user}","gists_url":"https://api.github.com/users/aviabird/gists{/gist_id}","starred_url":"https://api.github.com/users/aviabird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviabird/subscriptions","organizations_url":"https://api.github.com/users/aviabird/orgs","repos_url":"https://api.github.com/users/aviabird/repos","events_url":"https://api.github.com/users/aviabird/events{/privacy}","received_events_url":"https://api.github.com/users/aviabird/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aviabird/snitch","description":"E-Commerce re-invented in Elixir","fork":false,"url":"https://api.github.com/repos/aviabird/snitch","forks_url":"https://api.github.com/repos/aviabird/snitch/forks","keys_url":"https://api.github.com/repos/aviabird/snitch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aviabird/snitch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aviabird/snitch/teams","hooks_url":"https://api.github.com/repos/aviabird/snitch/hooks","issue_events_url":"https://api.github.com/repos/aviabird/snitch/issues/events{/number}","events_url":"https://api.github.com/repos/aviabird/snitch/events","assignees_url":"https://api.github.com/repos/aviabird/snitch/assignees{/user}","branches_url":"https://api.github.com/repos/aviabird/snitch/branches{/branch}","tags_url":"https://api.github.com/repos/aviabird/snitch/tags","blobs_url":"https://api.github.com/repos/aviabird/snitch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aviabird/snitch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aviabird/snitch/git/refs{/sha}","trees_url":"https://api.github.com/repos/aviabird/snitch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aviabird/snitch/statuses/{sha}","languages_url":"https://api.github.com/repos/aviabird/snitch/languages","stargazers_url":"https://api.github.com/repos/aviabird/snitch/stargazers","contributors_url":"https://api.github.com/repos/aviabird/snitch/contributors","subscribers_url":"https://api.github.com/repos/aviabird/snitch/subscribers","subscription_url":"https://api.github.com/repos/aviabird/snitch/subscription","commits_url":"https://api.github.com/repos/aviabird/snitch/commits{/sha}","git_commits_url":"https://api.github.com/repos/aviabird/snitch/git/commits{/sha}","comments_url":"https://api.github.com/repos/aviabird/snitch/comments{/number}","issue_comment_url":"https://api.github.com/repos/aviabird/snitch/issues/comments{/number}","contents_url":"https://api.github.com/repos/aviabird/snitch/contents/{+path}","compare_url":"https://api.github.com/repos/aviabird/snitch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aviabird/snitch/merges","archive_url":"https://api.github.com/repos/aviabird/snitch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aviabird/snitch/downloads","issues_url":"https://api.github.com/repos/aviabird/snitch/issues{/number}","pulls_url":"https://api.github.com/repos/aviabird/snitch/pulls{/number}","milestones_url":"https://api.github.com/repos/aviabird/snitch/milestones{/number}","notifications_url":"https://api.github.com/repos/aviabird/snitch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aviabird/snitch/labels{/name}","releases_url":"https://api.github.com/repos/aviabird/snitch/releases{/id}","deployments_url":"https://api.github.com/repos/aviabird/snitch/deployments","created_at":"2018-02-10T09:24:32Z","updated_at":"2018-07-02T18:38:14Z","pushed_at":"2018-07-02T22:26:22Z","git_url":"git://github.com/aviabird/snitch.git","ssh_url":"git@github.com:aviabird/snitch.git","clone_url":"https://github.com/aviabird/snitch.git","svn_url":"https://github.com/aviabird/snitch","homepage":"","size":914,"stargazers_count":14,"watchers_count":14,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"archived":false,"open_issues_count":21,"license":null,"forks":7,"open_issues":21,"watchers":14,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/115"},"html":{"href":"https://github.com/aviabird/snitch/pull/115"},"issue":{"href":"https://api.github.com/repos/aviabird/snitch/issues/115"},"comments":{"href":"https://api.github.com/repos/aviabird/snitch/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aviabird/snitch/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/aviabird/snitch/statuses/f12d057aa379858e9d040fedf69d37ab886b0944"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"pkrawat1"}}