From 6af6a70f75a037a4147f229d8eff23399815e96d Mon Sep 17 00:00:00 2001 From: benweet Date: Tue, 15 Oct 2013 23:45:42 +0100 Subject: [PATCH] Fixed Google different oauth scopes after refresh --- public/cache.manifest | 2 +- public/res-min/main.js | 65 ++++++++++++++++++----------- public/res-min/themes/blue-gray.css | 2 - public/res-min/themes/default.css | 2 - public/res-min/themes/night.css | 2 - public/res-min/themes/school.css | 2 - public/res/helpers/googleHelper.js | 42 +++++++++++++++---- 7 files changed, 74 insertions(+), 43 deletions(-) diff --git a/public/cache.manifest b/public/cache.manifest index 1d616bf7..8082e577 100644 --- a/public/cache.manifest +++ b/public/cache.manifest @@ -1,5 +1,5 @@ CACHE MANIFEST -#Date Tue Oct 15 2013 01:02:10 +#Date Tue Oct 15 2013 23:44:34 CACHE: index.html diff --git a/public/res-min/main.js b/public/res-min/main.js index 79f0a3c8..01c937d4 100644 --- a/public/res-min/main.js +++ b/public/res-min/main.js @@ -13662,7 +13662,7 @@ define("config", function() {}), define("storage", [ "underscore", "utils" ], fu } }), t; }), define("text!html/settingsExtensionsAccordion.html", [], function() { - return '
\n
\n
\n \n
\n \n <%= extensionName %> \n
\n
\n
<%= settingsBlock %>
\n
\n
\n'; + return '
\n
\n
\n \n
\n \n <%= extensionName %> \n
\n
\n
<%= settingsBlock %>
\n
\n
\n'; }), function() { var e = function(e, t, n, i) { this.rawMessage = e, this.parsedLine = void 0 !== t ? t : -1, this.snippet = void 0 !== n ? n : null, @@ -20364,13 +20364,13 @@ if (hljs.LANGUAGES.glsl = function(e) { var u = void 0; return c.onPagedownConfigure = function(e) { u = document.getElementById("preview-contents"); - var n = document.querySelectorAll(".table-of-contents"), i = new RegExp("^" + c.config.marker + "$", "g"); + var n = new RegExp("^" + c.config.marker + "$", "g"); e.hooks.chain("onPreviewRefresh", function() { - var e = l(); - t.each(u.getElementsByTagName("p"), function(t) { - i.test(t.innerHTML) && (t.innerHTML = e); - }), t.each(n, function(t) { - t.innerHTML = e; + var e = document.querySelectorAll(".table-of-contents, .toc"), i = l(); + t.each(u.getElementsByTagName("p"), function(e) { + n.test(e.innerHTML) && (e.innerHTML = i); + }), t.each(e, function(e) { + e.innerHTML = i; }); }); }, c; @@ -26926,32 +26926,32 @@ if (hljs.LANGUAGES.glsl = function(e) { }), void 0); }); } - function l(t, i) { + function l(t, i, o) { t.onRun(function() { - function o() { + function r() { n.redirectConfirm("You are being redirected to Google authorization page.", function() { - t.chain(r); + t.chain(s); }, function() { t.error(new Error("Operation canceled.")); }); } - function r() { - s === !1 && (t.timeout = ASYNC_TASK_LONG_TIMEOUT); - var n = e.chain(g).pick(e.keys(h).concat([ i ])).flatten().value(); + function s() { + a === !1 && (t.timeout = ASYNC_TASK_LONG_TIMEOUT); + var n = e.chain(g).pick(h.getListWithNew(i)).flatten().value(); gapi.auth.authorize({ client_id: GOOGLE_CLIENT_ID, scope: n, - immediate: s + immediate: a }, function(e) { gapi.client.load("drive", "v2", function() { - return !e || e.error ? d === !0 && s === !0 ? (s = !1, t.chain(o), void 0) : (t.error(new Error("Access to Google account is not authorized.")), - void 0) : (h[i] = !0, t.chain(), void 0); + return !e || e.error ? d === !0 && a === !0 ? (a = !1, t.chain(r), void 0) : (t.error(new Error("Access to Google account is not authorized.")), + void 0) : (h.add(i), t.chain(), void 0); }); }); } - if (e.has(h, i)) return t.chain(), void 0; - var s = !0; - t.chain(r); + if (!o && h.isAuthorized(i)) return t.chain(), void 0; + var a = !0; + t.chain(s); }); } function c(e, t) { @@ -26959,9 +26959,9 @@ if (hljs.LANGUAGES.glsl = function(e) { if (e) if (logger.error(e), "string" == typeof e) i = e; else { if (i = "Google error (" + e.code + ": " + e.message + ").", e.code >= 500 && e.code < 600) return t.retry(new Error(i)), void 0; - if (401 === e.code || 403 === e.code || "token_refresh_required" == e.code) return h = {}, + if (401 === e.code || 403 === e.code || "token_refresh_required" == e.code) return h.reset(), i = "Access to Google account is not authorized.", t.retry(new Error(i), 1), void 0; - (0 === e.code || -1 === e.code) && (d = !1, h = {}, n.setOffline(), i = "|stopPublish"); + (0 === e.code || -1 === e.code) && (d = !1, h.reset(), n.setOffline(), i = "|stopPublish"); } t.error(new Error(i)); } @@ -26989,7 +26989,23 @@ if (hljs.LANGUAGES.glsl = function(e) { }), void 0); }); } - var d = !1, h = {}, p = {}, f = !1; + var d = !1, h = {}; + (function() { + var t = {}, n = !1; + e.each((localStorage.gdrivePermissions || "").split(";"), function(e) { + e && (t[e] = !0); + }), h.reset = function() { + n = !1; + }, h.isAuthorized = function(i) { + return n && e.has(t, i); + }, h.add = function(i) { + t[i] = !0, localStorage.gdrivePermissions = e.keys(t).join(";"), n = !0; + }, h.getListWithNew = function(n) { + var i = e.keys(t); + return e.has(t, n) || i.push(n), i; + }; + })(); + var p = {}, f = !1; r.addListener("onOfflineChanged", function(e) { f = e; }); @@ -26999,9 +27015,8 @@ if (hljs.LANGUAGES.glsl = function(e) { picasa: [ "https://picasaweb.google.com/data/" ] }; p.forceGdriveAuthenticate = function() { - h = e.omit(h, "gdrive"); - var t = new s(); - a(t), l(t, "gdrive"), t.enqueue(); + var e = new s(); + a(e), l(e, "gdrive", !0), e.enqueue(); }, p.upload = function(e, t, n, o, r, u, d) { var h = void 0, p = new s(); a(p), l(p, "gdrive"), p.onRun(function() { diff --git a/public/res-min/themes/blue-gray.css b/public/res-min/themes/blue-gray.css index ce42f953..6a53cc2e 100644 --- a/public/res-min/themes/blue-gray.css +++ b/public/res-min/themes/blue-gray.css @@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo .modal-settings textarea{max-width:100%;min-height:100px} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f0f3f4;-webkit-box-shadow:none;box-shadow:none} .modal-settings .accordion-heading{padding:12px 15px} -.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer} -.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} diff --git a/public/res-min/themes/default.css b/public/res-min/themes/default.css index 5122ab98..c355bd2f 100644 --- a/public/res-min/themes/default.css +++ b/public/res-min/themes/default.css @@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo .modal-settings textarea{max-width:100%;min-height:100px} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f1f1f1;-webkit-box-shadow:none;box-shadow:none} .modal-settings .accordion-heading{padding:12px 15px} -.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer} -.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} diff --git a/public/res-min/themes/night.css b/public/res-min/themes/night.css index 13d14683..22cb0957 100644 --- a/public/res-min/themes/night.css +++ b/public/res-min/themes/night.css @@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo .modal-settings textarea{max-width:100%;min-height:100px} .modal-settings .panel{border:0;border-radius:inherit;background:#323232;border-bottom:1px solid #444444;-webkit-box-shadow:none;box-shadow:none} .modal-settings .accordion-heading{padding:12px 15px} -.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer} -.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} diff --git a/public/res-min/themes/school.css b/public/res-min/themes/school.css index 61e5141d..0cae1f4e 100644 --- a/public/res-min/themes/school.css +++ b/public/res-min/themes/school.css @@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo .modal-settings textarea{max-width:100%;min-height:100px} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #ede9e6;-webkit-box-shadow:none;box-shadow:none} .modal-settings .accordion-heading{padding:12px 15px} -.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer} -.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} diff --git a/public/res/helpers/googleHelper.js b/public/res/helpers/googleHelper.js index 49b56d0e..189759ec 100644 --- a/public/res/helpers/googleHelper.js +++ b/public/res/helpers/googleHelper.js @@ -10,7 +10,32 @@ define([ ], function(_, $, core, utils, settings, eventMgr, AsyncTask) { var connected = false; - var permissionList = {}; + var authorizationMgr = {}; + (function() { + var permissionList = {}; + var isAuthorized = false; + _.each((localStorage.gdrivePermissions || '').split(';'), function(permission) { + permission && (permissionList[permission] = true); + }); + authorizationMgr.reset = function() { + isAuthorized = false; + }; + authorizationMgr.isAuthorized = function(permission) { + return isAuthorized && _.has(permissionList, permission); + }; + authorizationMgr.add = function(permission) { + permissionList[permission] = true; + localStorage.gdrivePermissions = _.keys(permissionList).join(';'); + isAuthorized = true; + }; + authorizationMgr.getListWithNew = function(permission) { + var result = _.keys(permissionList); + if(!_.has(permissionList, permission)) { + result.push(permission); + } + return result; + }; + })(); var googleHelper = {}; @@ -65,9 +90,9 @@ define([ 'https://picasaweb.google.com/data/' ] }; - function authenticate(task, permission) { + function authenticate(task, permission, force) { task.onRun(function() { - if(_.has(permissionList, permission)) { + if(!force && authorizationMgr.isAuthorized(permission)) { task.chain(); return; } @@ -83,7 +108,7 @@ define([ if(immediate === false) { task.timeout = ASYNC_TASK_LONG_TIMEOUT; } - var scopeList = _.chain(scopeMap).pick(_.keys(permissionList).concat([permission])).flatten().value(); + var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value(); gapi.auth.authorize({ 'client_id': GOOGLE_CLIENT_ID, 'scope': scopeList, @@ -103,7 +128,7 @@ define([ return; } // Success - permissionList[permission] = true; + authorizationMgr.add(permission); task.chain(); }); }); @@ -112,10 +137,9 @@ define([ }); } googleHelper.forceGdriveAuthenticate = function() { - permissionList = _.omit(permissionList, 'gdrive') ; var task = new AsyncTask(); connect(task); - authenticate(task, 'gdrive'); + authenticate(task, 'gdrive', true); task.enqueue(); }; @@ -572,14 +596,14 @@ define([ return; } else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") { - permissionList = {}; + authorizationMgr.reset(); errorMsg = "Access to Google account is not authorized."; task.retry(new Error(errorMsg), 1); return; } else if(error.code === 0 || error.code === -1) { connected = false; - permissionList = {}; + authorizationMgr.reset(); core.setOffline(); errorMsg = "|stopPublish"; }