From e4a1b4536d6188cc8685aa818856a85d2d20a96f Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 27 Dec 2013 22:12:04 +0100 Subject: [PATCH] Added GitHub restricted access option in settings. Fixes #248 --- public/html/github-oauth-client.html | 3 +- public/res/core.js | 4 +++ public/res/helpers/githubHelper.js | 6 ++-- public/res/helpers/googleHelper.js | 17 +++------- public/res/html/bodyIndex.html | 47 ++++++++++++++++++---------- public/res/settings.js | 1 + 6 files changed, 46 insertions(+), 32 deletions(-) diff --git a/public/html/github-oauth-client.html b/public/html/github-oauth-client.html index e8f83c92..397117a6 100644 --- a/public/html/github-oauth-client.html +++ b/public/html/github-oauth-client.html @@ -11,10 +11,11 @@ } } var client_id = getParameter("client_id"); + var scope = getParameter("scope") || 'repo,gist'; var code = getParameter("code"); if (client_id) { window.location.href = "https://github.com/login/oauth/authorize?client_id=" - + client_id + "&scope=repo,gist"; + + client_id + "&scope=" + scope; } else { if (code) { localStorage["githubCode"] = code; diff --git a/public/res/core.js b/public/res/core.js index 19c0a248..46362773 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -137,6 +137,8 @@ define([ utils.setInputChecked("#input-settings-gdrive-full-access", settings.gdriveFullAccess); // Dropbox full access utils.setInputChecked("#input-settings-dropbox-full-access", settings.dropboxFullAccess); + // GitHub full access + utils.setInputChecked("#input-settings-github-full-access", settings.githubFullAccess); // Template utils.setInputValue("#textarea-settings-publish-template", settings.template); // PDF template @@ -181,6 +183,8 @@ define([ newSettings.gdriveFullAccess = utils.getInputChecked("#input-settings-gdrive-full-access"); // Drobox full access newSettings.dropboxFullAccess = utils.getInputChecked("#input-settings-dropbox-full-access"); + // GitHub full access + newSettings.githubFullAccess = utils.getInputChecked("#input-settings-github-full-access"); // Template newSettings.template = utils.getInputTextValue("#textarea-settings-publish-template", event); // PDF template diff --git a/public/res/helpers/githubHelper.js b/public/res/helpers/githubHelper.js index 27603af6..325678a5 100644 --- a/public/res/helpers/githubHelper.js +++ b/public/res/helpers/githubHelper.js @@ -6,9 +6,10 @@ define([ "utils", "storage", "logger", + "settings", "eventMgr", "classes/AsyncTask", -], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) { +], function($, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) { var connected; var github; @@ -81,7 +82,8 @@ define([ } function getCode() { storage.removeItem("githubCode"); - authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + constants.GITHUB_CLIENT_ID, 'stackedit-github-oauth', 960, 600); + var scope = settings.githubFullAccess ? 'repo,gist' : 'public_repo,gist'; + authWindow = utils.popupWindow('html/github-oauth-client.html?client_id=' + constants.GITHUB_CLIENT_ID + '&scope=' + scope, 'stackedit-github-oauth', 960, 600); authWindow.focus(); intervalId = setInterval(function() { if(authWindow.closed === true) { diff --git a/public/res/helpers/googleHelper.js b/public/res/helpers/googleHelper.js index 61a42301..e96f8af8 100644 --- a/public/res/helpers/googleHelper.js +++ b/public/res/helpers/googleHelper.js @@ -72,8 +72,10 @@ define([ } window.delayedFunction = function() { gapi.load("client,drive-realtime", function() { - connected = true; - task.chain(); + gapi.client.load('drive', 'v2', function() { + connected = true; + task.chain(); + }); }); }; $.ajax({ @@ -115,15 +117,6 @@ define([ task.onRun(function() { var currentToken = gapi.auth.getToken(); var newToken; - function loadGdriveClient() { - if(gapi.client.drive) { - task.chain(); - return; - } - gapi.client.load('drive', 'v2', function() { - task.chain(); - }); - } function getTokenInfo() { $.ajax({ url: 'https://www.googleapis.com/oauth2/v1/tokeninfo', @@ -141,7 +134,7 @@ define([ authorizationMgr.setUserId(data.user_id); authorizationMgr.add(permission); authorizationMgr.token = newToken; - task.chain(loadGdriveClient); + task.chain(); } }).fail(function(jqXHR) { var error = { diff --git a/public/res/html/bodyIndex.html b/public/res/html/bodyIndex.html index 1beb4283..ba8c960b 100644 --- a/public/res/html/bodyIndex.html +++ b/public/res/html/bodyIndex.html @@ -1013,7 +1013,7 @@ Any existing token has to be revoked in + Existing authorization has to be revoked in Google Dashboard for this change to take effect. @@ -1031,6 +1031,35 @@ +
+
+
+
+ Existing authorization has to be revoked in + GitHub settings + for this change to take effect. +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
-
- -
- -
-
-
- -
- -
-
diff --git a/public/res/settings.js b/public/res/settings.js index 47ebb266..4f681b47 100644 --- a/public/res/settings.js +++ b/public/res/settings.js @@ -15,6 +15,7 @@ define([ gdriveMultiAccount: 1, gdriveFullAccess: true, dropboxFullAccess: true, + githubFullAccess: true, template: [ '\n', '\n',