Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site level configuration for Akismet and Mailgun #372

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const path = require('path')
const schema = {
akismet: {
site: {
doc: 'URL of an Akismet account used for spam checking.',
doc: 'URL of an Akismet account used for spam checking. Will be overridden by a `akismet.site` parameter in the site config, if one is set.',
docExample: 'http://yourdomain.com',
format: String,
default: null,
env: 'AKISMET_SITE'
},
apiKey: {
doc: 'API key to be used with Akismet.',
doc: 'API key to be used with Akismet. Will be overridden by a `akismet.apiKey` parameter in the site config, if one is set.',
format: String,
default: null,
env: 'AKISMET_API_KEY'
Expand Down
5 changes: 1 addition & 4 deletions lib/Notification.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

const path = require('path')
const config = require(path.join(__dirname, '/../config'))

const Notification = function (mailAgent) {
this.mailAgent = mailAgent
}
Expand All @@ -29,7 +26,7 @@ Notification.prototype.send = function (to, fields, options, data) {

return new Promise((resolve, reject) => {
this.mailAgent.messages().send({
from: `Staticman <${config.get('email.fromAddress')}>`,
from: `Staticman <${data.fromAddress}>`,
to,
subject,
html: this._buildMessage(fields, options, data)
Expand Down
4 changes: 2 additions & 2 deletions lib/Staticman.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class Staticman {

return new Promise((resolve, reject) => {
const akismet = akismetApi.client({
apiKey: config.get('akismet.apiKey'),
blog: config.get('akismet.site')
apiKey: this.siteConfig.get('akismet.apiKey') || config.get('akismet.apiKey'),
blog: this.siteConfig.get('akismet.site') || config.get('akismet.site')
})

akismet.checkSpam({
Expand Down
3 changes: 3 additions & 0 deletions lib/SubscriptionsManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const md5 = require('md5')
const path = require('path')
const config = require(path.join(__dirname, '/../config'))
const Notification = require('./Notification')

const SubscriptionsManager = function (parameters, dataStore, mailAgent) {
Expand Down Expand Up @@ -39,6 +41,7 @@ SubscriptionsManager.prototype.send = function (entryId, fields, options, siteCo
const notifications = new Notification(this.mailAgent)

return notifications.send(list, fields, options, {
fromAddress: siteConfig.get('notifications.fromAddress') || config.get('email.fromAddress'),
siteName: siteConfig.get('name')
})
}
Expand Down
20 changes: 18 additions & 2 deletions siteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ const schema = {
format: Boolean,
default: false
},
site: {
doc: 'URL of an Akismet account used for spam checking.',
docExample: 'http://yourdomain.com',
format: 'EncryptedString',
default: null
},
apiKey: {
doc: 'API key to be used with Akismet.',
format: 'EncryptedString',
default: null
},
author: {
doc: 'Name of the field to be used as the entry\'s author in Akistmet',
format: String,
Expand Down Expand Up @@ -142,12 +153,17 @@ const schema = {
default: false
},
apiKey: {
doc: 'Mailgun API key',
doc: 'Mailgun API key to be used for email notifications.',
format: 'EncryptedString',
default: null
},
domain: {
doc: 'Mailgun domain',
doc: 'Domain to be used with Mailgun for email notifications.',
format: 'EncryptedString',
default: null
},
fromAddress: {
doc: 'Email address to send notifications from.',
format: 'EncryptedString',
default: null
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/lib/Notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ beforeEach(() => {
describe('Notification interface', () => {
const mockData = {
data: {
fromAddress: `${config.get('email.fromAddress')}`,
siteName: 'Eduardo\'s blog'
},
fields: {
Expand Down