Added GitHub restricted access option in settings. Fixes #248

This commit is contained in:
benweet 2013-12-27 22:12:04 +01:00
parent fcb54b196e
commit e4a1b4536d
6 changed files with 46 additions and 32 deletions

View File

@ -11,10 +11,11 @@
} }
} }
var client_id = getParameter("client_id"); var client_id = getParameter("client_id");
var scope = getParameter("scope") || 'repo,gist';
var code = getParameter("code"); var code = getParameter("code");
if (client_id) { if (client_id) {
window.location.href = "https://github.com/login/oauth/authorize?client_id=" window.location.href = "https://github.com/login/oauth/authorize?client_id="
+ client_id + "&scope=repo,gist"; + client_id + "&scope=" + scope;
} else { } else {
if (code) { if (code) {
localStorage["githubCode"] = code; localStorage["githubCode"] = code;

View File

@ -137,6 +137,8 @@ define([
utils.setInputChecked("#input-settings-gdrive-full-access", settings.gdriveFullAccess); utils.setInputChecked("#input-settings-gdrive-full-access", settings.gdriveFullAccess);
// Dropbox full access // Dropbox full access
utils.setInputChecked("#input-settings-dropbox-full-access", settings.dropboxFullAccess); utils.setInputChecked("#input-settings-dropbox-full-access", settings.dropboxFullAccess);
// GitHub full access
utils.setInputChecked("#input-settings-github-full-access", settings.githubFullAccess);
// Template // Template
utils.setInputValue("#textarea-settings-publish-template", settings.template); utils.setInputValue("#textarea-settings-publish-template", settings.template);
// PDF template // PDF template
@ -181,6 +183,8 @@ define([
newSettings.gdriveFullAccess = utils.getInputChecked("#input-settings-gdrive-full-access"); newSettings.gdriveFullAccess = utils.getInputChecked("#input-settings-gdrive-full-access");
// Drobox full access // Drobox full access
newSettings.dropboxFullAccess = utils.getInputChecked("#input-settings-dropbox-full-access"); newSettings.dropboxFullAccess = utils.getInputChecked("#input-settings-dropbox-full-access");
// GitHub full access
newSettings.githubFullAccess = utils.getInputChecked("#input-settings-github-full-access");
// Template // Template
newSettings.template = utils.getInputTextValue("#textarea-settings-publish-template", event); newSettings.template = utils.getInputTextValue("#textarea-settings-publish-template", event);
// PDF template // PDF template

View File

@ -6,9 +6,10 @@ define([
"utils", "utils",
"storage", "storage",
"logger", "logger",
"settings",
"eventMgr", "eventMgr",
"classes/AsyncTask", "classes/AsyncTask",
], function($, constants, core, utils, storage, logger, eventMgr, AsyncTask) { ], function($, constants, core, utils, storage, logger, settings, eventMgr, AsyncTask) {
var connected; var connected;
var github; var github;
@ -81,7 +82,8 @@ define([
} }
function getCode() { function getCode() {
storage.removeItem("githubCode"); 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(); authWindow.focus();
intervalId = setInterval(function() { intervalId = setInterval(function() {
if(authWindow.closed === true) { if(authWindow.closed === true) {

View File

@ -72,9 +72,11 @@ define([
} }
window.delayedFunction = function() { window.delayedFunction = function() {
gapi.load("client,drive-realtime", function() { gapi.load("client,drive-realtime", function() {
gapi.client.load('drive', 'v2', function() {
connected = true; connected = true;
task.chain(); task.chain();
}); });
});
}; };
$.ajax({ $.ajax({
url: "https://apis.google.com/js/api.js?onload=runDelayedFunction", url: "https://apis.google.com/js/api.js?onload=runDelayedFunction",
@ -115,15 +117,6 @@ define([
task.onRun(function() { task.onRun(function() {
var currentToken = gapi.auth.getToken(); var currentToken = gapi.auth.getToken();
var newToken; var newToken;
function loadGdriveClient() {
if(gapi.client.drive) {
task.chain();
return;
}
gapi.client.load('drive', 'v2', function() {
task.chain();
});
}
function getTokenInfo() { function getTokenInfo() {
$.ajax({ $.ajax({
url: 'https://www.googleapis.com/oauth2/v1/tokeninfo', url: 'https://www.googleapis.com/oauth2/v1/tokeninfo',
@ -141,7 +134,7 @@ define([
authorizationMgr.setUserId(data.user_id); authorizationMgr.setUserId(data.user_id);
authorizationMgr.add(permission); authorizationMgr.add(permission);
authorizationMgr.token = newToken; authorizationMgr.token = newToken;
task.chain(loadGdriveClient); task.chain();
} }
}).fail(function(jqXHR) { }).fail(function(jqXHR) {
var error = { var error = {

View File

@ -1013,7 +1013,7 @@
<label> <label>
<input type="checkbox" id="input-settings-gdrive-full-access" /> <input type="checkbox" id="input-settings-gdrive-full-access" />
Allow StackEdit to open any document in Google Drive Allow StackEdit to open any document in Google Drive
</label> <span class="help-block">Any existing token has to be revoked in </label> <span class="help-block">Existing authorization has to be revoked in
<a href="https://www.google.com/settings/dashboard" target="_blank">Google Dashboard</a> <a href="https://www.google.com/settings/dashboard" target="_blank">Google Dashboard</a>
for this change to take effect.</span> for this change to take effect.</span>
</div> </div>
@ -1031,6 +1031,35 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group">
<div class="col-lg-4"></div>
<div class="col-lg-7">
<div class="checkbox">
<label>
<input type="checkbox" id="input-settings-github-full-access" />
Allow StackEdit to access private repositories in GitHub
</label> <span class="help-block">Existing authorization has to be revoked in
<a href="https://github.com/settings/applications" target="_blank">GitHub settings</a>
for this change to take effect.</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-publish-commit-msg">GitHub commit message</label>
<div class="col-lg-7">
<input type="text" id="input-settings-publish-commit-msg"
class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-ssh-proxy">SSH proxy</label>
<div class="col-lg-7">
<input type="text" id="input-settings-ssh-proxy"
class="form-control">
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="col-lg-4 control-label" <label class="col-lg-4 control-label"
for="textarea-settings-publish-template">Default for="textarea-settings-publish-template">Default
@ -1062,22 +1091,6 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-publish-commit-msg">GitHub commit message</label>
<div class="col-lg-7">
<input type="text" id="input-settings-publish-commit-msg"
class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label"
for="input-settings-ssh-proxy">SSH proxy</label>
<div class="col-lg-7">
<input type="text" id="input-settings-ssh-proxy"
class="form-control">
</div>
</div>
</div> </div>
</div> </div>
<div class="tab-pane" id="tabpane-settings-shortcuts"> <div class="tab-pane" id="tabpane-settings-shortcuts">

View File

@ -15,6 +15,7 @@ define([
gdriveMultiAccount: 1, gdriveMultiAccount: 1,
gdriveFullAccess: true, gdriveFullAccess: true,
dropboxFullAccess: true, dropboxFullAccess: true,
githubFullAccess: true,
template: [ template: [
'<!DOCTYPE html>\n', '<!DOCTYPE html>\n',
'<html>\n', '<html>\n',