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

Commit

Permalink
Merge pull request #246 from HackIllinois/feature/CheckInSlackEmails
Browse files Browse the repository at this point in the history
CheckIn Slack Invites
  • Loading branch information
YashoSharma authored Feb 23, 2018
2 parents 29419ba + a12c738 commit 4523ffc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ overrides['REDIS_HOST'] = 'redis.host';
overrides['REDIS_PORT'] = 'redis.port';
overrides['RATELIMIT_COUNT'] = 'limit.count';
overrides['RATELIMIT_WINDOW'] = 'limit.window';
overrides['SLACK_SECRET'] = 'slack.secret';
handleEnvironmentOverrides(config, overrides);
handleAWSOverrides(config);

Expand All @@ -92,6 +93,7 @@ if (!config.isProduction) {
requireds.delete(overrides['GITHUB_MOBILE_REDIRECT']);
requireds.delete(overrides['RATELIMIT_COUNT']);
requireds.delete(overrides['RATELIMIT_WINDOW']);
requireds.delete(overrides['SLACK_SECRET']);
}
handleEnvironmentRequireds(config, requireds);

Expand Down
16 changes: 16 additions & 0 deletions api/v1/controllers/CheckInController.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const bodyParser = require('body-parser');
const _ = require('lodash');
const request = require('request-promise');

const config = require('ctx').config();
const services = require('../services');
const middleware = require('../middleware');
const requests = require('../requests');
const roles = require('../utils/roles');

const router = require('express').Router();

const SLACK_INVITE_URI = 'https://slack.com/api/users.admin.invite';

function updateCheckInByUserId(req, res, next) {
req.body.userId = req.params.id;
delete req.body.credentialsRequested;
Expand Down Expand Up @@ -57,6 +61,18 @@ function createCheckIn(req, res, next) {
req.body.userId = req.params.id;
services.CheckInService
.createCheckIn(req.body)
.tap((model) => services.UserService.findUserById(model.checkin.get('userId'))
.then((user) => request({
method: 'POST',
uri: SLACK_INVITE_URI,
headers: {
Authorization: 'Bearer ' + config.slack.secret
},
formData: {
email: user.get('email')
}
})
))
.then((response) => {
response.checkin = response.checkin.toJSON();
if (!_.isNil(response.credentials)) {
Expand Down
3 changes: 3 additions & 0 deletions config/development.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@
"limit": {
"count": 50,
"window": 60
},
"slack": {
"secret": "secret-slack-token"
}
}
3 changes: 3 additions & 0 deletions config/production.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@
"limit": {
"count": 50,
"window": 60
},
"slack": {
"secret": "secret-slack-token"
}
}

0 comments on commit 4523ffc

Please sign in to comment.