aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-07-16 04:25:30 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-07-16 04:25:30 +0200
commit3f70ba468a91e0f5abe20034dd50e3c63a6fcb1a (patch)
tree88fe917ec4e22b26134546249a9f51cbe1b85071 /lib
parent91aac059810fec3d849bb48eb51f55e64b1cc32b (diff)
downloadbugzilla-triage-3f70ba468a91e0f5abe20034dd50e3c63a6fcb1a.tar.gz
Use Firefox nsILoginManager to store password and make it optional.0.13
Fixes #16.
Diffstat (limited to 'lib')
-rw-r--r--lib/bzpage.js33
-rw-r--r--lib/rhbzpage.js6
-rw-r--r--lib/util.js29
3 files changed, 56 insertions, 12 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 3ac61d6..45e1196 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -3,6 +3,7 @@
// http://www.opensource.org/licenses/mit-license.php
"use strict";
var util = require("util");
+var passUtils = require("passwords");
var apiUtils = require("api-utils");
var simpleStorage = require("simple-storage");
var preferences = require("preferences-service");
@@ -13,6 +14,7 @@ var NumberOfFrames = 7;
var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";
var BTSPrefNS = "bugzilla-triage.setting.";
exports.BTSPrefNS = BTSPrefNS;
+var BTSPassRealm = "BTSXMLRPCPass";
// ====================================================================================
// BZPage's methods
@@ -679,15 +681,30 @@ BZPage.prototype.getAttachments = function getAttachments () {
*
* @return String with the password
*/
-BZPage.prototype.getPassword = function getPassword () {
- var prefName = BTSPrefNS+"BZpassword";
- if (preferences.isSet(prefName)) {
- return preferences.get(prefName,undefined);
- } else {
- var passwordText = util.getPassword();
- if (passwordText) {
- preferences.set(prefName, passwordText);
+BZPage.prototype.getPassword = function getPassword (login) {
+ 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 loc = this.win.location;
+ var domain = loc.protocol + "//" + loc.hostname;
+
+ var pass = passUtils.getPassword(login, domain, BTSPassRealm);
+ // pass === null means no appropriate password in the storage
+ if (!preferences.get(prefName,false) && (pass === null)) {
+ var passwordText = util.getPassword(passPrompt);
+ if (passwordText && passwordText.length > 0) {
+ passUtils.setLogin(login, passwordText, domain,
+ BTSPassRealm);
+ return passwordText;
+ } else {
+ var switchOff = util.promptOKNoCancel(switchPrompt);
+ if (switchOff) {
+ preferences.set(prefName,true);
+ }
+ return null;
}
+ } else {
+ return pass;
}
};
diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js
index 82d5e05..bc3394c 100644
--- a/lib/rhbzpage.js
+++ b/lib/rhbzpage.js
@@ -61,7 +61,7 @@ var RHBugzillaPage = function RHBugzillaPage(win, config) {
this.chipMagicInterestingLine = "";
this.login = this.getLogin();
- this.password = this.getPassword();
+ this.password = this.getPassword(this.login);
var ITbutton = this.doc.getElementById("cf_issuetracker");
this.its = ITbutton ? ITbutton.value.trim() : "";
@@ -288,6 +288,10 @@ RHBugzillaPage.prototype.pasteBacktraceInComments = function() {
*/
RHBugzillaPage.prototype.markBadAttachments = function() {
var badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ];
+ if (!this.password) {
+ return ; // User didn't provide password, so whole MIME fixing business
+ // should be switched off.
+ }
var badAttachments = this.attachments.filter(function(att, idx, arr) {
return (util.isInList(att[2], badMIMEArray));
diff --git a/lib/util.js b/lib/util.js
index f582d1d..dd4c4f9 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -197,8 +197,8 @@ var filterByRegexp = exports.filterByRegexp =
*
* @return String with the password
*/
-var getPassword = exports.getPassword = function getPassword(prompt) {
- if (prompt === null) {
+exports.getPassword = function getPassword(prompt) {
+ if (!prompt) { // either undefined or null
prompt = "Enter password:";
}
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
@@ -209,7 +209,7 @@ var getPassword = exports.getPassword = function getPassword(prompt) {
var check = {
value : true
}; // default the checkbox to true
- var result = prompts.promptPassword(null, "Title", prompt,
+ var result = prompts.promptPassword(null, "Bugzilla Triage Script", prompt,
password, null, check);
// result is true if OK was pressed, false if cancel was pressed.
// password.value is set if OK was pressed.
@@ -220,3 +220,26 @@ var getPassword = exports.getPassword = function getPassword(prompt) {
return undefined;
}
};
+
+/**
+ * YES/NO prompt; returns boolean or null (for Cancel)
+ * https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIPromptService
+ */
+exports.promptOKNoCancel = function promptOKNoCancel(prompt) {
+ if (!prompt) { // either undefined or null
+ console.error("Prompt is required!");
+ return undefined;
+ }
+ var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService);
+
+ var result = prompts.confirmEx(null, "Bugzilla Triage Script", prompt,
+ prompts.STD_YES_NO_BUTTONS, null, null, null, null, {});
+ if (result === 0) {
+ return true;
+ } else if (result === 1) {
+ return false;
+ } else {
+ return null;
+ }
+}; \ No newline at end of file