aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-09-01 10:29:28 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-09-01 10:53:51 +0200
commit5efc52cf5cec2b9b5f75351da8e473c2f90266b5 (patch)
tree4bb5bbc15dde0607737e642c0a5075875ebf58bb
parentb6b75faa9ef841396731398a2882e869df5b8ae7 (diff)
downloadbugzilla-triage-5efc52cf5cec2b9b5f75351da8e473c2f90266b5.tar.gz
Eliminating MakeJSONRPC calls and fixing multiple logins.
Fixes #113.
-rw-r--r--data/XMLRPCdata.json14
-rw-r--r--data/lib/bzpage.js6
-rw-r--r--data/lib/collectingMetadata.js4
-rw-r--r--data/lib/rpcutils.js63
-rw-r--r--data/rhlib/addAttachmentRow.js10
-rw-r--r--data/rhlib/fixingAttMIME.js16
-rw-r--r--data/rhlib/rhbzpage.js6
-rw-r--r--data/tweaks/bug-page-mod.js42
-rw-r--r--lib/libbugzilla.js47
-rw-r--r--lib/main.js31
10 files changed, 86 insertions, 153 deletions
diff --git a/data/XMLRPCdata.json b/data/XMLRPCdata.json
deleted file mode 100644
index 085f699..0000000
--- a/data/XMLRPCdata.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "bugzilla.redhat.com": {
- "url": "https://bugzilla.redhat.com/xmlrpc.cgi"
- },
- "bugzilla.mozilla.org": {
- "url": "https://bugzilla.mozilla.org/xmlrpc.cgi"
- },
- "bugs.freedesktop.org": {
- "url": "https://bugs.freedesktop.org/xmlrpc.cgi"
- },
- "bz-web2-test.devel.redhat.com": {
- "url": "https://bz-web2-test.devel.redhat.com/xmlrpc.cgi"
- }
-}
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js
index 4401792..d4c393f 100644
--- a/data/lib/bzpage.js
+++ b/data/lib/bzpage.js
@@ -36,7 +36,7 @@ self.on('message', function onMessage(msg) {
equivalentComponents = ("equivalentComponents" in constantData) ?
constantData.equivalentComponents : null;
generateButtons(msg.data.instPkgs, msg.data.kNodes);
- completeInit();
+ JSONRPCLogin(completeInit);
break;
case "Error":
alert("Error " + msg.data);
@@ -44,8 +44,8 @@ self.on('message', function onMessage(msg) {
case "Unhandled":
break;
default:
- if (TweakOnMessageHandler) {
- TweakOnMessageHandler(msg, [RHOnMessageHandler, MozOnMessageHandler]);
+ if (RHOnMessageHandler) {
+ RHOnMessageHandler(msg, [MozOnMessageHandler]);
}
else {
console.error("Error: unknown RPC call " + msg.toSource());
diff --git a/data/lib/collectingMetadata.js b/data/lib/collectingMetadata.js
index 743c812..00b973d 100644
--- a/data/lib/collectingMetadata.js
+++ b/data/lib/collectingMetadata.js
@@ -170,11 +170,11 @@ AttachList.prototype.markBadAttachments = function markBadAttachments() {
createDeadLink("fixAllButton", "Fix all", titleElement, function () {
Array.forEach(badAttachments, function (x) {
- fixAttachById(x.id, constantData.XMLRPCData[window.location.hostname].url);
+ fixAttachById(x.id);
});
}, [], false, null, "f");
badAttachments.forEach(function (x, i, a) {
- addTextLink(x, constantData.XMLRPCData[window.location.hostname].url);
+ addTextLink(x);
});
}
};
diff --git a/data/lib/rpcutils.js b/data/lib/rpcutils.js
new file mode 100644
index 0000000..d29fd68
--- /dev/null
+++ b/data/lib/rpcutils.js
@@ -0,0 +1,63 @@
+//Released under the MIT/X11 license
+//http://www.opensource.org/licenses/mit-license.php
+"use strict";
+
+/*
+We should first login and then we shouldn't bother with it.
+It could be interesting to know how many logins per second are bad.
+ */
+
+function JSONRPCLogin(callback) {
+ if (!constantData.passwordState.password) {
+ return;
+ }
+
+ console.myDebug("JSONRPCLogin: passObj = " +
+ constantData.passwordState.toSource());
+ makeJSONRPCCall("User.login", {
+ login: getLogin(),
+ password: constantData.passwordState.password,
+ remember: false
+ }, function(logResult) {
+ 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
+function makeJSONRPCCall(method, params, callback) {
+
+ var msg = {
+ "version": "1.1",
+ "method": method,
+ "params": params
+ };
+
+ console.myDebug("makeJSONRPCCall(" + method +
+ "): out = " + JSON.stringify(msg));
+
+ var req = new XMLHttpRequest();
+ req.open('POST', "/jsonrpc.cgi", true);
+ req.onreadystatechange = function (aEvt) {
+ if (req.readyState == 4) {
+ if(req.status == 200) {
+ console.myDebug("makeJSONRPCCall (" + method +
+ "): in = " + req.responseText);
+ var JSONresponse = JSON.parse(req.responseText);
+ if ("error" in JSONresponse) {
+ throw new Error("Error in JSON-RPC call:\n" +
+ JSONresponse.error);
+ }
+ callback(JSONresponse);
+ }
+ else {
+ console.error('Error', req.statusText);
+ }
+ }
+ };
+ req.setRequestHeader('Content-Type', "application/json");
+ req.send(JSON.stringify(msg));
+};
+
diff --git a/data/rhlib/addAttachmentRow.js b/data/rhlib/addAttachmentRow.js
index c8724e3..6fab1bd 100644
--- a/data/rhlib/addAttachmentRow.js
+++ b/data/rhlib/addAttachmentRow.js
@@ -2,7 +2,7 @@
//http://www.opensource.org/licenses/mit-license.php
"use strict";
-//FIXME resp is JSON, not XML anymore
+// FIXME resp is JSON, not XML anymore
function addAttachmentCallback(resp) {
var newAttachID = parseInt(
resp.params.param.value.array.data.value.int, 10);
@@ -51,12 +51,6 @@ function addAttachment(data, callback, param) {
nomail : true
};
- self.postMessage(new Message("MakeJSONRPCall", {
- url : constantData.XMLRPCData[window.location.hostname].url
- .replace("xmlrpc.cgi", "jsonrpc.cgi"),
- method : "bugzilla.addAttachment",
- params : params,
- callRPC : "AddAttachmentCallback"
- }));
+ makeJSONRPCCall("bugzilla.addAttachment", params, addAttachmentCallback);
reqCounter++;
}
diff --git a/data/rhlib/fixingAttMIME.js b/data/rhlib/fixingAttMIME.js
index f61ddbd..220b7ad 100644
--- a/data/rhlib/fixingAttMIME.js
+++ b/data/rhlib/fixingAttMIME.js
@@ -44,7 +44,7 @@ function XMLRPCcallback() {
* this change };
*
*/
-function fixAttachById(id, XMLRPCURL, type, email) {
+function fixAttachById(id, type, email) {
if (type === undefined) {
type = "text/plain";
}
@@ -61,13 +61,7 @@ function fixAttachById(id, XMLRPCURL, type, email) {
'nomail' : !email
};
- self.postMessage(new Message("MakeJSONRPCall", {
- url : XMLRPCURL.replace("xmlrpc.cgi", "jsonrpc.cgi"),
- method : "bugzilla.updateAttachMimeType",
- login : getLogin(),
- params : params,
- callRPC : "FixAttachmentMIMECallback"
- }));
+ makeJSONRPCCall("bugzilla.updateAttachMimeType", params, XMLRPCcallback);
reqCounter++;
}
@@ -78,11 +72,9 @@ function fixAttachById(id, XMLRPCURL, type, email) {
* <TR> DOM jQuery element with a bad attachment
* @return none
*/
-function addTextLink(att, xmlRpcUrl) {
+function addTextLink(att) {
var elemS = att.element.getElementsByTagName("td");
var elem = elemS[elemS.length - 1];
createDeadLink("addFix2TextLink", "text", elem, fixAttachById,
- [
- att.id, xmlRpcUrl
- ], "br");
+ [ att.id ], "br");
}
diff --git a/data/rhlib/rhbzpage.js b/data/rhlib/rhbzpage.js
index 944b9a6..abc84c7 100644
--- a/data/rhlib/rhbzpage.js
+++ b/data/rhlib/rhbzpage.js
@@ -71,12 +71,6 @@ function RHOnMessageHandler(msg, nextHandlerList) {
break;
case "Unhandled":
break;
- case "AddAttachmentCallback":
- addAttachmentCallback(msg.data);
- break;
- case "FixAttachmentMIMECallback":
- XMLRPCcallback();
- break;
case "queryUpstream":
queryUpstreamCallback(msg.data, constantData.queryUpstreamBug);
break;
diff --git a/data/tweaks/bug-page-mod.js b/data/tweaks/bug-page-mod.js
index f5d154e..32672b0 100644
--- a/data/tweaks/bug-page-mod.js
+++ b/data/tweaks/bug-page-mod.js
@@ -33,27 +33,6 @@
* ***** END LICENSE BLOCK *****
*/
-function TweakOnMessageHandler(msg, nextHandlerList) {
- switch (msg.cmd) {
- case "Unhandled":
- break;
- case "returnedHistory":
- processHistory(msg.data);
- break;
- default:
- if (nextHandlerList) {
- var nextHandler = nextHandlerList.splice(0, 1);
- if (nextHandler[0]) {
- nextHandler[0](msg, nextHandlerList);
- }
- }
- else {
- console.error("Error: unknown RPC call " + msg.toSource());
- }
- break;
- }
-}
-
/**
* generate XML-RPC call to collect complete history of the bug
*
@@ -61,9 +40,8 @@ function TweakOnMessageHandler(msg, nextHandlerList) {
* URL of the XML-RPC gateway on the particular bugzilla
* @returns nothing
*
- * As part of the message is name of the signal "returnedHistory"
*/
-function collectHistory(rpcURL) {
+function collectHistory() {
// https://bugzilla.redhat.com/docs/en/html/api/Bugzilla\
// /WebService/Bug.html#Bug_Information
/*
@@ -96,14 +74,7 @@ function collectHistory(rpcURL) {
The change will be made to the production servers in early May, with
notification to the announce list prior to the change.
*/
- var bugId = getBugNo();
- self.postMessage(new Message("MakeJSONRPCall", {
- url : rpcURL.replace("xmlrpc.cgi","jsonrpc.cgi"),
- login : getLogin(),
- method : "Bug.history",
- params : { "ids": [ bugId ] },
- callRPC : "returnedHistory"
- }));
+ makeJSONRPCCall("Bug.history", { "ids": [ getBugNo() ] }, processHistory);
}
function tweakBugzilla(things, cData) {
@@ -199,10 +170,7 @@ function tweakBugzilla(things, cData) {
var CheckinComment = new CheckinCommentCtor();
CheckinComment.initialize(AttachmentFlagHandler._interestingFlags);
- if (document.location.hostname in cData.XMLRPCData) {
- var XMLRPCUrl = cData.XMLRPCData[document.location.hostname].url;
- collectHistory(XMLRPCUrl);
- }
+ collectHistory();
tbplbotSpamCollapser();
}
@@ -334,7 +302,7 @@ return ; // FIXME just to get rid of this unfinished and unanalyzed function
// §§§§ This is a function addToInlineHistory or something TODO
var currentDiv = document.createElement("div");
var userPrefix = '';
- if (inline) {
+ if (inline) {
// assume that the change was made by the same user // XXX? §§§
commentHead.appendChild(currentDiv);
currentDiv.setAttribute("class", "bztw_inlinehistory");
@@ -408,7 +376,7 @@ return ; // FIXME just to get rid of this unfinished and unanalyzed function
formatTransition(trimContent(item[3]), trimContent(item[4]),
trimContent(item[2]), iframe.contentDocument);
-//
+//
var nextItemsCount = item[0].rowSpan;
for (var k = 1; k < nextItemsCount; ++k) {
// XXX doing once more the same for non-first elements of the imte array.
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 46356cc..4858a96 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -11,7 +11,6 @@ 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"+
@@ -87,8 +86,10 @@ function getRealBugNoSlow(bugNo, location, callback) {
}
function getPassword(login, domain, callback) {
- var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types";
- var switchPrompt = "Do you want to switch off features requiring password completely";
+ var passPrompt = "Enter your Bugzilla password " +
+ "for accessing JSONRPC services";
+ var switchPrompt = "Do you want to switch off features " +
+ "requiring password completely";
var prefName = BTSPrefNS+"withoutPassowrd";
var retObject = {
password: null, // password string or null if no password provided
@@ -217,6 +218,7 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
// In order to avoid sending whole password to the content script,
// we are sending just these two Booleans.
config.constantData.passwordState = {
+ password: passwObj.password,
passAvailable: (passwObj.password !== null),
withoutPass: passwObj.withoutPass
};
@@ -283,41 +285,6 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subjectStr, comme
});
};
-// 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);
- getPassword(login,
- urlObj.scheme + "://" + urlObj.host,
- function (passwObj) {
- if (!passwObj.password) {
- // TODO this should happen, only when user presses Escape in password
- // prompt
- return null;
- }
-
- 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.toXMLString());
- }
- },
- content: msg.xml(),
- contentType: "text/xml"
- }).post();
- }
- );
-};
-
exports.makeJSONRPCCallWithLogin = function makeJSONRPCCallWithLogin(url, method,
params, login, callback) {
var urlObj = urlMod.URL(url);
@@ -328,7 +295,7 @@ exports.makeJSONRPCCallWithLogin = function makeJSONRPCCallWithLogin(url, method
return;
}
- console.myDebug("makeJSONRPCCallWithLogin: passObj = " +
+ debug("makeJSONRPCCallWithLogin: passObj = " +
passObj.toSource());
makeJSONRPCCall(url, "User.login", {
login: login,
@@ -418,8 +385,6 @@ exports.initialize = function initialize(config, callback) {
config.constantData = config.gJSONData.constantData;
config.constantData.queryUpstreamBug = JSON.parse(
selfMod.data.load("queryUpstreamBug.json"));
- config.constantData.XMLRPCData = JSON.parse(
- selfMod.data.load("XMLRPCdata.json"));
config.constantData.bugzillaLabelNames =
JSON.parse(selfMod.data.load("bugzillalabelNames.json"));
config.constantData.newUpstreamBug =
diff --git a/lib/main.js b/lib/main.js
index b7ac152..1d97e81 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -86,36 +86,6 @@ var messageHandler = exports.messageHandler = function messageHandler(
case "OpenStringInPanel":
libbz.openStringInNewPanel(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(new Message(msg.data.callRPC,
- ret));
- });
- break;
- case "MakeJSONRPCall":
- // url, login, method, params, callback
- console.myDebug("messageHandler: msg = " + msg.toSource());
- 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;
// Needed because creating additional page-mods on remote bugzilla
case "OpenBugUpstream":
libbz.createUpstreamBug(msg.data.url, msg.data.subject,
@@ -133,6 +103,7 @@ var messageHandler = exports.messageHandler = function messageHandler(
var contentScriptLibraries = [
self.data.url('tweaks/urltest.js'),
self.data.url("lib/util.js"),
+ self.data.url("lib/rpcutils.js"),
self.data.url("lib/jumpNextBug.js"),
self.data.url("lib/queries.js"),
self.data.url("lib/collectingMetadata.js"),