Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(project): move mailer files into proper directories (#1676) r=vla…
Browse files Browse the repository at this point in the history
…dikoff
  • Loading branch information
philbooth authored and vladikoff committed Feb 24, 2017
1 parent 0c52a7c commit d09759c
Show file tree
Hide file tree
Showing 97 changed files with 7,889 additions and 13,856 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ secret*
/.vagrant
.nyc_output
npm-debug.log
mailer/server.pot
mailer/.mail_output
server.pot
.mail_output
3 changes: 3 additions & 0 deletions .nsprc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"exceptions": [
// i18n-abide@0.0.25
"https://nodesecurity.io/advisories/39",
"https://nodesecurity.io/advisories/48"
]
}
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ script:
- COVERALLS_REPO_TOKEN=vKN3jjhAOwxkv9HG0VBX4EYIlWLPwiJ9d npm test
- npm run test-e2e
# Test fxa-auth-mailer
- cd mailer
- grunt templates
- npm test
- grunt l10n-extract
- cd ..
# NSP check
- grunt nsp
5 changes: 5 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt)

grunt.initConfig({
pkg: grunt.file.readJSON('package.json')
})

grunt.loadTasks('grunttasks')

grunt.registerTask('default', ['eslint', 'copyright'])
grunt.registerTask('mailer', ['templates', 'copy:strings', 'l10n-extract'])
}
18 changes: 9 additions & 9 deletions mailer/bin/server.js → bin/mailer_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var restify = require('restify')
var config = require('../config')
var config = require('../mailer/config')

var log = require('../log')('server')
var log = require('../lib/senders/log')('server')
var mailConfig = config.get('mail')

var packageJson = require('../package.json')
var P = require('bluebird')

// NOTE: Mailer is also used by fxa-auth-server directly with an old logging interface
// the legacy log module provides an interface to convert old logs to new mozlog logging.
var mailerLog = require('../log')('mailer')
var legacyMailerLog = require('../legacy_log')(mailerLog)
var Mailer = require('../mailer')(legacyMailerLog)
var mailerLog = require('../lib/senders/log')('mailer')
var legacyMailerLog = require('../lib/senders/legacy_log')(mailerLog)
var Mailer = require('../lib/senders/email')(legacyMailerLog)

var dbConnect = require('../lib/db_connect')()
var dbConnect = require('../lib/senders/db_connect')()

P.all(
[
require('../translator')(config.get('locales'), config.get('defaultLanguage')),
require('../templates')()
require('../lib/senders/translator')(config.get('locales'), config.get('defaultLanguage')),
require('../lib/senders/templates')()
]
)
.spread(
Expand All @@ -35,7 +35,7 @@ P.all(
dbConnect()
.then(function (db) {
// fetch and process verification reminders
var verificationReminders = require('../lib/verification-reminders')(mailer, db)
var verificationReminders = require('../lib/senders/verification-reminders')(mailer, db)
verificationReminders.poll()
})
.catch(function (err) {
Expand Down
2 changes: 1 addition & 1 deletion grunttasks/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function (grunt) {
bumpVersion: true,
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json', 'npm-shrinkwrap.json', 'CHANGELOG.md'],
commitFiles: ['package.json', 'npm-shrinkwrap.json', 'CHANGELOG.md', 'AUTHORS'],
createTag: true,
tagName: 'v%VERSION%',
tagMessage: 'Version %VERSION%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (grunt) {
var done = this.async()

var walker = extract({
'input-dir': path.join(pkgroot, 'templates'),
'input-dir': path.join(pkgroot, 'lib/senders/templates'),
'output-dir': pkgroot,
'output': 'server.pot',
'join-existing': true,
Expand All @@ -43,12 +43,7 @@ module.exports = function (grunt) {

walker.on('end', function () {
var jsWalker = extract({
'input-dir': pkgroot,
/* node_modules and test should not contain any strings
* Gruntfile causes an error and should contain no strings
* bin/server.js extracts "/", so it is excluded.
*/
exclude: /(node_modules|test|Gruntfile|grunttasks|bin|scripts|\.git|config)/,
'input-dir': path.join(pkgroot, 'lib/senders'),
'output-dir': pkgroot,
'output': 'server.pot',
'join-existing': true,
Expand Down
5 changes: 3 additions & 2 deletions mailer/grunttasks/templates.js → grunttasks/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function (grunt) {

grunt.config('nunjucks', {
options: {
paths: 'lib/senders/',
tags: {
blockStart: '<%',
blockEnd: '%>',
Expand All @@ -23,9 +24,9 @@ module.exports = function (grunt) {
files: [
{
expand: true,
cwd: 'partials/',
cwd: 'lib/senders/partials/',
src: '*.html',
dest: 'templates/',
dest: 'lib/senders/templates/',
ext: '.html'
}
]
Expand Down
10 changes: 5 additions & 5 deletions mailer/lib/db.js → lib/senders/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var butil = require('./crypto/butil')
var log = require('../log')('db')
var P = require('./promise')
var butil = require('../crypto/butil')
var log = require('./log')('db')
var P = require('../promise')
var Pool = require('./pool')
var qs = require('querystring')

Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = function () {
.then(
function (body) {
var data = bufferize(body)
data.emailVerified = !!data.emailVerified
data.emailVerified = !! data.emailVerified
return data
},
function (err) {
Expand All @@ -55,7 +55,7 @@ module.exports = function () {
.then(
function (body) {
var data = bufferize(body)
data.emailVerified = !!data.emailVerified
data.emailVerified = !! data.emailVerified
return data
},
function (err) {
Expand Down
10 changes: 5 additions & 5 deletions mailer/lib/db_connect.js → lib/senders/db_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var P = require('bluebird')
var config = require('../config')
var log = require('../log')('db')
var config = require('../../mailer/config')
var log = require('./log')('db')

var DB = require('./db')()

Expand All @@ -29,10 +29,10 @@ module.exports = function () {
function (err) {
if (err && err.message && err.message.indexOf('ECONNREFUSED') > -1) {
log.warn('db', {message: 'Failed to connect to database, retrying...'})
if (!cancelled) {
if (! cancelled) {
return P.delay(dbConnectionRetry)
.then(function () {
if (!cancelled) {
if (! cancelled) {
return dbConnectPoll()
}
})
Expand All @@ -51,7 +51,7 @@ module.exports = function () {
// report any errors to the db log and rethrow it to the consumer.
log.error('db', {err: err})
throw err
});
})
}

return dbConnect
Expand Down
File renamed without changes.
17 changes: 11 additions & 6 deletions lib/senders.js → lib/senders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

'use strict'

const P = require('./promise')
const createSenders = require('../mailer/index')
var P = require('../promise')
// This indirection exists to accommodate different config properties
// in the old auth mailer. If/when the two config files are merged and
// there's nothing left that imports mailer/config, it is safe to merge
// raw.js and this file into one. Be careful not to mix the arguments
// up when you do that, they expect config and log in a different order.
var createSenders = require('./legacy_index')

module.exports = (config, log) => {
const defaultLanguage = config.i18n.defaultLanguage
module.exports = function (config, log) {
var defaultLanguage = config.i18n.defaultLanguage

return createSenders(
log,
Expand All @@ -20,8 +25,8 @@ module.exports = (config, log) => {
}
)
.then(
senders => {
const mailer = senders.email
function (senders) {
var mailer = senders.email
mailer.sendVerifyCode = function (account, code, opts) {
return P.resolve(mailer.verifyEmail(
{
Expand Down
13 changes: 10 additions & 3 deletions mailer/index.js → lib/senders/legacy_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var P = require('bluebird')
var createMailer = require('./mailer')
var createSms = require('./lib/sms')
// This module exists because some files still use the old mailer config.
// Those files should import this module rather than its sibling index.js.
// If/when we eliminate the old mailer config and everything is importing
// index.js, we can merge this into there and get rid of the indirection.
// Be careful when doing that btw, they expect the log and config arguments
// in a different order.

var P = require('../promise')
var createMailer = require('./email')
var createSms = require('./sms')

module.exports = function (log, config, sender) {
var Mailer = createMailer(log)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion mailer/log.js → lib/senders/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var mozlog = require('mozlog')

var logConfig = require('./config').get('logging')
var logConfig = require('../../mailer/config').get('logging')

mozlog.config(logConfig)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mailer/lib/pool.js → lib/senders/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var P = require('./promise')
var P = require('../promise')
var Poolee = require('poolee')

function parseUrl(url) {
Expand Down
2 changes: 1 addition & 1 deletion mailer/lib/sms.js → lib/senders/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (log, translator, templates, smsConfig) {
apiKey: smsConfig.apiKey,
apiSecret: smsConfig.apiSecret
})
var sendSms = P.promisify(nexmo.message.sendSms, { context: nexmo.message })
var sendSms = P.promisify(nexmo.message.sendSms, nexmo.message)

return {
send: function (phoneNumber, senderId, messageId, acceptLanguage) {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions mailer/templates/index.js → lib/senders/templates/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var path = require('path')
var P = require('bluebird')
var handlebars = require('handlebars')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion mailer/translator.js → lib/senders/translator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var path = require('path')
var i18n = require('i18n-abide')
var Jed = require('jed')
Expand All @@ -14,7 +18,7 @@ module.exports = function (locales, defaultLanguage) {
return poParseFile(
path.join(
__dirname,
'node_modules/fxa-content-server-l10n/locale',
'../../node_modules/fxa-content-server-l10n/locale',
i18n.normalizeLocale(locale),
'LC_MESSAGES/server.po'
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var logger = require('../log')('verification-reminders')
var P = require('./promise')
var config = require('../config')
var logger = require('./log')('verification-reminders')
var P = require('../promise')
var config = require('../../mailer/config')
var reminderConfig = config.get('verificationReminders')

module.exports = function (mailer, db, options) {
Expand All @@ -22,25 +22,25 @@ module.exports = function (mailer, db, options) {
* @private
*/
_processReminder: function (reminderData) {
log.debug('_processReminder', reminderData)
log.debug('_processReminder', reminderData)

return db.account(reminderData.uid)
.then(function (account) {
if (! account.emailVerified) {
// if account is not verified then send the reminder
mailer.verificationReminderEmail({
email: account.email,
uid: account.uid.toString('hex'),
code: account.emailCode.toString('hex'),
type: reminderData.type,
acceptLanguage: account.locale
})
} else {
log.debug('_processReminder', { msg: 'Already Verified' })
}
}, function (err) {
log.error('_processReminder', { err: err })
})
return db.account(reminderData.uid)
.then(function (account) {
if (! account.emailVerified) {
// if account is not verified then send the reminder
mailer.verificationReminderEmail({
email: account.email,
uid: account.uid.toString('hex'),
code: account.emailCode.toString('hex'),
type: reminderData.type,
acceptLanguage: account.locale
})
} else {
log.debug('_processReminder', { msg: 'Already Verified' })
}
}, function (err) {
log.error('_processReminder', { err: err })
})
},
_continuousPoll: function () {
var self = this
Expand Down
5 changes: 0 additions & 5 deletions mailer/.gitignore

This file was deleted.

19 changes: 0 additions & 19 deletions mailer/Gruntfile.js

This file was deleted.

Loading

0 comments on commit d09759c

Please sign in to comment.