{"action":"created","comment":{"url":"https://api.github.com/repos/ceph/ceph/pulls/comments/214665694","pull_request_review_id":151766906,"id":214665694,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDY2NTY5NA==","diff_hunk":"@@ -1,15 +1,110 @@\n # -*- coding: utf-8 -*-\n from __future__ import absolute_import\n \n-from . import ApiController, RESTController\n-from ..security import Scope\n+import cherrypy\n+\n+from . import ApiController, RESTController, UiApiController\n+from ..exceptions import RoleDoesNotExist, DashboardException,\\\n+    RoleIsAssociatedWithUser, RoleAlreadyExists\n+from ..security import Scope as SecurityScope, Permission\n from ..services.access_control import ACCESS_CTRL_DB, SYSTEM_ROLES\n \n \n-@ApiController('/role', Scope.USER)\n+@ApiController('/role', SecurityScope.USER)\n class Role(RESTController):\n+    @staticmethod\n+    def _role_to_dict(role):\n+        role_dict = role.to_dict()\n+        role_dict['system'] = role_dict['name'] in SYSTEM_ROLES\n+        return role_dict\n+\n+    @staticmethod\n+    def _validate_permissions(scopes_permissions):\n+        if scopes_permissions:\n+            for scope in scopes_permissions.keys():\n+                if scope not in SecurityScope.all_scopes():\n+                    raise DashboardException(msg='Invalid scope',\n+                                             code='invalid_scope',\n+                                             component='role')\n+                permissions = scopes_permissions[scope]\n+                if any(permission not in Permission.all_permissions()\n+                       for permission in permissions):\n+                    raise DashboardException(msg='Invalid permission',\n+                                             code='invalid_permission',\n+                                             component='role')\n+\n+    @staticmethod\n+    def _set_permissions(role, scopes_permissions):\n+        role.reset_scope_permissions()\n+        if scopes_permissions:\n+            for scope in scopes_permissions.keys():\n+                permissions = scopes_permissions[scope]\n+                if permissions:\n+                    role.set_scope_permissions(scope, permissions)\n+\n+    def list(self):\n+        roles = dict(ACCESS_CTRL_DB.roles)\n+        roles.update(SYSTEM_ROLES)\n+        roles_items = sorted(roles.items(), key=lambda role: role[1].name)","path":"src/pybind/mgr/dashboard/controllers/role.py","position":51,"original_position":51,"commit_id":"b87b4a6c8252709ae525fce48428616749780be8","original_commit_id":"b87b4a6c8252709ae525fce48428616749780be8","user":{"login":"rjfd","id":17119885,"node_id":"MDQ6VXNlcjE3MTE5ODg1","avatar_url":"https://avatars0.githubusercontent.com/u/17119885?v=4","gravatar_id":"","url":"https://api.github.com/users/rjfd","html_url":"https://github.com/rjfd","followers_url":"https://api.github.com/users/rjfd/followers","following_url":"https://api.github.com/users/rjfd/following{/other_user}","gists_url":"https://api.github.com/users/rjfd/gists{/gist_id}","starred_url":"https://api.github.com/users/rjfd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjfd/subscriptions","organizations_url":"https://api.github.com/users/rjfd/orgs","repos_url":"https://api.github.com/users/rjfd/repos","events_url":"https://api.github.com/users/rjfd/events{/privacy}","received_events_url":"https://api.github.com/users/rjfd/received_events","type":"User","site_admin":false},"body":"maybe use the dict values directly like: `roles = sorted(roles.values(), key=lambda role: role.name)`\r\nand change the following line to: `[Role._role_to_dict(r) for r in roles]`","created_at":"2018-09-03T11:57:41Z","updated_at":"2018-09-03T11:59:53Z","html_url":"https://github.com/ceph/ceph/pull/23322#discussion_r214665694","pull_request_url":"https://api.github.com/repos/ceph/ceph/pulls/23322","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/ceph/ceph/pulls/comments/214665694"},"html":{"href":"https://github.com/ceph/ceph/pull/23322#discussion_r214665694"},"pull_request":{"href":"https://api.github.com/repos/ceph/ceph/pulls/23322"}}},"pull_request":{"url":"https://api.github.com/repos/ceph/ceph/pulls/23322","id":204814808,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0ODE0ODA4","html_url":"https://github.com/ceph/ceph/pull/23322","diff_url":"https://github.com/ceph/ceph/pull/23322.diff","patch_url":"https://github.com/ceph/ceph/pull/23322.patch","issue_url":"https://api.github.com/repos/ceph/ceph/issues/23322","number":23322,"state":"open","locked":false,"title":"mgr/dashboard: Add REST API for role management","user":{"login":"ricardoasmarques","id":14297426,"node_id":"MDQ6VXNlcjE0Mjk3NDI2","avatar_url":"https://avatars2.githubusercontent.com/u/14297426?v=4","gravatar_id":"","url":"https://api.github.com/users/ricardoasmarques","html_url":"https://github.com/ricardoasmarques","followers_url":"https://api.github.com/users/ricardoasmarques/followers","following_url":"https://api.github.com/users/ricardoasmarques/following{/other_user}","gists_url":"https://api.github.com/users/ricardoasmarques/gists{/gist_id}","starred_url":"https://api.github.com/users/ricardoasmarques/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricardoasmarques/subscriptions","organizations_url":"https://api.github.com/users/ricardoasmarques/orgs","repos_url":"https://api.github.com/users/ricardoasmarques/repos","events_url":"https://api.github.com/users/ricardoasmarques/events{/privacy}","received_events_url":"https://api.github.com/users/ricardoasmarques/received_events","type":"User","site_admin":false},"body":"This PR adds the REST API to manage ceph dashboard user roles.\r\n\r\nFixes: https://tracker.ceph.com/issues/25138\r\n\r\nSigned-off-by: Ricardo Marques <rimarques@suse.com>","created_at":"2018-07-30T14:02:37Z","updated_at":"2018-09-03T11:59:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11cf80e424cb4eb92a2f945a041632c840fe9c89","assignee":null,"assignees":[],"requested_reviewers":[{"login":"sebastian-philipp","id":2574405,"node_id":"MDQ6VXNlcjI1NzQ0MDU=","avatar_url":"https://avatars2.githubusercontent.com/u/2574405?v=4","gravatar_id":"","url":"https://api.github.com/users/sebastian-philipp","html_url":"https://github.com/sebastian-philipp","followers_url":"https://api.github.com/users/sebastian-philipp/followers","following_url":"https://api.github.com/users/sebastian-philipp/following{/other_user}","gists_url":"https://api.github.com/users/sebastian-philipp/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastian-philipp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastian-philipp/subscriptions","organizations_url":"https://api.github.com/users/sebastian-philipp/orgs","repos_url":"https://api.github.com/users/sebastian-philipp/repos","events_url":"https://api.github.com/users/sebastian-philipp/events{/privacy}","received_events_url":"https://api.github.com/users/sebastian-philipp/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":850326757,"node_id":"MDU6TGFiZWw4NTAzMjY3NTc=","url":"https://api.github.com/repos/ceph/ceph/labels/dashboard","name":"dashboard","color":"68a2c1","default":false},{"id":134774006,"node_id":"MDU6TGFiZWwxMzQ3NzQwMDY=","url":"https://api.github.com/repos/ceph/ceph/labels/feature","name":"feature","color":"00ff24","default":false},{"id":340048817,"node_id":"MDU6TGFiZWwzNDAwNDg4MTc=","url":"https://api.github.com/repos/ceph/ceph/labels/needs-review","name":"needs-review","color":"d4c5f9","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ceph/ceph/pulls/23322/commits","review_comments_url":"https://api.github.com/repos/ceph/ceph/pulls/23322/comments","review_comment_url":"https://api.github.com/repos/ceph/ceph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ceph/ceph/issues/23322/comments","statuses_url":"https://api.github.com/repos/ceph/ceph/statuses/b87b4a6c8252709ae525fce48428616749780be8","head":{"label":"ricardoasmarques:wip-role-management-api","ref":"wip-role-management-api","sha":"b87b4a6c8252709ae525fce48428616749780be8","user":{"login":"ricardoasmarques","id":14297426,"node_id":"MDQ6VXNlcjE0Mjk3NDI2","avatar_url":"https://avatars2.githubusercontent.com/u/14297426?v=4","gravatar_id":"","url":"https://api.github.com/users/ricardoasmarques","html_url":"https://github.com/ricardoasmarques","followers_url":"https://api.github.com/users/ricardoasmarques/followers","following_url":"https://api.github.com/users/ricardoasmarques/following{/other_user}","gists_url":"https://api.github.com/users/ricardoasmarques/gists{/gist_id}","starred_url":"https://api.github.com/users/ricardoasmarques/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricardoasmarques/subscriptions","organizations_url":"https://api.github.com/users/ricardoasmarques/orgs","repos_url":"https://api.github.com/users/ricardoasmarques/repos","events_url":"https://api.github.com/users/ricardoasmarques/events{/privacy}","received_events_url":"https://api.github.com/users/ricardoasmarques/received_events","type":"User","site_admin":false},"repo":{"id":116938688,"node_id":"MDEwOlJlcG9zaXRvcnkxMTY5Mzg2ODg=","name":"ceph","full_name":"ricardoasmarques/ceph","owner":{"login":"ricardoasmarques","id":14297426,"node_id":"MDQ6VXNlcjE0Mjk3NDI2","avatar_url":"https://avatars2.githubusercontent.com/u/14297426?v=4","gravatar_id":"","url":"https://api.github.com/users/ricardoasmarques","html_url":"https://github.com/ricardoasmarques","followers_url":"https://api.github.com/users/ricardoasmarques/followers","following_url":"https://api.github.com/users/ricardoasmarques/following{/other_user}","gists_url":"https://api.github.com/users/ricardoasmarques/gists{/gist_id}","starred_url":"https://api.github.com/users/ricardoasmarques/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricardoasmarques/subscriptions","organizations_url":"https://api.github.com/users/ricardoasmarques/orgs","repos_url":"https://api.github.com/users/ricardoasmarques/repos","events_url":"https://api.github.com/users/ricardoasmarques/events{/privacy}","received_events_url":"https://api.github.com/users/ricardoasmarques/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ricardoasmarques/ceph","description":"Ceph is a distributed object, block, and file storage platform ","fork":true,"url":"https://api.github.com/repos/ricardoasmarques/ceph","forks_url":"https://api.github.com/repos/ricardoasmarques/ceph/forks","keys_url":"https://api.github.com/repos/ricardoasmarques/ceph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ricardoasmarques/ceph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ricardoasmarques/ceph/teams","hooks_url":"https://api.github.com/repos/ricardoasmarques/ceph/hooks","issue_events_url":"https://api.github.com/repos/ricardoasmarques/ceph/issues/events{/number}","events_url":"https://api.github.com/repos/ricardoasmarques/ceph/events","assignees_url":"https://api.github.com/repos/ricardoasmarques/ceph/assignees{/user}","branches_url":"https://api.github.com/repos/ricardoasmarques/ceph/branches{/branch}","tags_url":"https://api.github.com/repos/ricardoasmarques/ceph/tags","blobs_url":"https://api.github.com/repos/ricardoasmarques/ceph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ricardoasmarques/ceph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ricardoasmarques/ceph/git/refs{/sha}","trees_url":"https://api.github.com/repos/ricardoasmarques/ceph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ricardoasmarques/ceph/statuses/{sha}","languages_url":"https://api.github.com/repos/ricardoasmarques/ceph/languages","stargazers_url":"https://api.github.com/repos/ricardoasmarques/ceph/stargazers","contributors_url":"https://api.github.com/repos/ricardoasmarques/ceph/contributors","subscribers_url":"https://api.github.com/repos/ricardoasmarques/ceph/subscribers","subscription_url":"https://api.github.com/repos/ricardoasmarques/ceph/subscription","commits_url":"https://api.github.com/repos/ricardoasmarques/ceph/commits{/sha}","git_commits_url":"https://api.github.com/repos/ricardoasmarques/ceph/git/commits{/sha}","comments_url":"https://api.github.com/repos/ricardoasmarques/ceph/comments{/number}","issue_comment_url":"https://api.github.com/repos/ricardoasmarques/ceph/issues/comments{/number}","contents_url":"https://api.github.com/repos/ricardoasmarques/ceph/contents/{+path}","compare_url":"https://api.github.com/repos/ricardoasmarques/ceph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ricardoasmarques/ceph/merges","archive_url":"https://api.github.com/repos/ricardoasmarques/ceph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ricardoasmarques/ceph/downloads","issues_url":"https://api.github.com/repos/ricardoasmarques/ceph/issues{/number}","pulls_url":"https://api.github.com/repos/ricardoasmarques/ceph/pulls{/number}","milestones_url":"https://api.github.com/repos/ricardoasmarques/ceph/milestones{/number}","notifications_url":"https://api.github.com/repos/ricardoasmarques/ceph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ricardoasmarques/ceph/labels{/name}","releases_url":"https://api.github.com/repos/ricardoasmarques/ceph/releases{/id}","deployments_url":"https://api.github.com/repos/ricardoasmarques/ceph/deployments","created_at":"2018-01-10T09:41:33Z","updated_at":"2018-07-30T13:16:36Z","pushed_at":"2018-09-03T10:33:43Z","git_url":"git://github.com/ricardoasmarques/ceph.git","ssh_url":"git@github.com:ricardoasmarques/ceph.git","clone_url":"https://github.com/ricardoasmarques/ceph.git","svn_url":"https://github.com/ricardoasmarques/ceph","homepage":"http://ceph.com","size":295431,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"ceph:master","ref":"master","sha":"76ab1dcb73f2150272826bb1a27da8ef0562994f","user":{"login":"ceph","id":1015767,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMTU3Njc=","avatar_url":"https://avatars3.githubusercontent.com/u/1015767?v=4","gravatar_id":"","url":"https://api.github.com/users/ceph","html_url":"https://github.com/ceph","followers_url":"https://api.github.com/users/ceph/followers","following_url":"https://api.github.com/users/ceph/following{/other_user}","gists_url":"https://api.github.com/users/ceph/gists{/gist_id}","starred_url":"https://api.github.com/users/ceph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ceph/subscriptions","organizations_url":"https://api.github.com/users/ceph/orgs","repos_url":"https://api.github.com/users/ceph/repos","events_url":"https://api.github.com/users/ceph/events{/privacy}","received_events_url":"https://api.github.com/users/ceph/received_events","type":"Organization","site_admin":false},"repo":{"id":2310495,"node_id":"MDEwOlJlcG9zaXRvcnkyMzEwNDk1","name":"ceph","full_name":"ceph/ceph","owner":{"login":"ceph","id":1015767,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEwMTU3Njc=","avatar_url":"https://avatars3.githubusercontent.com/u/1015767?v=4","gravatar_id":"","url":"https://api.github.com/users/ceph","html_url":"https://github.com/ceph","followers_url":"https://api.github.com/users/ceph/followers","following_url":"https://api.github.com/users/ceph/following{/other_user}","gists_url":"https://api.github.com/users/ceph/gists{/gist_id}","starred_url":"https://api.github.com/users/ceph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ceph/subscriptions","organizations_url":"https://api.github.com/users/ceph/orgs","repos_url":"https://api.github.com/users/ceph/repos","events_url":"https://api.github.com/users/ceph/events{/privacy}","received_events_url":"https://api.github.com/users/ceph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ceph/ceph","description":"Ceph is a distributed object, block, and file storage platform ","fork":false,"url":"https://api.github.com/repos/ceph/ceph","forks_url":"https://api.github.com/repos/ceph/ceph/forks","keys_url":"https://api.github.com/repos/ceph/ceph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ceph/ceph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ceph/ceph/teams","hooks_url":"https://api.github.com/repos/ceph/ceph/hooks","issue_events_url":"https://api.github.com/repos/ceph/ceph/issues/events{/number}","events_url":"https://api.github.com/repos/ceph/ceph/events","assignees_url":"https://api.github.com/repos/ceph/ceph/assignees{/user}","branches_url":"https://api.github.com/repos/ceph/ceph/branches{/branch}","tags_url":"https://api.github.com/repos/ceph/ceph/tags","blobs_url":"https://api.github.com/repos/ceph/ceph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ceph/ceph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ceph/ceph/git/refs{/sha}","trees_url":"https://api.github.com/repos/ceph/ceph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ceph/ceph/statuses/{sha}","languages_url":"https://api.github.com/repos/ceph/ceph/languages","stargazers_url":"https://api.github.com/repos/ceph/ceph/stargazers","contributors_url":"https://api.github.com/repos/ceph/ceph/contributors","subscribers_url":"https://api.github.com/repos/ceph/ceph/subscribers","subscription_url":"https://api.github.com/repos/ceph/ceph/subscription","commits_url":"https://api.github.com/repos/ceph/ceph/commits{/sha}","git_commits_url":"https://api.github.com/repos/ceph/ceph/git/commits{/sha}","comments_url":"https://api.github.com/repos/ceph/ceph/comments{/number}","issue_comment_url":"https://api.github.com/repos/ceph/ceph/issues/comments{/number}","contents_url":"https://api.github.com/repos/ceph/ceph/contents/{+path}","compare_url":"https://api.github.com/repos/ceph/ceph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ceph/ceph/merges","archive_url":"https://api.github.com/repos/ceph/ceph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ceph/ceph/downloads","issues_url":"https://api.github.com/repos/ceph/ceph/issues{/number}","pulls_url":"https://api.github.com/repos/ceph/ceph/pulls{/number}","milestones_url":"https://api.github.com/repos/ceph/ceph/milestones{/number}","notifications_url":"https://api.github.com/repos/ceph/ceph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ceph/ceph/labels{/name}","releases_url":"https://api.github.com/repos/ceph/ceph/releases{/id}","deployments_url":"https://api.github.com/repos/ceph/ceph/deployments","created_at":"2011-09-01T21:41:26Z","updated_at":"2018-09-03T08:16:58Z","pushed_at":"2018-09-03T10:52:18Z","git_url":"git://github.com/ceph/ceph.git","ssh_url":"git@github.com:ceph/ceph.git","clone_url":"https://github.com/ceph/ceph.git","svn_url":"https://github.com/ceph/ceph","homepage":"http://ceph.com","size":307434,"stargazers_count":5023,"watchers_count":5023,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2612,"mirror_url":null,"archived":false,"open_issues_count":780,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":2612,"open_issues":780,"watchers":5023,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ceph/ceph/pulls/23322"},"html":{"href":"https://github.com/ceph/ceph/pull/23322"},"issue":{"href":"https://api.github.com/repos/ceph/ceph/issues/23322"},"comments":{"href":"https://api.github.com/repos/ceph/ceph/issues/23322/comments"},"review_comments":{"href":"https://api.github.com/repos/ceph/ceph/pulls/23322/comments"},"review_comment":{"href":"https://api.github.com/repos/ceph/ceph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ceph/ceph/pulls/23322/commits"},"statuses":{"href":"https://api.github.com/repos/ceph/ceph/statuses/b87b4a6c8252709ae525fce48428616749780be8"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"rjfd"}}