diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-05-05 18:41:00 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-06-05 14:52:35 +0200 |
commit | 49feb276224dfa812339b94cfe52ea8f0ee5c491 (patch) | |
tree | c9e9c296b1f70fa4573442cd9065d53dc5d35eb5 /lib | |
parent | da49b6460ae02a1a1f0e86aef8f541798730a18f (diff) | |
download | bugzilla-triage-49feb276224dfa812339b94cfe52ea8f0ee5c491.tar.gz |
Add makeJSONRPCCallWithLogin, and other small issues.
* Release 0.102
* Don't react on bugzilla.gnome.org per default
* Simplify handling of preferences and debugging output.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libbugzilla.js | 67 | ||||
-rw-r--r-- | lib/main.js | 24 |
2 files changed, 60 insertions, 31 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index 990c759..ae4ea01 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -26,6 +26,7 @@ var copiedAttributes = [ "queryButton", "upstreamButton", "parseAbrtBacktraces", var passwords = {}; // hash of passwords indexed by a hostname var config = exports.config = {}; +var debugOption = false; function Message(cmd, data) { console.log("Message: cmd = " + cmd + ", data = " + data); @@ -37,6 +38,12 @@ function log(msg) { postMessage(new Message("LogMessage", msg)); } +function debug(str) { + if (debugOption) { + console.log(str); + } +} + /** * parse XML object out of string working around various bugs in Gecko * implementation see https://developer.mozilla.org/en/E4X for more information @@ -61,7 +68,7 @@ function parseXMLfromString (inStuff) { * This is a slow variant for bugs other than actual window */ function getRealBugNoSlow(bugNo, location, callback) { - console.log("We have to deal with bug aliased as " + this.bugNo); + debug("We have to deal with bug aliased as " + this.bugNo); // https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom Request({ url: location.href+"&ctype=xml", @@ -73,7 +80,7 @@ function getRealBugNoSlow(bugNo, location, callback) { if (isNaN(bugID)) { throw new Error("Cannot get bug no. even from XML representation!"); } - console.log("The real bug no. is " + bugID); + debug("The real bug no. is " + bugID); callback(bugID) } } @@ -133,7 +140,7 @@ function getPassword(login, domain, callback) { exports.changeJSONURL = function changeJSONURL() { var prfNm = BTSPrefNS+"JSONURL"; - var url = preferences.get(prfNm,""); + var url = preferences.get(prfNm, JSONURLDefault); var reply = prompts.prompt("New location of JSON configuration file", url); if (reply && (reply != url)) { @@ -287,7 +294,7 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment) exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) { var urlObj = urlMod.URL(url); getPassword(login, - urlObj.schema + "://" + urlObj.host, + urlObj.scheme + "://" + urlObj.host, function (passwObj) { if (!passwObj.password) { // TODO this should happen, only when user presses Escape in password @@ -317,25 +324,46 @@ exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, cal ); }; +exports.makeJSONRPCCallWithLogin = function makeJSONRPCCallWithLogin(url, method, params, + login, callback) { + var urlObj = urlMod.URL(url); + getPassword(login, + urlObj.scheme + "://" + urlObj.host, + function (passObj) { + if (!passObj.password) { + return; + } + + makeJSONRPCCall(url, "User.login", { + login: login, + password: passObj.password, + remember: false + }, function(logResult) { + console.log("logResult = " + logResult.toSource()); + makeJSONRPCCall(url, method, params, callback); + }); + } + ); +}; + // Make a JSONL-RPC call ... most of the business logic should stay in the // content script // http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html -exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback) { +var makeJSONRPCCall = exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback) { -// {"version":"1.1", "method":"Bug.history", "params":{ "ids":[12345] } } var msg = { "version": "1.1", "method": method, "params": params }; -// console.log("makeJSONRPCCall: out = " + JSON.stringify(msg)); + debug("makeJSONRPCCall: out = " + JSON.stringify(msg)); Request({ url: url, onComplete: function(response) { if (response.status == 200) { -// console.log("makeJSONRPCCall: in = " + response.text); + debug("makeJSONRPCCall: in = " + response.text); callback(response.json.result); } }, @@ -346,24 +374,13 @@ exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback exports.initialize = function initialize(config, callback) { var prefJSONURLName = BTSPrefNS+"JSONURL"; - var prefDebugName = BTSPrefNS+"debug"; - var urlStr = "", - debugOption = false; // should we spit out a lot of debugging output + var urlStr = preferences.get(prefJSONURLName, JSONURLDefault); + preferences.set(prefJSONURLName, urlStr); - if (preferences.isSet(prefJSONURLName)) { - urlStr = preferences.get(prefJSONURLName); - } - else { - urlStr = JSONURLDefault; - preferences.set(prefJSONURLName, JSONURLDefault); - } - - if (preferences.isSet(prefDebugName)) { - debugOption = preferences.get(prefDebugName); - } - else { - preferences.set(prefDebugName, debugOption); - } + // should we spit out a lot of debugging output + var prefDebugName = BTSPrefNS+"debug"; + debugOption = preferences.get(prefDebugName, false); + preferences.set(prefDebugName, debugOption); // Randomize URL to avoid caching // TODO see https://fedorahosted.org/bugzilla-triage-scripts/ticket/21 diff --git a/lib/main.js b/lib/main.js index 302dda8..431ffe6 100644 --- a/lib/main.js +++ b/lib/main.js @@ -101,12 +101,24 @@ var messageHandler = exports.messageHandler = function messageHandler( break; case "MakeJSONRPCall": // url, login, method, params, callback - libbz - .makeJSONRPCCall(msg.data.url, msg.data.method, - msg.data.params, function(ret) { - worker.postMessage(new Message(msg.data.callRPC, - ret)); - }); + if (msg.data.login) { + libbz + .makeJSONRPCCallWithLogin(msg.data.url, msg.data.method, + msg.data.params, msg.data.login, function(ret) { + worker.postMessage(new Message(msg.data.callRPC, + ret)); + } + ); + } + else { + libbz + .makeJSONRPCCall(msg.data.url, msg.data.method, + msg.data.params, function(ret) { + worker.postMessage(new Message(msg.data.callRPC, + ret)); + } + ); + } break; case "GetURL": libbz.getURL(msg.data.url, |