aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-02-09 10:56:33 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-02-09 10:56:33 +0100
commitba0b4d6110e5b50c15ce722a5a123bcf26bafe3e (patch)
treef3605fc899db3152068f9c4bfc6f840ea198b11d /lib
parentcc50408c9661d35a81f921ff6347eee3c1781d0f (diff)
downloadbugzilla-triage-ba0b4d6110e5b50c15ce722a5a123bcf26bafe3e.tar.gz
Mainly add XML-RPC handling
In details: * add libbugzilla.makeXMLRPCCall * rewrite addAttachment and fixAttachById to use it * add RHOnMessageHandler to process RHBZ-specific RPC messages * fix the mess around getting passwords and not-provided passwords (there should be no password in a content script) * add libbugzilla.openURLinPanel and make showAttachment to use it * fix indentation of switch statements * remove JSLint strings, we need to fix the script, no screw up my ones
Diffstat (limited to 'lib')
-rw-r--r--lib/libbugzilla.js108
-rw-r--r--lib/main.js94
-rw-r--r--lib/passwords.js1
-rw-r--r--lib/xmlrpc.js1
4 files changed, 133 insertions, 71 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 0477c70..337a72e 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -1,4 +1,3 @@
-/*jslint rhino: true, forin: true, onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: false, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
@@ -12,12 +11,16 @@ var passUtils = require("passwords");
var Request = require("request").Request;
var selfMod = require("self");
var urlMod = require("url");
+var xrpc = require("xmlrpc");
+var panelMod = require("panel");
var JSONURLDefault = "https://fedorahosted.org/released"+
"/bugzilla-triage-scripts/Config_data.json";
var BTSPrefNS = "bugzilla-triage.setting.";
var BTSPassRealm = "BTSXMLRPCPass";
+var passwords = {}; // hash of passwords indexed by a hostname
+
function Message(cmd, data) {
console.log("Message: cmd = " + cmd + ", data = " + data);
this.cmd = cmd;
@@ -46,13 +49,9 @@ function parseXMLfromString (inStuff) {
* In case URL contains alias, not the real bug number, get the real bug no
* from the XML representation. Sets correct value to this.bugNo.
*
- * somewhere in RPC functions which need it, we should have
- * if (isNAN(parseInt(bugNo, 10))) {
- * getRealBugNo(bugNo, location, callback);
- * }
- * Or not
+ * This is a slow variant for bugs other than actual window
*/
-function getRealBugNo(bugNo, location, callback) {
+function getRealBugNoSlow(bugNo, location, callback) {
console.log("We have to deal with bug aliased as " + this.bugNo);
// https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom
Request({
@@ -72,20 +71,19 @@ function getRealBugNo(bugNo, location, callback) {
}).get();
}
-exports.getPassword = function getPassword(login, domain, callback) {
+function getPassword(login, domain) {
var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types";
var switchPrompt = "Do you want to switch off features requiring password completely";
var prefName = BTSPrefNS+"withoutPassowrd";
- var domain = window.location.protocol + "//" + window.location.hostname;
-
+
var pass = passUtils.getPassword(login,
domain, BTSPassRealm);
var retObject = {
- password: null,
- withoutPass: false
+ password: null, // password string or null if no password provided
+ withoutPass: false // whether user doesn't want to use password at all
};
-
- // pass === null means no appropriate password in the storage
+
+ // pass === null means no appropriatjslie password in the storage
if (!preferences.get(prefName,false) && (pass === null)) {
passwordText = prompts.promptPassword(passPrompt);
if (passwordText && passwordText.length > 0) {
@@ -102,30 +100,36 @@ exports.getPassword = function getPassword(login, domain, callback) {
} else {
retObject.password = pass;
}
- callback(new Message("RetPassword", retObject));
-};
+ return retObject;
+}
exports.changeJSONURL = function changeJSONURL() {
var prfNm = BTSPrefNS+"JSONURL";
var url = preferences.get(prfNm,"");
-
+
var reply = prompts.prompt("New location of JSON configuration file", url);
if (reply) {
preferences.set(prfNm, reply.trim());
// TODO Restartless add-on needs to resolve this.
prompts.alert("For now, you should really restart Firefox!");
- }
+ }
};
/**
*
libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
worker.postMessage(pkgsMsg);
+
+ locationLoginObj: {
+ location: window.location.href,
+ login: getLogin()
+ }
*/
-exports.getInstalledPackages = function getInstalledPackages(location, config, callback) {
+exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, config, callback) {
var installedPackages = {};
var enabledPackages = [];
-
+ var location = locationLoginObj.location;
+
if (typeof location == "string") {
location = new urlMod.URL(location);
}
@@ -160,7 +164,7 @@ exports.getInstalledPackages = function getInstalledPackages(location, config, c
}
});
}
-
+
// Expand commentIdx properties into full comments
var cmdObj = {};
for (var pkgKey in installedPackages) {
@@ -168,11 +172,27 @@ exports.getInstalledPackages = function getInstalledPackages(location, config, c
cmdObj = installedPackages[pkgKey][cmdObjKey];
if ("commentIdx" in cmdObj) {
cmdObj.comment = config.gJSONData.commentStrings[cmdObj.commentIdx];
- delete cmdObj.commentIdx;
+ delete cmdObj.commentIdx;
}
}
}
-
+
+ // Investigate situation about password
+ /*
+ passwObj = {
+ password: null, // password string or null if no password provided
+ withoutPass: false // whether user doesn't want to use password at all
+ }; */
+ var locURL = new urlMod.URL(locationLoginObj.location);
+ var passDomain = locURL.scheme + "://" + locURL.host;
+ passwObj = getPassword(locationLoginObj.login, passDomain);
+ // In order to avoid sending whole password to the content script,
+ // we are sending just these two Booleans.
+ config.constantData.passwordState = {
+ passAvailable: (passwObj.password === null),
+ withoutPass: passwObj.withoutPass
+ };
+
callback(new Message("CreateButtons", {
instPkgs: installedPackages,
constData: config.constantData,
@@ -187,6 +207,15 @@ exports.getClipboard = function getClipboard(command, cb) {
}));
};
+exports.openURLInNewPanel = function openURLInNewPanel(url) {
+ panelMod.Panel({
+ contentURL: url,
+ width: 640,
+ height: 640,
+ allow: false // TODO needs to be reviewed
+ });
+}
+
exports.openURLinNewTab = function openURLinNewTab(urlStr) {
tabs.open({
url: urlStr,
@@ -197,9 +226,38 @@ exports.openURLinNewTab = function openURLinNewTab(urlStr) {
});
};
+// Make a XML-RPC call ... most of the business logic should stay in the content script
+exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) {
+ var urlObj = urlMod.URL(url);
+ var passwObj = getPassword(login, urlObj.schema + "://" + urlObj.host);
+ if (!passwObj.password) {
+ return null; // TODO this should happen, only when user presses Escape in password prompt
+ }
+
+ var msg = new xrpc.XMLRPCMessage(method);
+ params.forEach(function (par) {
+ msg.addParameter(par);
+ });
+ msg.addParameter(login);
+ msg.addParameter(passwObj.password);
+
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ var resp = parseXMLfromString(response.text);
+ callback(resp);
+ }
+ },
+ content: msg.xml(),
+ contentType: "text/xml"
+ }).post();
+};
+
exports.initialize = function initialize(config, callback) {
var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
+ var passwObj = {};
if (preferences.isSet(prefName)) {
urlStr = preferences.get(prefName);
@@ -253,7 +311,7 @@ exports.initialize = function initialize(config, callback) {
// config.objConstructor = require("mozillabzpage").MozillaBugzilla;
// callback(config);
-
+
config.constantData = {};
// TODO this is important and missing
if ("constantData" in config.gJSONData) {
@@ -263,7 +321,7 @@ exports.initialize = function initialize(config, callback) {
config.constantData.XMLRPCData = JSON.parse(
selfMod.data.load("XMLRPCdata.json"));
}
-
+
if ("CCmaintainer" in config.constantData) {
config.defBugzillaMaintainerArr = config.constantData.CCmaintainer;
}
diff --git a/lib/main.js b/lib/main.js
index bf34514..5ba237d 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,4 +1,3 @@
-/*jslint rhino: true, forin: true, onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: false, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
@@ -48,47 +47,56 @@ function skipThisPage(doc) {
var messageHandler = exports.messageHandler = function messageHandler(worker, msg) {
console.log("messageHandler: msg = " + msg.toSource());
switch (msg.cmd) {
- case "LogMessage":
- console.log(msg.data);
- break;
- case "ExecCmd":
- libbz.executeCommand(msg.data);
- break;
- case "AddLogRecord":
- logger.addLogRecord(msg.data);
- break;
- case "GenerateTS":
- logger.generateTimeSheet();
- break;
- case "ClearTS":
- logger.clearTimeSheet();
- break;
- case "ImportTS":
- logger.importTimeSheet();
- break;
- case "GetInstalledPackages":
- // send message with packages back
- console.log("msg = " + msg.toSource());
- libbz.getInstalledPackages(msg.data, config, function (pkgsMsg) {
- worker.postMessage(pkgsMsg);
- });
- break;
- case "GetClipboard":
- libbz.getClipboard(msg.data, function (clipboard) {
- worker.postMessage(clipboard);
- });
- break;
- case "ChangeJSONURL":
- libbz.changeJSONURL();
- break;
- case "OpenURLinNewTab":
- libbz.openURLinNewTab(msg.data);
- break;
- case "testReady":
- // we ignore it here, interesting only in unit test
- break;
- default:
- console.error(msg.toSource());
+ case "LogMessage":
+ console.log(msg.data);
+ break;
+ case "ExecCmd":
+ libbz.executeCommand(msg.data);
+ break;
+ case "AddLogRecord":
+ logger.addLogRecord(msg.data);
+ break;
+ case "GenerateTS":
+ logger.generateTimeSheet();
+ break;
+ case "ClearTS":
+ logger.clearTimeSheet();
+ break;
+ case "ImportTS":
+ logger.importTimeSheet();
+ break;
+ case "GetInstalledPackages":
+ // send message with packages back
+ libbz.getInstalledPackages(msg.data, config, function (pkgsMsg) {
+ worker.postMessage(pkgsMsg);
+ });
+ break;
+ case "GetClipboard":
+ libbz.getClipboard(msg.data, function (clipboard) {
+ worker.postMessage(clipboard);
+ });
+ break;
+ case "ChangeJSONURL":
+ libbz.changeJSONURL();
+ break;
+ case "OpenURLinPanel":
+ libbz.openURLinPanel(msg.data);
+ break;
+ case "MakeXMLRPCall":
+ // url, login, method, params, callback
+ libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method,
+ msg.data.params, function(ret) {
+ worker.postMessage({
+ payback: ret,
+ cbRPC: msg.data.callRPC
+ });
+ });
+ break;
+ case "testReady":
+ // we ignore it here, interesting only in unit test
+ break;
+ default:
+ console.error(msg.toSource());
}
};
@@ -116,5 +124,3 @@ libbz.initialize(config, function () {
}
});
});
-
-tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=673153");
diff --git a/lib/passwords.js b/lib/passwords.js
index cc9c16b..af76f47 100644
--- a/lib/passwords.js
+++ b/lib/passwords.js
@@ -1,4 +1,3 @@
-/*jslint forin: true, rhino: true, onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";
diff --git a/lib/xmlrpc.js b/lib/xmlrpc.js
index e883d91..0b84c07 100644
--- a/lib/xmlrpc.js
+++ b/lib/xmlrpc.js
@@ -1,4 +1,3 @@
-/*jslint rhino: true, forin: true, onevar: false, browser: true */
/*global exports: false */
"use strict";
// Modification of Matěj Cepl released under the MIT/X11 license