move settings to settings file

This commit is contained in:
John McLear 2013-01-31 15:49:45 +00:00
parent c616591391
commit 58b5144f19
4 changed files with 59 additions and 32 deletions

View file

@ -1,6 +1,27 @@
# Description
This plugin allows users to subscribe to pads and recieve email updates when a pad is being modified. You can modify the frequency. This plugin is very much in alpha stage and has a lot of things TODO (See TODO).
# Installation
Make sure an SMTP gateway is installed IE postfix
Configure SPF and RDNS records to ensure proper mail flow <-- Search online
Copy/Edit the below to your settings.json
Connect to a pad, Click on the Share/Embed link and enter in your email address.
Open that pad in ANOTHER BROWSER then begin modifying, you should recieve an email when the pad has begun editing and once the pad has gone stale (when everyone stops editing it and a time period passes).
```
"ep_email_notifications" : {
checkFrequency: 6000, // checkFrequency = How frequently(milliseconds) to check for pad updates -- Move me to the settings file
staleTime: 30000, // staleTime = How stale(milliseconds) does a pad need to be before notifying subscribers? Move me to settings
fromName: "Etherpad SETTINGS FILE!",
fromEmail: "pad@etherpad.org",
urlToPads: "http://beta.etherpad.org/p/", // urlToPads = The URL to your pads note the trailing /
smtpHostname: "127.0.0.1"
}
```
# TODO # TODO
* a point to unsubscribe and validate email https://github.com/alfredwesterveld/node-email-verification * a point to unsubscribe and validate/verify email https://github.com/alfredwesterveld/node-email-verification
* stop the ui prompting if already subscribed * stop the ui prompting if already subscribed
* move settings to settings.json * move settings to settings.json
* Clean up all code * Clean up all code
@ -9,3 +30,5 @@
* Re-enable the pop up * Re-enable the pop up
* Some schpeil about setting your server up IE Postfix / RDNS & SPF records * Some schpeil about setting your server up IE Postfix / RDNS & SPF records
* Exports is undefined error * Exports is undefined error
* Stop it emailing me if I'm the person who made the updates
* Allow for various SMTP auth / connectivity types

View file

@ -9,7 +9,7 @@
"eejsBlock_embedPopup": "ep_email_notifications/client:eejsBlock_embedPopup" "eejsBlock_embedPopup": "ep_email_notifications/client:eejsBlock_embedPopup"
}, },
"client_hooks": { "client_hooks": {
"documentReady":"ep_email_notifications/static/js/ep_email", "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"
} }
} }

View file

@ -1,4 +1,4 @@
exports.documentReady = function(){ exports.postAceInit = function(hook, context){
// after 10 seconds if we dont already have an email for this author then prompt them // after 10 seconds if we dont already have an email for this author then prompt them
setTimeout(function(){init()},10000); setTimeout(function(){init()},10000);

View file

@ -1,5 +1,4 @@
// We check pads periodically for activity and notify owners when someone begins editing and when someone finishes. // Main job is to check pads periodically for activity and notify owners when someone begins editing and when someone finishes.
var db = require('../../src/node/db/DB').db, var db = require('../../src/node/db/DB').db,
API = require('../../src/node/db/API.js'), API = require('../../src/node/db/API.js'),
async = require('../../src/node_modules/async'), async = require('../../src/node_modules/async'),
@ -7,20 +6,24 @@
email = require('emailjs'), email = require('emailjs'),
settings = require('../../src/node/utils/Settings'); settings = require('../../src/node/utils/Settings');
// Settings -- EDIT THESE IN settings.json not here..
var pluginSettings = settings.ep_email_notifications; var pluginSettings = settings.ep_email_notifications;
var checkInterval = 3000; // How frequently(milliseconds) to check for pad updates -- Move me to the settings file var checkFrequency = pluginSettings.checkFrequency || 3000;
var staleTime = 30000; // How stale(milliseconds) does a pad need to be before notifying subscribers? Move me to settings var staleTime = pluginSettings.staleTime || 30000;
var timers = {}; var fromName = pluginSettings.fromName || "Etherpad";
var fromName = "Etherpad"; var fromEmail = pluginSettings.fromEmail || "pad@etherpad.org";
var fromEmail = "pad@etherpad.org"; var urlToPads = pluginSettings.urlToPads || "http://beta.etherpad.org/p/";
var urlToPads = "http://beta.etherpad.org/p/"; // The URL to your pads note the trailing / var smtpHostname = pluginSettings.smtpHostname || "127.0.0.1";
// A timer object we maintain to control how we send emails
var timers = {};
// Connect to the email server
var server = email.server.connect({ var server = email.server.connect({
host: "127.0.0.1", host: smtpHostname,
}); });
exports.padUpdate = function (hook_name, _pad) { exports.padUpdate = function (hook_name, _pad) {
var pad = _pad.pad; var pad = _pad.pad;
var padId = pad.id; var padId = pad.id;
exports.sendUpdates(padId); exports.sendUpdates(padId);
@ -31,32 +34,33 @@ exports.padUpdate = function (hook_name, _pad) {
exports.notifyBegin(padId); exports.notifyBegin(padId);
console.debug("Created an interval time check for "+padId); console.debug("Created an interval time check for "+padId);
// if not then create one and write it to the timers object // if not then create one and write it to the timers object
timers[padId] = exports.createInterval(padId, checkInterval); timers[padId] = exports.createInterval(padId, checkFrequency);
}else{ // an interval already exists so don't create }else{ // an interval already exists so don't create
} }
}; };
exports.notifyBegin = function(padId){ exports.notifyBegin = function(padId){
console.warn("Getting "+padId); console.warn("Getting "+padId);
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
console.warn(recipients); console.warn(recipients);
async.forEach(Object.keys(recipients), function(recipient, cb){ if(recipients){
console.warn("Emailing "+recipient +" about a new begin update"); async.forEach(Object.keys(recipients), function(recipient, cb){
console.warn("Emailing "+recipient +" about a new begin update");
server.send({
text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)", server.send({
from: fromName+ "<"+fromEmail+">", text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)",
to: recipient, from: fromName+ "<"+fromEmail+">",
subject: "Someone begin editing "+padId to: recipient,
}, function(err, message) { console.log(err || message); }); subject: "Someone begin editing "+padId
}, function(err, message) { console.log(err || message); });
cb(); // finish each user
}, cb(); // finish each user
function(err){ },
function(err){
});
});
}
}); });
} }
@ -152,10 +156,10 @@ exports.isUserEditingPad = function(padId, user, cb){
}); });
}; };
// Creates an interval process to check to send Updates based on checkInterval and it returns an ID // Creates an interval process to check to send Updates based on checkFrequency and it returns an ID
exports.createInterval = function(padId){ exports.createInterval = function(padId){
return setInterval(function(){ return setInterval(function(){
exports.sendUpdates(padId), checkInterval exports.sendUpdates(padId), checkFrequency
}); });
} }