handling missing setting values

- default value given to panelDisplyLocation if missing instead of showing an error msg
- sending an error msg when user tries to use the plugin if settings are missing
- send a warn msg in the console on server start and when using the plugin if settings are missing
This commit is contained in:
quenenni 2013-04-04 20:39:43 +02:00
parent 941ede5daf
commit 0bccbc5ce1
3 changed files with 44 additions and 16 deletions

View file

@ -15,7 +15,8 @@
"postAceInit":"ep_email_notifications/static/js/ep_email:postAceInit", "postAceInit":"ep_email_notifications/static/js/ep_email:postAceInit",
"handleClientMessage_emailSubscriptionSuccess":"ep_email_notifications/static/js/ep_email", "handleClientMessage_emailSubscriptionSuccess":"ep_email_notifications/static/js/ep_email",
"handleClientMessage_emailUnsubscriptionSuccess":"ep_email_notifications/static/js/ep_email", "handleClientMessage_emailUnsubscriptionSuccess":"ep_email_notifications/static/js/ep_email",
"handleClientMessage_emailNotificationGetUserInfo":"ep_email_notifications/static/js/ep_email" "handleClientMessage_emailNotificationGetUserInfo":"ep_email_notifications/static/js/ep_email",
"handleClientMessage_emailNotificationMissingParams":"ep_email_notifications/static/js/ep_email"
} }
} }
] ]

View file

@ -6,11 +6,14 @@ randomString = require('../../src/static/js/pad_utils').randomString;
settings = require('../../src/node/utils/Settings'); settings = require('../../src/node/utils/Settings');
var pluginSettings = settings.ep_email_notifications; var pluginSettings = settings.ep_email_notifications;
var areParamsOk = (pluginSettings)?true:false;
var fromName = (pluginSettings && pluginSettings.fromName)?pluginSettings.fromName:"Etherpad"; var fromName = (pluginSettings && pluginSettings.fromName)?pluginSettings.fromName:"Etherpad";
var fromEmail = (pluginSettings && pluginSettings.fromEmail)?pluginSettings.fromEmail:"pad@etherpad.org"; var fromEmail = (pluginSettings && pluginSettings.fromEmail)?pluginSettings.fromEmail:"pad@etherpad.org";
var urlToPads = (pluginSettings && pluginSettings.urlToPads)?pluginSettings.urlToPads:"http://beta.etherpad.org/p/"; var urlToPads = (pluginSettings && pluginSettings.urlToPads)?pluginSettings.urlToPads:"http://beta.etherpad.org/p/";
var emailServer = (pluginSettings && pluginSettings.emailServer)?pluginSettings.emailServer:{host:"127.0.0.1"}; var emailServer = (pluginSettings && pluginSettings.emailServer)?pluginSettings.emailServer:{host:"127.0.0.1"};
if (areParamsOk == false) console.warn("Settings for ep_email_notifications plugin are missing in settings.json file");
// Connect to the email server -- This might not be the ideal place to connect but it stops us having lots of connections // Connect to the email server -- This might not be the ideal place to connect but it stops us having lots of connections
var server = email.server.connect(emailServer); var server = email.server.connect(emailServer);
@ -18,7 +21,15 @@ var server = email.server.connect(emailServer);
exports.handleMessage = function(hook_name, context, callback){ exports.handleMessage = function(hook_name, context, callback){
if (context.message && context.message.data){ if (context.message && context.message.data){
if (context.message.data.type == 'USERINFO_UPDATE' ) { // if it's a request to update an authors email if (context.message.data.type == 'USERINFO_UPDATE' ) { // if it's a request to update an authors email
if (context.message.data.userInfo){ if (areParamsOk == false) {
context.client.json.send({ type: "COLLABROOM",
data:{
type: "emailNotificationMissingParams",
payload: true
}
});
console.warn("Settings for ep_email_notifications plugin are missing in settings.json file");
} else if (context.message.data.userInfo){
if(context.message.data.userInfo.email){ // it contains email if(context.message.data.userInfo.email){ // it contains email
console.debug(context.message); console.debug(context.message);

View file

@ -6,21 +6,12 @@ if(typeof exports == 'undefined'){
} }
exports.postAceInit = function(hook, context){ exports.postAceInit = function(hook, context){
// Test if settings are good before continuing // If panelDisplayLocation setting is missing, set default value
if (typeof clientVars.panelDisplayLocation != "object") { if (typeof clientVars.panelDisplayLocation != "object") {
$.gritter.add({ clientVars.panelDisplayLocation = {
// (string | mandatory) the heading of the notification mysettings: true, // In the "mysettings" menu
title: window._('ep_email_notifications.titleGritterError'), popup: true
// (string | mandatory) the text inside the notification }
text: window._('ep_email_notifications.msgParamsMissing'),
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true
});
// Hide the notification menu in mysettings
$('#options-emailNotifications').parent().hide();
return false;
} }
// If plugin settings set panel form in mysettings menu // If plugin settings set panel form in mysettings menu
@ -118,6 +109,31 @@ exports.handleClientMessage_emailNotificationGetUserInfo = function (hook, conte
} }
} }
exports.handleClientMessage_emailNotificationMissingParams = function (hook, context) { // Settings are missing in settings.json file
if (context.payload == true) {
$.gritter.add({
// (string | mandatory) the heading of the notification
title: window._('ep_email_notifications.titleGritterError'),
// (string | mandatory) the text inside the notification
text: window._('ep_email_notifications.msgParamsMissing'),
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true
});
// Hide the notification menu in mysettings
if (clientVars.panelDisplayLocation.mysettings == true && $('.ep_email_settings').is(":visible")) {
$('.ep_email_settings').slideToggle();
$('#options-emailNotifications').prop('checked', false);
$('#options-emailNotifications').parent().hide();
}
// Hide the popup if it is visible
if (clientVars.panelDisplayLocation.popup == true && $('#ep_email_form_popup').is(":visible")) {
$('#ep_email_form_popup').parent().parent().parent().hide();
}
}
}
/** /**
* Initialize the popup panel form for subscription * Initialize the popup panel form for subscription
*/ */