{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-android/pulls/comments/132183703","pull_request_review_id":55224237,"id":132183703,"diff_hunk":"@@ -0,0 +1,185 @@\n+package org.commcare.utils;\n+\n+import org.commcare.modern.util.Pair;\n+import org.json.JSONArray;\n+import org.json.JSONException;\n+import org.json.JSONObject;\n+\n+import java.util.ArrayList;\n+\n+/**\n+ * Helper methods for privilege data\n+ *\n+ * Created by ctsims on 8/7/2017.\n+ */\n+\n+public class PrivilegesUtility {\n+    private String authorityPublicKeyString;\n+\n+    public PrivilegesUtility(String authorityPublicKeyString) {\n+        this.authorityPublicKeyString = authorityPublicKeyString;\n+    }\n+\n+    public Pair<String, String[]> processPrivilegePayloadForActivatedPrivileges\n+            (String privilegePayloadJson) throws PrivilagePayloadException{\n+        try {\n+            JSONObject obj = new JSONObject(privilegePayloadJson);\n+            int version;\n+            if(obj.has(\"version\")) {\n+                version = obj.getInt(\"version\");\n+            } else {\n+                if(obj.has(\"flag\")) {\n+                    version = 1;\n+                } else {\n+                    throw new UnrecognizedPayloadVersionException();\n+                }\n+            }\n+\n+            switch(version) {\n+                case 1:\n+                    return processAndValidateV1Payload(obj);\n+                case 2:\n+                    return processAndValidateV2Payload(obj);\n+                default:\n+                    throw new UnrecognizedPayloadVersionException();\n+            }\n+\n+        } catch (JSONException e) {\n+            throw new MalformedPayloadException(e);\n+        }\n+    }\n+\n+    private Pair<String, String[]> processAndValidateV2Payload(JSONObject obj) throws JSONException, PrivilagePayloadException {","path":"app/src/org/commcare/utils/PrivilegesUtility.java","position":52,"original_position":52,"commit_id":"a373d48928be05faac9bdca1460ab7d83f6f5a38","original_commit_id":"a373d48928be05faac9bdca1460ab7d83f6f5a38","user":{"login":"amstone326","id":3723143,"avatar_url":"https://avatars0.githubusercontent.com/u/3723143?v=4","gravatar_id":"","url":"https://api.github.com/users/amstone326","html_url":"https://github.com/amstone326","followers_url":"https://api.github.com/users/amstone326/followers","following_url":"https://api.github.com/users/amstone326/following{/other_user}","gists_url":"https://api.github.com/users/amstone326/gists{/gist_id}","starred_url":"https://api.github.com/users/amstone326/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amstone326/subscriptions","organizations_url":"https://api.github.com/users/amstone326/orgs","repos_url":"https://api.github.com/users/amstone326/repos","events_url":"https://api.github.com/users/amstone326/events{/privacy}","received_events_url":"https://api.github.com/users/amstone326/received_events","type":"User","site_admin":false},"body":"Even though it seems a little repetitive, I think the readability of this method and `procesesAndValidateV1Payload()` would be helped enormously if after calling `processV1Payload()` and `processV2Payload()`, respectively, you created named variables for each of the results, instead of just referencing them by `payload.first`, `payload[0]`, etc.","created_at":"2017-08-09T13:32:08Z","updated_at":"2017-08-09T13:45:20Z","html_url":"https://github.com/dimagi/commcare-android/pull/1784#discussion_r132183703","pull_request_url":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/comments/132183703"},"html":{"href":"https://github.com/dimagi/commcare-android/pull/1784#discussion_r132183703"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784","id":134781655,"html_url":"https://github.com/dimagi/commcare-android/pull/1784","diff_url":"https://github.com/dimagi/commcare-android/pull/1784.diff","patch_url":"https://github.com/dimagi/commcare-android/pull/1784.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-android/issues/1784","number":1784,"state":"open","locked":false,"title":"Expand Signed Privilege System to Allow for Multiple Privileges","user":{"login":"ctsims","id":155066,"avatar_url":"https://avatars3.githubusercontent.com/u/155066?v=4","gravatar_id":"","url":"https://api.github.com/users/ctsims","html_url":"https://github.com/ctsims","followers_url":"https://api.github.com/users/ctsims/followers","following_url":"https://api.github.com/users/ctsims/following{/other_user}","gists_url":"https://api.github.com/users/ctsims/gists{/gist_id}","starred_url":"https://api.github.com/users/ctsims/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ctsims/subscriptions","organizations_url":"https://api.github.com/users/ctsims/orgs","repos_url":"https://api.github.com/users/ctsims/repos","events_url":"https://api.github.com/users/ctsims/events{/privacy}","received_events_url":"https://api.github.com/users/ctsims/received_events","type":"User","site_admin":false},"body":"V2 of privilege granting\r\ntests for privilege blocks\r\ntools for generating test signatures more easily\r\nsplit out test and usage signatures for clarity\r\n\r\nStill needs some testing, but review can start.","created_at":"2017-08-08T23:36:29Z","updated_at":"2017-08-09T13:45:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2f691e46834e81ef05d952f5ad8ccbb25e4ebc53","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-android/issues/1784/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-android/statuses/a373d48928be05faac9bdca1460ab7d83f6f5a38","head":{"label":"dimagi:ctsims/privilege_claim_split","ref":"ctsims/privilege_claim_split","sha":"a373d48928be05faac9bdca1460ab7d83f6f5a38","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20939877,"name":"commcare-android","full_name":"dimagi/commcare-android","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-android","description":"The best open source form management tool in town","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-android","forks_url":"https://api.github.com/repos/dimagi/commcare-android/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-android/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-android/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-android/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-android/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-android/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-android/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-android/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-android/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-android/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-android/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-android/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-android/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-android/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-android/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-android/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-android/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-android/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-android/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-android/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-android/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-android/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-android/deployments","created_at":"2014-06-17T21:17:26Z","updated_at":"2017-07-23T14:09:40Z","pushed_at":"2017-08-08T23:36:29Z","git_url":"git://github.com/dimagi/commcare-android.git","ssh_url":"git@github.com:dimagi/commcare-android.git","clone_url":"https://github.com/dimagi/commcare-android.git","svn_url":"https://github.com/dimagi/commcare-android","homepage":"https://play.google.com/store/apps/details?id=org.commcare.dalvik&hl=en","size":155942,"stargazers_count":9,"watchers_count":9,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":11,"forks":15,"open_issues":11,"watchers":9,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"64c0f8d077f00836debc44ac299c584162f949cc","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20939877,"name":"commcare-android","full_name":"dimagi/commcare-android","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-android","description":"The best open source form management tool in town","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-android","forks_url":"https://api.github.com/repos/dimagi/commcare-android/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-android/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-android/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-android/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-android/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-android/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-android/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-android/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-android/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-android/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-android/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-android/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-android/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-android/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-android/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-android/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-android/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-android/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-android/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-android/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-android/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-android/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-android/deployments","created_at":"2014-06-17T21:17:26Z","updated_at":"2017-07-23T14:09:40Z","pushed_at":"2017-08-08T23:36:29Z","git_url":"git://github.com/dimagi/commcare-android.git","ssh_url":"git@github.com:dimagi/commcare-android.git","clone_url":"https://github.com/dimagi/commcare-android.git","svn_url":"https://github.com/dimagi/commcare-android","homepage":"https://play.google.com/store/apps/details?id=org.commcare.dalvik&hl=en","size":155942,"stargazers_count":9,"watchers_count":9,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":11,"forks":15,"open_issues":11,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784"},"html":{"href":"https://github.com/dimagi/commcare-android/pull/1784"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-android/issues/1784"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-android/issues/1784/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-android/pulls/1784/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-android/statuses/a373d48928be05faac9bdca1460ab7d83f6f5a38"}}}}
{"actor":{"display_login":"amstone326"}}