GitHub PullRequestReviewCommentEvent at 2014-10-24 15:37:00
Repository: fxa-content-server
Actor: shane-tomlinson
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/19346025","id":19346025,"diff_hunk":"@@ -0,0 +1,175 @@\n+/* This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this\n+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n+\n+/**\n+ * A broker that knows how to communicate with Firefox when used for Sync.\n+ */\n+\n+'use strict';\n+\n+define([\n+  'underscore',\n+  'models/auth_brokers/default',\n+  'models/auth_brokers/mixins/channel',\n+  'lib/promise',\n+  'lib/auth-errors',\n+  'lib/channels/fx-desktop',\n+  'lib/constants'\n+], function (_, DefaultAuthenticationBroker, ChannelMixin, p, AuthErrors,\n+        FxDesktopChannel, Constants) {\n+\n+  var FxDesktopAuthenticationBroker = DefaultAuthenticationBroker.extend({\n+    initialize: function (options) {\n+      options = options || {};\n+\n+      // channel can be passed in for testing.\n+      this._channel = options.channel;\n+      this._session = options.session;\n+\n+      return DefaultAuthenticationBroker.prototype.initialize.call(\n+          this, options);\n+    },\n+\n+    fetch: function () {\n+      var self = this;\n+\n+      return DefaultAuthenticationBroker.prototype.fetch.call(self)\n+        .then(function () {\n+          // only fetch session_status if the user is trying to sign up or\n+          // sign in. If session_status is fetched during verification,\n+          // the browser is not listening and a channel timeout occurs.\n+          if (! self._isSignUpOrSignIn()) {\n+            return;\n+          }\n+\n+          return self.send('session_status', {})\n+            .then(function (response) {\n+              return response.data;\n+            })\n+            .then(_.bind(self._initializeSession, self));\n+        });\n+    },\n+\n+    selectStartPage: function () {\n+      var self = this;\n+      return p().then(function () {\n+        var canRedirect = self.window.location.pathname === '/';\n+        if (canRedirect) {\n+          if (self.isForceAuth()) {\n+            return 'force_auth';\n+          } else if (self._isUserAuthenticated()) {\n+            return 'settings';\n+          } else {\n+            return 'signup';\n+          }\n+        }\n+      });\n+    },\n+\n+    checkCanLinkAccount: function (email) {\n+      var self = this;\n+      // This will send a message over the channel to determine whether\n+      // we should cancel the login to sync or not based on Desktop\n+      // specific checks and dialogs. It throws an error with\n+      // message='USER_CANCELED_LOGIN' and errno=1001 if that's the case.\n+      self._verifiedCanLinkAccount = true;\n+      return self.send('can_link_account', { email: email })\n+        .then(function (response) {\n+          if (response && response.data && ! response.data.ok) {\n+            throw AuthErrors.toError('USER_CANCELED_LOGIN');\n+          }\n+\n+          self._verifiedCanLinkAccount = true;\n+        }, function (err) {\n+          console.error('checkCanLinkAccount failed with', err);\n+          // If the browser doesn't implement this command, then it will\n+          // handle prompting the relink warning after sign in completes.\n+          // This can likely be changed to 'reject' after Fx31 hits nightly,\n+          // because all browsers will likely support 'can_link_account'\n+        });\n+    },\n+\n+    notifyOfLogin: function () {\n+      return this.send('login', this._getLoginData());\n+    },\n+\n+    afterSignIn: function () {\n+      return this.notifyOfLogin();\n+    },\n+\n+    afterSignUpConfirmed: function (view) {\n+      return this.notifyOfLogin()\n+        .then(function () {\n+          return view.navigate('signup_complete');","path":"app/scripts/models/auth_brokers/fx-desktop.js","position":null,"original_position":104,"commit_id":"59d75291eb65f5584010949f6673373ee6d4165b","original_commit_id":"dca33cc6e99a7a1d3ffb961cd315875a0be9b43a","user":{"login":"shane-tomlinson","id":848085,"avatar_url":"https://avatars.githubusercontent.com/u/848085?v=2","gravatar_id":"","url":"https://api.github.com/users/shane-tomlinson","html_url":"https://github.com/shane-tomlinson","followers_url":"https://api.github.com/users/shane-tomlinson/followers","following_url":"https://api.github.com/users/shane-tomlinson/following{/other_user}","gists_url":"https://api.github.com/users/shane-tomlinson/gists{/gist_id}","starred_url":"https://api.github.com/users/shane-tomlinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shane-tomlinson/subscriptions","organizations_url":"https://api.github.com/users/shane-tomlinson/orgs","repos_url":"https://api.github.com/users/shane-tomlinson/repos","events_url":"https://api.github.com/users/shane-tomlinson/events{/privacy}","received_events_url":"https://api.github.com/users/shane-tomlinson/received_events","type":"User","site_admin":false},"body":"I'm trying to think of other alternatives.\r\n\r\nWe could have all screens automatically redirect to the subsequent screen. Brokers that need to prevent the screen transition could throw a pre-defined error that is then ignored.\r\n\r\nmodels/auth_brokers/fx-desktop.js\r\n```js\r\nafterSignIn: function () {\r\n      return this.notifyOfLogin()\r\n        .then(function () {\r\n          return p.reject(AuthErrors.toError('LOGIN_HANDLED'));\r\n        });\r\n}\r\n```\r\n\r\nviews/sign_in.js\r\n```js\r\n    onSignInSuccess: function () {\r\n      var self = this;\r\n      return self.broker.afterSignIn(self)\r\n        .then(function () {\r\n          self.navigate('settings');\r\n        }, function (err) {\r\n          if (! AuthErrors.is(err, 'LOGIN_HANDLED')) {\r\n            throw err;\r\n          }\r\n        });\r\n    },\r\n```\r\n\r\nWe could have brokers return a boolean or status object. If the boolean or status object indicates the broker has handled the flow, then skip the screen transition.\r\n\r\nmodels/auth_brokers/fx-desktop.js\r\n```js\r\nafterSignIn: function () {\r\n      return this.notifyOfLogin()\r\n        .then(function () {\r\n          return { handled: true };\r\n        });\r\n}\r\n```\r\n\r\nviews/sign_in.js\r\n```js\r\n    onSignInSuccess: function () {\r\n      var self = this;\r\n      return self.broker.afterSignIn(self)\r\n        .then(function (status) {\r\n          if (! status.handled) {\r\n            self.navigate('settings');\r\n          }\r\n        });\r\n    },\r\n```\r\n\r\n","created_at":"2014-10-24T15:37:00Z","updated_at":"2014-10-24T15:37:00Z","html_url":"https://github.com/mozilla/fxa-content-server/pull/1609#discussion_r19346025","pull_request_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609","_links":{"self":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/19346025"},"html":{"href":"https://github.com/mozilla/fxa-content-server/pull/1609#discussion_r19346025"},"pull_request":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609","id":20518791,"html_url":"https://github.com/mozilla/fxa-content-server/pull/1609","diff_url":"https://github.com/mozilla/fxa-content-server/pull/1609.diff","patch_url":"https://github.com/mozilla/fxa-content-server/pull/1609.patch","issue_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/1609","number":1609,"state":"open","locked":false,"title":"Add some brokers","user":{"login":"shane-tomlinson","id":848085,"avatar_url":"https://avatars.githubusercontent.com/u/848085?v=2","gravatar_id":"","url":"https://api.github.com/users/shane-tomlinson","html_url":"https://github.com/shane-tomlinson","followers_url":"https://api.github.com/users/shane-tomlinson/followers","following_url":"https://api.github.com/users/shane-tomlinson/following{/other_user}","gists_url":"https://api.github.com/users/shane-tomlinson/gists{/gist_id}","starred_url":"https://api.github.com/users/shane-tomlinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shane-tomlinson/subscriptions","organizations_url":"https://api.github.com/users/shane-tomlinson/orgs","repos_url":"https://api.github.com/users/shane-tomlinson/repos","events_url":"https://api.github.com/users/shane-tomlinson/events{/privacy}","received_events_url":"https://api.github.com/users/shane-tomlinson/received_events","type":"User","site_admin":false},"body":"This is for @nchapman, @zaach, @vladikoff and @ckarlof. These are the first brokers, see what you think!\r\n\r\nfeat(client): Add some brokers!\r\n\r\n* Start to add brokers that know how to startup/complete flows.\r\n* 3 brokers to start, fx-desktop, redirect, web-channel.\r\n* Get rid of the Channels high level abstraction, these are used directly by the brokers if needed.\r\n* Move some code from service-mixin and various channels to brokers.\r\n* Update tests to make use of the brokers.","created_at":"2014-08-29T19:27:52Z","updated_at":"2014-10-24T15:37:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3a330ff2dc648a24774970f84914deb0aa7f16e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609/commits","review_comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609/comments","review_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/1609/comments","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/59d75291eb65f5584010949f6673373ee6d4165b","head":{"label":"mozilla:add-a-broker","ref":"add-a-broker","sha":"59d75291eb65f5584010949f6673373ee6d4165b","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":11778024,"name":"fxa-content-server","full_name":"mozilla/fxa-content-server","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/fxa-content-server","description":"Firefox Accounts Content Server","fork":false,"url":"https://api.github.com/repos/mozilla/fxa-content-server","forks_url":"https://api.github.com/repos/mozilla/fxa-content-server/forks","keys_url":"https://api.github.com/repos/mozilla/fxa-content-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/fxa-content-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/fxa-content-server/teams","hooks_url":"https://api.github.com/repos/mozilla/fxa-content-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/events","assignees_url":"https://api.github.com/repos/mozilla/fxa-content-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/fxa-content-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/tags","blobs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/fxa-content-server/languages","stargazers_url":"https://api.github.com/repos/mozilla/fxa-content-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla/fxa-content-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscription","commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla/fxa-content-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/fxa-content-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/fxa-content-server/merges","archive_url":"https://api.github.com/repos/mozilla/fxa-content-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/fxa-content-server/downloads","issues_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/fxa-content-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/fxa-content-server/releases{/id}","created_at":"2013-07-30T23:35:35Z","updated_at":"2014-10-23T23:42:19Z","pushed_at":"2014-10-24T14:55:01Z","git_url":"git://github.com/mozilla/fxa-content-server.git","ssh_url":"git@github.com:mozilla/fxa-content-server.git","clone_url":"https://github.com/mozilla/fxa-content-server.git","svn_url":"https://github.com/mozilla/fxa-content-server","homepage":"","size":31707,"stargazers_count":36,"watchers_count":36,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":177,"forks":26,"open_issues":177,"watchers":36,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"cdc16f433157b37fc254e7dc6d33b5f4f6b43cf4","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":11778024,"name":"fxa-content-server","full_name":"mozilla/fxa-content-server","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/fxa-content-server","description":"Firefox Accounts Content Server","fork":false,"url":"https://api.github.com/repos/mozilla/fxa-content-server","forks_url":"https://api.github.com/repos/mozilla/fxa-content-server/forks","keys_url":"https://api.github.com/repos/mozilla/fxa-content-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/fxa-content-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/fxa-content-server/teams","hooks_url":"https://api.github.com/repos/mozilla/fxa-content-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/fxa-content-server/events","assignees_url":"https://api.github.com/repos/mozilla/fxa-content-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/fxa-content-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/tags","blobs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/fxa-content-server/languages","stargazers_url":"https://api.github.com/repos/mozilla/fxa-content-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla/fxa-content-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla/fxa-content-server/subscription","commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/fxa-content-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/fxa-content-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla/fxa-content-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/fxa-content-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/fxa-content-server/merges","archive_url":"https://api.github.com/repos/mozilla/fxa-content-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/fxa-content-server/downloads","issues_url":"https://api.github.com/repos/mozilla/fxa-content-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/fxa-content-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/fxa-content-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/fxa-content-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/fxa-content-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/fxa-content-server/releases{/id}","created_at":"2013-07-30T23:35:35Z","updated_at":"2014-10-23T23:42:19Z","pushed_at":"2014-10-24T14:55:01Z","git_url":"git://github.com/mozilla/fxa-content-server.git","ssh_url":"git@github.com:mozilla/fxa-content-server.git","clone_url":"https://github.com/mozilla/fxa-content-server.git","svn_url":"https://github.com/mozilla/fxa-content-server","homepage":"","size":31707,"stargazers_count":36,"watchers_count":36,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":26,"mirror_url":null,"open_issues_count":177,"forks":26,"open_issues":177,"watchers":36,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609"},"html":{"href":"https://github.com/mozilla/fxa-content-server/pull/1609"},"issue":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/issues/1609"},"comments":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/issues/1609/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/pulls/1609/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/fxa-content-server/statuses/59d75291eb65f5584010949f6673373ee6d4165b"}}}}