{"action":"created","comment":{"url":"https://api.github.com/repos/foam-framework/foam/pulls/comments/42369788","id":42369788,"diff_hunk":"@@ -0,0 +1,59 @@\n+/**\n+ * @license\n+ * Copyright 2015 Google Inc. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+CLASS({\n+  package: 'foam.dao',\n+  name: 'PublicReadPrivateWriteAuthenticator',\n+  implements: ['foam.dao.Authenticator'],\n+\n+  documentation: function() {/*\n+    <p>$$DOC{ref:'foam.dao.Authenticator'} for the common case where each user\n+    of the service can only write their own data, but all data is\n+    world-readable. (Eg. Twitter, to a first approximation.)</p>\n+  */},\n+\n+  properties: [\n+    {\n+      name: 'ownerProp',\n+    },\n+  ],\n+\n+  methods: [\n+    function massageForPut(ret, principal, old, nu) {\n+      // If old exists and old.owner != principal, fail: trying to write someone\n+      // else's data.\n+      if (old && NEQ(this.ownerProp, principal).f(old)) {\n+        ret(null);\n+        return;\n+      }\n+\n+      // Now either old exists but is owned by me, or this is a new put.\n+      // Either way, clone nu and set its owner to the principal.\n+      var clone = nu.clone();\n+      clone[this.ownerProp.name] = principal;\n+      ret(clone);\n+    },\n+    function massageForRead(ret, principal, obj) {\n+      ret(obj);\n+    },\n+    function shouldAllowRemove(ret, principal, obj) {\n+      ret(!obj || EQ(this.ownerProp, principal).f(obj));","path":"js/foam/dao/PublicReadPrivateWriteAuthenticator.js","position":53,"original_position":53,"commit_id":"7e5db744c6dc83743abbb2ab4e749b0506c76533","original_commit_id":"7e5db744c6dc83743abbb2ab4e749b0506c76533","user":{"login":"adamvy","id":7491581,"avatar_url":"https://avatars.githubusercontent.com/u/7491581?v=3","gravatar_id":"","url":"https://api.github.com/users/adamvy","html_url":"https://github.com/adamvy","followers_url":"https://api.github.com/users/adamvy/followers","following_url":"https://api.github.com/users/adamvy/following{/other_user}","gists_url":"https://api.github.com/users/adamvy/gists{/gist_id}","starred_url":"https://api.github.com/users/adamvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamvy/subscriptions","organizations_url":"https://api.github.com/users/adamvy/orgs","repos_url":"https://api.github.com/users/adamvy/repos","events_url":"https://api.github.com/users/adamvy/events{/privacy}","received_events_url":"https://api.github.com/users/adamvy/received_events","type":"User","site_admin":false},"body":"Unroll this into if () {} else {} as well.","created_at":"2015-10-19T13:26:27Z","updated_at":"2015-10-19T13:26:27Z","html_url":"https://github.com/foam-framework/foam/pull/429#discussion_r42369788","pull_request_url":"https://api.github.com/repos/foam-framework/foam/pulls/429","_links":{"self":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/comments/42369788"},"html":{"href":"https://github.com/foam-framework/foam/pull/429#discussion_r42369788"},"pull_request":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/429"}}},"pull_request":{"url":"https://api.github.com/repos/foam-framework/foam/pulls/429","id":47577263,"html_url":"https://github.com/foam-framework/foam/pull/429","diff_url":"https://github.com/foam-framework/foam/pull/429.diff","patch_url":"https://github.com/foam-framework/foam/pull/429.patch","issue_url":"https://api.github.com/repos/foam-framework/foam/issues/429","number":429,"state":"open","locked":false,"title":"PR: New client-server authentication and authorization scheme","user":{"login":"shepheb","id":157812,"avatar_url":"https://avatars.githubusercontent.com/u/157812?v=3","gravatar_id":"","url":"https://api.github.com/users/shepheb","html_url":"https://github.com/shepheb","followers_url":"https://api.github.com/users/shepheb/followers","following_url":"https://api.github.com/users/shepheb/following{/other_user}","gists_url":"https://api.github.com/users/shepheb/gists{/gist_id}","starred_url":"https://api.github.com/users/shepheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shepheb/subscriptions","organizations_url":"https://api.github.com/users/shepheb/orgs","repos_url":"https://api.github.com/users/shepheb/repos","events_url":"https://api.github.com/users/shepheb/events{/privacy}","received_events_url":"https://api.github.com/users/shepheb/received_events","type":"User","site_admin":false},"body":"- General framework for authorizing user actions: `AuthenticatedDAO` and `Authenticator` interface (with default implmentations `PrivateOwnerAuthenticator` and `PublicReadPrivateWriteAuthenticator`).\r\n- Google authentication on the client side and server side, with easy integration (`GoogleSignIn` on the client and `GoogleAuthDAO` on the server).\r\n\r\nThis scheme keeps things nicely decoupled:\r\n- `Authenticator`s are async and can make network calls or look things up in this and other DAOs before responding to a user request.\r\n- `AuthenticatedDAO` doesn't care about authenticating that a user is who they claim to be, it just checks their authorization to read/write what they asked for.\r\n- `GoogleAuthDAO` doesn't check what the user can read or write, just retrieves and verifies the token in the context.\r\n\r\nQuestions:\r\n\r\n- I should probably rename `Authenticator` and `AuthenticatedDAO`, because they're really solving the *authorization* problem (what this user is allowed to do), not the *authentication* problem (who this user is). Thoughts?","created_at":"2015-10-13T19:28:51Z","updated_at":"2015-10-19T13:26:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c72f63597f194c79b25f86190bd43b80554bb867","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/foam-framework/foam/pulls/429/commits","review_comments_url":"https://api.github.com/repos/foam-framework/foam/pulls/429/comments","review_comment_url":"https://api.github.com/repos/foam-framework/foam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/foam-framework/foam/issues/429/comments","statuses_url":"https://api.github.com/repos/foam-framework/foam/statuses/7e5db744c6dc83743abbb2ab4e749b0506c76533","head":{"label":"shepheb:auth","ref":"auth","sha":"7e5db744c6dc83743abbb2ab4e749b0506c76533","user":{"login":"shepheb","id":157812,"avatar_url":"https://avatars.githubusercontent.com/u/157812?v=3","gravatar_id":"","url":"https://api.github.com/users/shepheb","html_url":"https://github.com/shepheb","followers_url":"https://api.github.com/users/shepheb/followers","following_url":"https://api.github.com/users/shepheb/following{/other_user}","gists_url":"https://api.github.com/users/shepheb/gists{/gist_id}","starred_url":"https://api.github.com/users/shepheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shepheb/subscriptions","organizations_url":"https://api.github.com/users/shepheb/orgs","repos_url":"https://api.github.com/users/shepheb/repos","events_url":"https://api.github.com/users/shepheb/events{/privacy}","received_events_url":"https://api.github.com/users/shepheb/received_events","type":"User","site_admin":false},"repo":{"id":19540558,"name":"foam","full_name":"shepheb/foam","owner":{"login":"shepheb","id":157812,"avatar_url":"https://avatars.githubusercontent.com/u/157812?v=3","gravatar_id":"","url":"https://api.github.com/users/shepheb","html_url":"https://github.com/shepheb","followers_url":"https://api.github.com/users/shepheb/followers","following_url":"https://api.github.com/users/shepheb/following{/other_user}","gists_url":"https://api.github.com/users/shepheb/gists{/gist_id}","starred_url":"https://api.github.com/users/shepheb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shepheb/subscriptions","organizations_url":"https://api.github.com/users/shepheb/orgs","repos_url":"https://api.github.com/users/shepheb/repos","events_url":"https://api.github.com/users/shepheb/events{/privacy}","received_events_url":"https://api.github.com/users/shepheb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shepheb/foam","description":"Feature-Oriented Active Modeller","fork":true,"url":"https://api.github.com/repos/shepheb/foam","forks_url":"https://api.github.com/repos/shepheb/foam/forks","keys_url":"https://api.github.com/repos/shepheb/foam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shepheb/foam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shepheb/foam/teams","hooks_url":"https://api.github.com/repos/shepheb/foam/hooks","issue_events_url":"https://api.github.com/repos/shepheb/foam/issues/events{/number}","events_url":"https://api.github.com/repos/shepheb/foam/events","assignees_url":"https://api.github.com/repos/shepheb/foam/assignees{/user}","branches_url":"https://api.github.com/repos/shepheb/foam/branches{/branch}","tags_url":"https://api.github.com/repos/shepheb/foam/tags","blobs_url":"https://api.github.com/repos/shepheb/foam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shepheb/foam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shepheb/foam/git/refs{/sha}","trees_url":"https://api.github.com/repos/shepheb/foam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shepheb/foam/statuses/{sha}","languages_url":"https://api.github.com/repos/shepheb/foam/languages","stargazers_url":"https://api.github.com/repos/shepheb/foam/stargazers","contributors_url":"https://api.github.com/repos/shepheb/foam/contributors","subscribers_url":"https://api.github.com/repos/shepheb/foam/subscribers","subscription_url":"https://api.github.com/repos/shepheb/foam/subscription","commits_url":"https://api.github.com/repos/shepheb/foam/commits{/sha}","git_commits_url":"https://api.github.com/repos/shepheb/foam/git/commits{/sha}","comments_url":"https://api.github.com/repos/shepheb/foam/comments{/number}","issue_comment_url":"https://api.github.com/repos/shepheb/foam/issues/comments{/number}","contents_url":"https://api.github.com/repos/shepheb/foam/contents/{+path}","compare_url":"https://api.github.com/repos/shepheb/foam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shepheb/foam/merges","archive_url":"https://api.github.com/repos/shepheb/foam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shepheb/foam/downloads","issues_url":"https://api.github.com/repos/shepheb/foam/issues{/number}","pulls_url":"https://api.github.com/repos/shepheb/foam/pulls{/number}","milestones_url":"https://api.github.com/repos/shepheb/foam/milestones{/number}","notifications_url":"https://api.github.com/repos/shepheb/foam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shepheb/foam/labels{/name}","releases_url":"https://api.github.com/repos/shepheb/foam/releases{/id}","created_at":"2014-05-07T15:48:09Z","updated_at":"2014-06-19T19:06:55Z","pushed_at":"2015-10-19T12:53:05Z","git_url":"git://github.com/shepheb/foam.git","ssh_url":"git@github.com:shepheb/foam.git","clone_url":"https://github.com/shepheb/foam.git","svn_url":"https://github.com/shepheb/foam","homepage":null,"size":27330,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"foam-framework:master","ref":"master","sha":"6f7bc59c8f7052934129eb39911c326af5048500","user":{"login":"foam-framework","id":7460756,"avatar_url":"https://avatars.githubusercontent.com/u/7460756?v=3","gravatar_id":"","url":"https://api.github.com/users/foam-framework","html_url":"https://github.com/foam-framework","followers_url":"https://api.github.com/users/foam-framework/followers","following_url":"https://api.github.com/users/foam-framework/following{/other_user}","gists_url":"https://api.github.com/users/foam-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/foam-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foam-framework/subscriptions","organizations_url":"https://api.github.com/users/foam-framework/orgs","repos_url":"https://api.github.com/users/foam-framework/repos","events_url":"https://api.github.com/users/foam-framework/events{/privacy}","received_events_url":"https://api.github.com/users/foam-framework/received_events","type":"Organization","site_admin":false},"repo":{"id":19353092,"name":"foam","full_name":"foam-framework/foam","owner":{"login":"foam-framework","id":7460756,"avatar_url":"https://avatars.githubusercontent.com/u/7460756?v=3","gravatar_id":"","url":"https://api.github.com/users/foam-framework","html_url":"https://github.com/foam-framework","followers_url":"https://api.github.com/users/foam-framework/followers","following_url":"https://api.github.com/users/foam-framework/following{/other_user}","gists_url":"https://api.github.com/users/foam-framework/gists{/gist_id}","starred_url":"https://api.github.com/users/foam-framework/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foam-framework/subscriptions","organizations_url":"https://api.github.com/users/foam-framework/orgs","repos_url":"https://api.github.com/users/foam-framework/repos","events_url":"https://api.github.com/users/foam-framework/events{/privacy}","received_events_url":"https://api.github.com/users/foam-framework/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/foam-framework/foam","description":"Feature-Oriented Active Modeller","fork":false,"url":"https://api.github.com/repos/foam-framework/foam","forks_url":"https://api.github.com/repos/foam-framework/foam/forks","keys_url":"https://api.github.com/repos/foam-framework/foam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/foam-framework/foam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/foam-framework/foam/teams","hooks_url":"https://api.github.com/repos/foam-framework/foam/hooks","issue_events_url":"https://api.github.com/repos/foam-framework/foam/issues/events{/number}","events_url":"https://api.github.com/repos/foam-framework/foam/events","assignees_url":"https://api.github.com/repos/foam-framework/foam/assignees{/user}","branches_url":"https://api.github.com/repos/foam-framework/foam/branches{/branch}","tags_url":"https://api.github.com/repos/foam-framework/foam/tags","blobs_url":"https://api.github.com/repos/foam-framework/foam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/foam-framework/foam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/foam-framework/foam/git/refs{/sha}","trees_url":"https://api.github.com/repos/foam-framework/foam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/foam-framework/foam/statuses/{sha}","languages_url":"https://api.github.com/repos/foam-framework/foam/languages","stargazers_url":"https://api.github.com/repos/foam-framework/foam/stargazers","contributors_url":"https://api.github.com/repos/foam-framework/foam/contributors","subscribers_url":"https://api.github.com/repos/foam-framework/foam/subscribers","subscription_url":"https://api.github.com/repos/foam-framework/foam/subscription","commits_url":"https://api.github.com/repos/foam-framework/foam/commits{/sha}","git_commits_url":"https://api.github.com/repos/foam-framework/foam/git/commits{/sha}","comments_url":"https://api.github.com/repos/foam-framework/foam/comments{/number}","issue_comment_url":"https://api.github.com/repos/foam-framework/foam/issues/comments{/number}","contents_url":"https://api.github.com/repos/foam-framework/foam/contents/{+path}","compare_url":"https://api.github.com/repos/foam-framework/foam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/foam-framework/foam/merges","archive_url":"https://api.github.com/repos/foam-framework/foam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/foam-framework/foam/downloads","issues_url":"https://api.github.com/repos/foam-framework/foam/issues{/number}","pulls_url":"https://api.github.com/repos/foam-framework/foam/pulls{/number}","milestones_url":"https://api.github.com/repos/foam-framework/foam/milestones{/number}","notifications_url":"https://api.github.com/repos/foam-framework/foam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/foam-framework/foam/labels{/name}","releases_url":"https://api.github.com/repos/foam-framework/foam/releases{/id}","created_at":"2014-05-01T18:10:55Z","updated_at":"2015-10-14T08:14:17Z","pushed_at":"2015-10-19T12:53:06Z","git_url":"git://github.com/foam-framework/foam.git","ssh_url":"git@github.com:foam-framework/foam.git","clone_url":"https://github.com/foam-framework/foam.git","svn_url":"https://github.com/foam-framework/foam","homepage":null,"size":44077,"stargazers_count":700,"watchers_count":700,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":42,"mirror_url":null,"open_issues_count":167,"forks":42,"open_issues":167,"watchers":700,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/429"},"html":{"href":"https://github.com/foam-framework/foam/pull/429"},"issue":{"href":"https://api.github.com/repos/foam-framework/foam/issues/429"},"comments":{"href":"https://api.github.com/repos/foam-framework/foam/issues/429/comments"},"review_comments":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/429/comments"},"review_comment":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/foam-framework/foam/pulls/429/commits"},"statuses":{"href":"https://api.github.com/repos/foam-framework/foam/statuses/7e5db744c6dc83743abbb2ab4e749b0506c76533"}}}}