aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-07-16 13:02:51 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-07-16 16:28:08 +0200
commit641d7c3743be440112952140ca799b6748b261c7 (patch)
treebd52a73063daa459cace130eea68666eb5e7f6f2
parent3f70ba468a91e0f5abe20034dd50e3c63a6fcb1a (diff)
downloadbugzilla-triage-641d7c3743be440112952140ca799b6748b261c7.tar.gz
Bail out if we are not logged in.
Adding our own exception and checking it. Move configuration button to special method of BZPage. A bit of cleanup. Fixes #20 (I hope).
-rw-r--r--lib/bzpage.js77
-rw-r--r--lib/main.js23
-rw-r--r--lib/rhbzpage.js11
3 files changed, 59 insertions, 52 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 45e1196..3f0f81b 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -16,15 +16,21 @@ var BTSPrefNS = "bugzilla-triage.setting.";
exports.BTSPrefNS = BTSPrefNS;
var BTSPassRealm = "BTSXMLRPCPass";
+// ============================================
+
+var NotLoggedinException = function NotLoggedinException (message) {
+ this.message = message;
+ this.name = "NotLoggedinException";
+};
+
+NotLoggedinException.prototype.toString = function () {
+ return this.name + ': "' + this.message + '"';
+};
+exports.NotLoggedinException = NotLoggedinException;
+
// ====================================================================================
// BZPage's methods
var BZPage = function BZPage(win, config) {
- var keys = "";
- for (var key in config) {
- keys += key + ", ";
- }
- console.log("config keys = " + keys);
-
// constants
this.SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2,
// 85
@@ -34,6 +40,18 @@ var BZPage = function BZPage(win, config) {
var that = this;
this.win = win;
this.doc = win.document;
+
+ // First, preflight check ... if we are not logged in, there
+ // is nothing we can do.
+ var logoutLink = Array.some(this.doc.links, function (x) {
+ return x.search === "?logout=1" ;
+ });
+ if (!logoutLink) {
+ throw new NotLoggedinException("Not logged in");
+ }
+
+ // So, now we know we are logged in, so we can get to
+ // the real work.
this.packages = this.getInstalledPackages(config);
if ("commentStrings" in config.gJSONData) {
@@ -59,28 +77,7 @@ var BZPage = function BZPage(win, config) {
this.setUpLogging();
}
- // configuration button
- var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
- var configurationButtonUI = this.doc.createElement("li");
- configurationButtonUI.innerHTML = "\u00A0-\u00A0<a href='#' id='configurationButton'>"
- + "Configuration buttons</a>";
- additionalButtons.appendChild(configurationButtonUI);
- this.doc.getElementById("configurationButton").addEventListener(
- "click",
- function(evt) {
- var prfNm = BTSPrefNS+"JSONURL";
- var url = preferences.get(prfNm,"");
-
- var reply = that.win.prompt("New location of JSON configuration file",url);
- if (reply) {
- preferences.set(prfNm,reply.trim());
- that.win.alert("For now, you should really restart Firefox!");
- }
-
- evt.stopPropagation();
- evt.preventDefault();
- }, false);
-
+ this.setConfigurationButton();
this.submitHandlerInstalled = false;
this.bugNo = util.getBugNo(this.doc.location.toString());
@@ -439,6 +436,30 @@ BZPage.prototype.generateButtons = function generateButtons () {
}
};
+BZPage.prototype.setConfigurationButton = function setConfigurationButton () {
+ var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
+ var configurationButtonUI = this.doc.createElement("li");
+ configurationButtonUI.innerHTML = "\u00A0-\u00A0<a href='#' id='configurationButton'>"
+ + "Triage configuration</a>";
+ additionalButtons.appendChild(configurationButtonUI);
+ this.doc.getElementById("configurationButton").addEventListener(
+ "click",
+ function(evt) {
+ var prfNm = BTSPrefNS+"JSONURL";
+ var url = preferences.get(prfNm,"");
+
+ // FIXME don't use window.prompt, but create util.prompt instead
+ var reply = that.win.prompt("New location of JSON configuration file",url);
+ if (reply) {
+ preferences.set(prfNm,reply.trim());
+ that.win.alert("For now, you should really restart Firefox!");
+ }
+
+ evt.stopPropagation();
+ evt.preventDefault();
+ }, false);
+};
+
/**
* Get the current email of the reporter of the bug.
*
diff --git a/lib/main.js b/lib/main.js
index 937f237..7524552 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -34,29 +34,6 @@ var config = {};
config.matches = matchesAll.matches;
config.skipMatches = matchesAll.skipMatches;
})();
-// ==============================================================
-// https://wiki.mozilla.org/Labs/Jetpack/JEP/24
-var WillBemanifest = {
- settings : [
- {
- name : "BZpassword",
- type : "password",
- label : "Bugzilla password"
- },
- {
- name : "JSONURL",
- type : "text",
- label : "Configuration file URL",
- "default" : "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json"
- },
- {
- name : "enabledPacks",
- type : "text",
- label : "comment packs which should be enabled",
- "default" : ""
- }
- ]
-};
function isOurPage(window, matchingURLs) {
var url = window.location.href;
diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js
index bc3394c..fd53278 100644
--- a/lib/rhbzpage.js
+++ b/lib/rhbzpage.js
@@ -22,7 +22,16 @@ var tabs = require("tabs");
var RHBugzillaPage = function RHBugzillaPage(win, config) {
// inheritance ... call superobject's constructor
- BZPage.call(this, win, config);
+ try {
+ BZPage.call(this, win, config);
+ } catch (ex) {
+ if (ex instanceof require("bzpage").NotLoggedinException) {
+ console.log(ex);
+ return ; // Bail out if the user is not logged in
+ } else {
+ throw ex; // rethrow the exception otherwise
+ }
+ }
// For identification of graphics card
var manuChipStrs = [ [ "ATI Radeon", "ATI", "1002" ],