{"action":"created","comment":{"url":"https://api.github.com/repos/getredash/redash/pulls/comments/78119619","id":78119619,"diff_hunk":"@@ -0,0 +1,77 @@\n+import logging\n+from redash.handlers.base import BaseResource\n+from redash.models import AccessPermission\n+from flask import request\n+from flask_restful import abort\n+\n+class AccessListResource(BaseResource):\n+\n+    def get(self, object_type, object_id):\n+\n+        permissions = AccessPermission.select(AccessPermission)\\\n+                .where(AccessPermission.object_id == object_id)\\\n+                .where(AccessPermission.object_type == object_type)\\\n+                .where(AccessPermission.grantor == self.current_user)\n+\n+        result = {}\n+        for perm in permissions:\n+            if perm.access_type not in result:\n+                result[perm.access_type] = []\n+            result[perm.access_type].append(perm.grantee.to_dict())\n+\n+        return result\n+\n+\n+class AccessGrantResource(BaseResource):\n+\n+    def post(self, object_type, object_id):\n+\n+        req = request.get_json(True)\n+        grantee = req['user_id']\n+        access_type = req['access_type']\n+\n+        permissions = AccessPermission.select(AccessPermission)\\\n+                .where(AccessPermission.object_id == object_id)\\\n+                .where(AccessPermission.object_type == object_type)\\\n+                .where(AccessPermission.grantee == grantee)\\\n+                .where(AccessPermission.grantor == self.current_user)\\\n+                .where(AccessPermission.access_type == access_type)\n+\n+        if permissions.count() > 0:\n+            return {'result': 'already_granted'}\n+\n+        perm = AccessPermission()\n+        perm.object_type = object_type\n+        perm.object_id = object_id\n+        perm.access_type = access_type\n+        perm.grantor = self.current_user\n+        perm.grantee = grantee\n+        perm.save()","path":"redash/handlers/access.py","position":null,"original_position":49,"commit_id":"e89802b1e0fee76dda63a5890a1830a976550672","original_commit_id":"c403f4e00096b3b3c7cf0e6149f9b22b1e57a419","user":{"login":"whummer","id":2807888,"avatar_url":"https://avatars.githubusercontent.com/u/2807888?v=3","gravatar_id":"","url":"https://api.github.com/users/whummer","html_url":"https://github.com/whummer","followers_url":"https://api.github.com/users/whummer/followers","following_url":"https://api.github.com/users/whummer/following{/other_user}","gists_url":"https://api.github.com/users/whummer/gists{/gist_id}","starred_url":"https://api.github.com/users/whummer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whummer/subscriptions","organizations_url":"https://api.github.com/users/whummer/orgs","repos_url":"https://api.github.com/users/whummer/repos","events_url":"https://api.github.com/users/whummer/events{/privacy}","received_events_url":"https://api.github.com/users/whummer/received_events","type":"User","site_admin":false},"body":"Done. Moved to `AccessPermission` model.","created_at":"2016-09-09T02:05:49Z","updated_at":"2016-09-09T02:05:49Z","html_url":"https://github.com/getredash/redash/pull/1113#discussion_r78119619","pull_request_url":"https://api.github.com/repos/getredash/redash/pulls/1113","_links":{"self":{"href":"https://api.github.com/repos/getredash/redash/pulls/comments/78119619"},"html":{"href":"https://github.com/getredash/redash/pull/1113#discussion_r78119619"},"pull_request":{"href":"https://api.github.com/repos/getredash/redash/pulls/1113"}}},"pull_request":{"url":"https://api.github.com/repos/getredash/redash/pulls/1113","id":73539547,"html_url":"https://github.com/getredash/redash/pull/1113","diff_url":"https://github.com/getredash/redash/pull/1113.diff","patch_url":"https://github.com/getredash/redash/pull/1113.patch","issue_url":"https://api.github.com/repos/getredash/redash/issues/1113","number":1113,"state":"open","locked":false,"title":"Add: share modify/access permissions for queries and dashboard","user":{"login":"whummer","id":2807888,"avatar_url":"https://avatars.githubusercontent.com/u/2807888?v=3","gravatar_id":"","url":"https://api.github.com/users/whummer","html_url":"https://github.com/whummer","followers_url":"https://api.github.com/users/whummer/followers","following_url":"https://api.github.com/users/whummer/following{/other_user}","gists_url":"https://api.github.com/users/whummer/gists{/gist_id}","starred_url":"https://api.github.com/users/whummer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whummer/subscriptions","organizations_url":"https://api.github.com/users/whummer/orgs","repos_url":"https://api.github.com/users/whummer/repos","events_url":"https://api.github.com/users/whummer/events{/privacy}","received_events_url":"https://api.github.com/users/whummer/received_events","type":"User","site_admin":false},"body":"Hi @arikfr,\r\n\r\nThis PR allows users to share edit permissions for a given query or dashboard. This feature request has previously been [discussed here](https://discuss.redash.io/t/ability-to-contribute-to-someone-elses-query/14).\r\n\r\nA new button *\"Share Edit Permissions\"* has been added to the \"...\" details popup when viewing the source of a query (or dashboard). \r\n![image](https://cloud.githubusercontent.com/assets/2807888/16001106/bc37037a-3193-11e6-8e70-2a76d2007029.png)\r\n\r\n\r\nTo manage the access permissions, a modal dialog is used (similar to the dialog used for managing group members). To give an existing user \"modify\" access, the user can simply be selected from the search/dropdown list. To revoke access, use the \"Remove\" button and changes will be effected immediately. Note that the same modal code (view and controller) is used for both, query permissions and dashboard permissions, to avoid code duplication.\r\n![image](https://cloud.githubusercontent.com/assets/2807888/16001038/4e263dd8-3193-11e6-89ef-5a9c82cad8d4.png)\r\n\r\nAt the core of the approach is a new table and model entity `Change`, which keeps track of the historical changes made to model entities (i.e., Query, and Dashboard). Whenever a change is made, a new record is added to the `changes` table. The UI is aware of the current \"version\" of the query/dashboard it is working with, and the approach implements \"optimistic locking\" to avoid concurrent changes to override each other. If a conflict is detected, a warning message is displayed to the user (see below). This can be easily tested by using two browser sessions with two different users, attempting to modify the same query.\r\n![image](https://cloud.githubusercontent.com/assets/2807888/16001086/9d2c8ab8-3193-11e6-806e-5516c19b9448.png)\r\n\r\nThe access permissions are handled via a new API endpoint `/api/access/`, which allows to 1) list, 2) grant, and 3) revoke access permissions, as well as to 4) attempt an access and receive an access \"granted\" or \"denied\" decision.\r\n\r\nA set of tests has been added to cover the basic functionality of managing access permissions.","created_at":"2016-06-13T08:39:14Z","updated_at":"2016-09-09T02:05:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6622059ae724ffbc1d28464c99df9ef6636b6507","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/getredash/redash/milestones/8","html_url":"https://github.com/getredash/redash/milestones/v0.12.0","labels_url":"https://api.github.com/repos/getredash/redash/milestones/8/labels","id":1825264,"number":8,"title":"v0.12.0","description":"","creator":{"login":"arikfr","id":71468,"avatar_url":"https://avatars.githubusercontent.com/u/71468?v=3","gravatar_id":"","url":"https://api.github.com/users/arikfr","html_url":"https://github.com/arikfr","followers_url":"https://api.github.com/users/arikfr/followers","following_url":"https://api.github.com/users/arikfr/following{/other_user}","gists_url":"https://api.github.com/users/arikfr/gists{/gist_id}","starred_url":"https://api.github.com/users/arikfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arikfr/subscriptions","organizations_url":"https://api.github.com/users/arikfr/orgs","repos_url":"https://api.github.com/users/arikfr/repos","events_url":"https://api.github.com/users/arikfr/events{/privacy}","received_events_url":"https://api.github.com/users/arikfr/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":4,"state":"open","created_at":"2016-06-14T07:20:45Z","updated_at":"2016-09-06T09:33:38Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/getredash/redash/pulls/1113/commits","review_comments_url":"https://api.github.com/repos/getredash/redash/pulls/1113/comments","review_comment_url":"https://api.github.com/repos/getredash/redash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getredash/redash/issues/1113/comments","statuses_url":"https://api.github.com/repos/getredash/redash/statuses/e89802b1e0fee76dda63a5890a1830a976550672","head":{"label":"whummer:feat/share-access-permissions","ref":"feat/share-access-permissions","sha":"e89802b1e0fee76dda63a5890a1830a976550672","user":{"login":"whummer","id":2807888,"avatar_url":"https://avatars.githubusercontent.com/u/2807888?v=3","gravatar_id":"","url":"https://api.github.com/users/whummer","html_url":"https://github.com/whummer","followers_url":"https://api.github.com/users/whummer/followers","following_url":"https://api.github.com/users/whummer/following{/other_user}","gists_url":"https://api.github.com/users/whummer/gists{/gist_id}","starred_url":"https://api.github.com/users/whummer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whummer/subscriptions","organizations_url":"https://api.github.com/users/whummer/orgs","repos_url":"https://api.github.com/users/whummer/repos","events_url":"https://api.github.com/users/whummer/events{/privacy}","received_events_url":"https://api.github.com/users/whummer/received_events","type":"User","site_admin":false},"repo":{"id":57185746,"name":"redash","full_name":"whummer/redash","owner":{"login":"whummer","id":2807888,"avatar_url":"https://avatars.githubusercontent.com/u/2807888?v=3","gravatar_id":"","url":"https://api.github.com/users/whummer","html_url":"https://github.com/whummer","followers_url":"https://api.github.com/users/whummer/followers","following_url":"https://api.github.com/users/whummer/following{/other_user}","gists_url":"https://api.github.com/users/whummer/gists{/gist_id}","starred_url":"https://api.github.com/users/whummer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whummer/subscriptions","organizations_url":"https://api.github.com/users/whummer/orgs","repos_url":"https://api.github.com/users/whummer/repos","events_url":"https://api.github.com/users/whummer/events{/privacy}","received_events_url":"https://api.github.com/users/whummer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/whummer/redash","description":"Make Your Company Data Driven. Connect to any data source, easily visualize and share your data.","fork":true,"url":"https://api.github.com/repos/whummer/redash","forks_url":"https://api.github.com/repos/whummer/redash/forks","keys_url":"https://api.github.com/repos/whummer/redash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/whummer/redash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/whummer/redash/teams","hooks_url":"https://api.github.com/repos/whummer/redash/hooks","issue_events_url":"https://api.github.com/repos/whummer/redash/issues/events{/number}","events_url":"https://api.github.com/repos/whummer/redash/events","assignees_url":"https://api.github.com/repos/whummer/redash/assignees{/user}","branches_url":"https://api.github.com/repos/whummer/redash/branches{/branch}","tags_url":"https://api.github.com/repos/whummer/redash/tags","blobs_url":"https://api.github.com/repos/whummer/redash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/whummer/redash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/whummer/redash/git/refs{/sha}","trees_url":"https://api.github.com/repos/whummer/redash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/whummer/redash/statuses/{sha}","languages_url":"https://api.github.com/repos/whummer/redash/languages","stargazers_url":"https://api.github.com/repos/whummer/redash/stargazers","contributors_url":"https://api.github.com/repos/whummer/redash/contributors","subscribers_url":"https://api.github.com/repos/whummer/redash/subscribers","subscription_url":"https://api.github.com/repos/whummer/redash/subscription","commits_url":"https://api.github.com/repos/whummer/redash/commits{/sha}","git_commits_url":"https://api.github.com/repos/whummer/redash/git/commits{/sha}","comments_url":"https://api.github.com/repos/whummer/redash/comments{/number}","issue_comment_url":"https://api.github.com/repos/whummer/redash/issues/comments{/number}","contents_url":"https://api.github.com/repos/whummer/redash/contents/{+path}","compare_url":"https://api.github.com/repos/whummer/redash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/whummer/redash/merges","archive_url":"https://api.github.com/repos/whummer/redash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/whummer/redash/downloads","issues_url":"https://api.github.com/repos/whummer/redash/issues{/number}","pulls_url":"https://api.github.com/repos/whummer/redash/pulls{/number}","milestones_url":"https://api.github.com/repos/whummer/redash/milestones{/number}","notifications_url":"https://api.github.com/repos/whummer/redash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/whummer/redash/labels{/name}","releases_url":"https://api.github.com/repos/whummer/redash/releases{/id}","deployments_url":"https://api.github.com/repos/whummer/redash/deployments","created_at":"2016-04-27T05:24:30Z","updated_at":"2016-04-27T05:24:32Z","pushed_at":"2016-09-09T02:02:51Z","git_url":"git://github.com/whummer/redash.git","ssh_url":"git@github.com:whummer/redash.git","clone_url":"https://github.com/whummer/redash.git","svn_url":"https://github.com/whummer/redash","homepage":"http://redash.io/","size":6101,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"getredash:master","ref":"master","sha":"21a9b4b03e05fbc9fb6bed896fb15825a023c1ff","user":{"login":"getredash","id":10746780,"avatar_url":"https://avatars.githubusercontent.com/u/10746780?v=3","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"repo":{"id":13926404,"name":"redash","full_name":"getredash/redash","owner":{"login":"getredash","id":10746780,"avatar_url":"https://avatars.githubusercontent.com/u/10746780?v=3","gravatar_id":"","url":"https://api.github.com/users/getredash","html_url":"https://github.com/getredash","followers_url":"https://api.github.com/users/getredash/followers","following_url":"https://api.github.com/users/getredash/following{/other_user}","gists_url":"https://api.github.com/users/getredash/gists{/gist_id}","starred_url":"https://api.github.com/users/getredash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getredash/subscriptions","organizations_url":"https://api.github.com/users/getredash/orgs","repos_url":"https://api.github.com/users/getredash/repos","events_url":"https://api.github.com/users/getredash/events{/privacy}","received_events_url":"https://api.github.com/users/getredash/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getredash/redash","description":"Make Your Company Data Driven. Connect to any data source, easily visualize and share your data.","fork":false,"url":"https://api.github.com/repos/getredash/redash","forks_url":"https://api.github.com/repos/getredash/redash/forks","keys_url":"https://api.github.com/repos/getredash/redash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getredash/redash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getredash/redash/teams","hooks_url":"https://api.github.com/repos/getredash/redash/hooks","issue_events_url":"https://api.github.com/repos/getredash/redash/issues/events{/number}","events_url":"https://api.github.com/repos/getredash/redash/events","assignees_url":"https://api.github.com/repos/getredash/redash/assignees{/user}","branches_url":"https://api.github.com/repos/getredash/redash/branches{/branch}","tags_url":"https://api.github.com/repos/getredash/redash/tags","blobs_url":"https://api.github.com/repos/getredash/redash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getredash/redash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getredash/redash/git/refs{/sha}","trees_url":"https://api.github.com/repos/getredash/redash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getredash/redash/statuses/{sha}","languages_url":"https://api.github.com/repos/getredash/redash/languages","stargazers_url":"https://api.github.com/repos/getredash/redash/stargazers","contributors_url":"https://api.github.com/repos/getredash/redash/contributors","subscribers_url":"https://api.github.com/repos/getredash/redash/subscribers","subscription_url":"https://api.github.com/repos/getredash/redash/subscription","commits_url":"https://api.github.com/repos/getredash/redash/commits{/sha}","git_commits_url":"https://api.github.com/repos/getredash/redash/git/commits{/sha}","comments_url":"https://api.github.com/repos/getredash/redash/comments{/number}","issue_comment_url":"https://api.github.com/repos/getredash/redash/issues/comments{/number}","contents_url":"https://api.github.com/repos/getredash/redash/contents/{+path}","compare_url":"https://api.github.com/repos/getredash/redash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getredash/redash/merges","archive_url":"https://api.github.com/repos/getredash/redash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getredash/redash/downloads","issues_url":"https://api.github.com/repos/getredash/redash/issues{/number}","pulls_url":"https://api.github.com/repos/getredash/redash/pulls{/number}","milestones_url":"https://api.github.com/repos/getredash/redash/milestones{/number}","notifications_url":"https://api.github.com/repos/getredash/redash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getredash/redash/labels{/name}","releases_url":"https://api.github.com/repos/getredash/redash/releases{/id}","deployments_url":"https://api.github.com/repos/getredash/redash/deployments","created_at":"2013-10-28T13:19:39Z","updated_at":"2016-09-08T23:31:30Z","pushed_at":"2016-09-09T02:02:52Z","git_url":"git://github.com/getredash/redash.git","ssh_url":"git@github.com:getredash/redash.git","clone_url":"https://github.com/getredash/redash.git","svn_url":"https://github.com/getredash/redash","homepage":"http://redash.io/","size":9099,"stargazers_count":2179,"watchers_count":2179,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":415,"mirror_url":null,"open_issues_count":147,"forks":415,"open_issues":147,"watchers":2179,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getredash/redash/pulls/1113"},"html":{"href":"https://github.com/getredash/redash/pull/1113"},"issue":{"href":"https://api.github.com/repos/getredash/redash/issues/1113"},"comments":{"href":"https://api.github.com/repos/getredash/redash/issues/1113/comments"},"review_comments":{"href":"https://api.github.com/repos/getredash/redash/pulls/1113/comments"},"review_comment":{"href":"https://api.github.com/repos/getredash/redash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getredash/redash/pulls/1113/commits"},"statuses":{"href":"https://api.github.com/repos/getredash/redash/statuses/e89802b1e0fee76dda63a5890a1830a976550672"}}}}
{"actor":{"display_login":"whummer"}}