From 1a89db8a88701c0407f2296c3ddaae72c920f053 Mon Sep 17 00:00:00 2001 From: David Avellaneda Date: Sat, 22 Oct 2016 17:04:50 -0500 Subject: [PATCH] Adding support to use environment variable to filter email inviting (#243) --- bin/slackin | 2 ++ lib/index.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/bin/slackin b/bin/slackin index e09d5329..f6b896b7 100755 --- a/bin/slackin +++ b/bin/slackin @@ -23,6 +23,7 @@ var flags = args.parse(process.argv, { var org = args.sub[0] || process.env.SLACK_SUBDOMAIN var token = args.sub[1] || process.env.SLACK_API_TOKEN +var emails = process.env.EMAIL_SLACK_LIST || '' if (flags.help) { args.showHelp() @@ -33,6 +34,7 @@ if (!org || !token) { } else { flags.org = org flags.token = token + flags.emails = emails } var port = flags.port diff --git a/lib/index.js b/lib/index.js index e4710df3..d970b6b9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,6 +27,7 @@ export default function slackin ({ cors: useCors = false, path='/', channels, + emails, silent = false // jshint ignore:line, }){ // must haves @@ -42,6 +43,11 @@ export default function slackin ({ }) } + if (emails) { + // convert to an array + emails = emails.split(',') + } + // setup app let app = express() let srv = http(app) @@ -137,6 +143,13 @@ export default function slackin ({ .json({ msg: 'Invalid email' }) } + // Restricting email invites? + if (emails && emails.indexOf(email) === -1) { + return res + .status(400) + .json({ msg: 'Your email is not on the accepted email list' }) + } + if (coc && '1' != req.body.coc) { return res .status(400)